Centos7.8 sets nginx boot self-start/nginx start, stop, view version and other command summary

Table of contents

1. Enter /usr/lib/md/systemsyste

2. Create nginx.service file

3. vim edit nginx.service

4. Set the boot to start automatically

5. Set to cancel the boot from the start  

6. nginx service start, restart, stop, view service, view status

7. Check whether the service exists by checking the nginx process

8. Check the nginx version


1. Enter /usr/lib/md/systemsyste

cd /usr/lib/systemd/system

2. Create nginx.service file

touch nginx.service

3. vim edit nginx.service

The paths in ExecStart, ExecReload, and ExecStop are modified according to your actual nginx installation path.

    ----------------The contents of the file are as follows ----------------------------- -----------
[Unit]  
Description=nginx
After=network.target
             
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
             
[Install]
WantedBy=multi-user.target

 ------------------------------The contents of the file are as above---------------- -------------------------

Command comments are as follows:

[Unit] : Description of the service

Description : Describe the service
After : Describe the service category
[Service] The setting of service operation parameters
Type=forking is the form of running in the background
ExecStart is the specific operation command of the service
ExecReload is the restart command
ExecStop is the stop command
PrivateTmp=True means assigning an independent temporary service to the service Space
 note:

        The start, restart, and stop commands of [Service] all require the use of absolute paths. The relevant settings for service installation under
        the [Install] run level can be set to multi-user, that is, the system run level is 3

4. Set the boot to start automatically

   systemctl enable nginx.service

         Kill the original process (manual path startup mode) after setting the boot auto-start, and restart nginx with the start command, and then the boot will auto-start normally.

5. Set to cancel the boot from the start  

systemctl disable nginx.service 

6. nginx service start, restart, stop, view service, view status

        I also wrote a detailed summary blog about nginx service startup, restart and other related commands before. You can jump to the following address:

How to restart, start and stop nginx in Linux - Programmer Sought

systemctl start nginx.service #open
systemctl stop nginx.service #close

systemctl restart nginx.service #Restart service
systemctl reload nginx.service #Reload configuration
systemctl status nginx.service #View current nginx service status

systemctl list-units --type=service View all started services

7. Check whether the service exists by checking the nginx process

ps -ef|grep nginx

 View the process service of a specific port: such as viewing the service of port 80

lsof -i:80

8. Check the nginx version

(1) View through the ./nginx -v command (it can be used by compiling and installing)

 Enter the nginx installation directory and execute the -v command

cd /usr/local/nginx/sbin

./nginx -v

 (2) The way to search for services through the rpm -qa|grep nginx command (it can be used through yum source installation)

rpm -qa|grep nginx

-----------------------------------------No text below--------- ---------------------------------------------

Note: For study only, record questions and reference, encourage each other!

Guess you like

Origin blog.csdn.net/qq_39715000/article/details/125052307