Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure nginx startup service script in Centos7

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to configure the nginx startup service script in Centos7, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Add self-booting service

The service systemctl script for CentOS 7 is stored at: / usr/lib/systemd/

It can be divided into system (system) and user (user), such as programs that can be run without logging in.

It should be stored in the system service, that is, under the / usr/lib/systemd/system directory

Each service ends with .service and is generally divided into three parts: [Unit], [Service] and [Install]

It is very convenient to add a self-starting service to centos7. You only need two commands (take Jenkins as an example):

Systemctl enable jenkins.service # set the jenkins service to the self-startup service sysstemctl start jenkins.service # start the jenkins service CentOS 7 set the boot service

Establish a service file

Save catalog

Set Boot self-boot

Other commands

1. Establish a service file

File path

Vim / usr/lib/systemd/system/nginx.service

Service file content

1.nginx.service

[Unit] Description=nginx-high performance web serverAfter=network.target remote-fs.target nss- lookup.target [service] Type=forkingExecStart=/usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx-s reloadExecStop=/usr/local/nginx/sbin/nginx-s stop[ install] WantedBy=multi-user.target

2.mysql.service

[Unit] Description=mysqlAfter=network.target remote-fs.target nss-lookup.target [Service] Type=forkingExecStart=/usr/local/mysql/support-files/mysql.server start#ExecReload=/usr/local/mysql/support-files/mysql.server restart#ExecStop=/usr/local/mysql/support-files/mysql.server stop#PrivateTmp= true[Install] WantedBy=multi-user.target

3.php-fpm.service

[Unit] Description=phpAfter=network.target remote-fs.target nss-lookup.target [Service] Type=forkingExecStart=/usr/local/php/sbin/php-fpm [Install] WantedBy=multi-user.target

4.redis.service

[Unit] Description=RedisAfter=network.target remote-fs.target nss-lookup.target [Service] Type=forkingExecStart=/usr/local/bin/redis-server / etc/redis.confExecStop=kill-INT `cat / tmp/ redis.pid`User = wwwGroup= www [install] WantedBy=multi-user.target

5.supervisord.service

[Unit] Description=Process Monitoring and Control DaemonAfter=rc- local.service [service] Type=forkingExecStart=/usr/bin/supervisord-c / etc/supervisord.confSysVStartPriority= 99 [install] WantedBy=multi-user.target

Interpretation of document content

[Unit]: description of the service Description: description of the service After: description of the service category [Service] service running parameter setting Type=forking is the form of background operation ExecStart specific operation command ExecReload for the restart command ExecStop for the stop command PrivateTmp=True indicates the allocation of independent temporary space to the service Note: start, restart, stop commands all require the use of absolute path [Install] service installation related settings, can be set to multi-user 2. Save catalog

Save it in the directory with 754 permissions:

/ usr/lib/systemd/system/3. Set Boot self-boot

Execute under any directory

Systemctl enable nginx.service4. Other commands

Start the nginx service

Systemctl start nginx.service

Set Boot self-boot

Systemctl enable nginx.service

Stop booting and self-starting

Systemctl disable nginx.service

View the current status of the service

Systemctl status nginx.service

Restart the service

Systemctl restart nginx.service

View all started services

Systemctl list-units-type=service

The following is a supplement to the relevant knowledge.

See what a service contains:

Systemctl cat sshd.service

For more information about services, you can learn the following BLOG:

System Service systemd

Http://blog.51cto.com/littledevil/1912449

System service configuration-unit (Unit)

Http://blog.51cto.com/littledevil/1912489

System Service configuration objective (Target)

Http://blog.51cto.com/littledevil/1912559

System Service configuration Service (Service)

Http://blog.51cto.com/littledevil/1912570

Second, add a boot script

There are two common ways to add scripts to centos7. Take the script autostart.sh as an example:

#! / bin/bash#description: boot script / usr/local/tomcat/bin/startup.sh # start tomcat method 1

1. Give the script executable permissions (/ opt/script/autostart.sh is your script path)

Chmod + x / opt/script/autostart.sh

2. Open the / etc/rc.d/rc/local file and add the following at the end

/ opt/script/autostart.sh

3. In centos7, the permission of / etc/rc.d/rc.local is reduced, so you need to execute the following command to give it executable permission.

Chmod + x / etc/rc.d/rc.local method II

Service httpd start actually starts the script stored in the / etc/init.d directory.

1. Move the script to / etc/rc.d/init.d directory

Mv / opt/script/autostart.sh / etc/rc.d/init.d

2. Increase the executable permissions of the script

Chmod + x / etc/rc.d/init.d/autostart.sh

3. Add a script to the startup project

Cd / etc/rc.d/init.dchkconfig-this is the end of the add autostart.shchkconfig autostart.sh on script on how to configure nginx startup service in Centos7. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report