Boot from boot nginx,php-fpm (other services similar)
CentOS 7 above is initialized with SYSTEMD system, SYSTEMD is the latest initialization system (INIT) in Linux system, its main design goal is to overcome the inherent shortcomings of sysvinit, and improve the system startup speed. SYSTEMD Service files end with. Service, such as now to build nginx for boot, if installed with the Yum Install command, yum command will automatically create Nginx.service file, directly with the command Systemcel enable Nginx.service set boot up.
systemcel enable nginx.service
Manually set up Nginx.service service files for source installation
- Create a Nginx.service file in the System services directory
vi /lib/systemd/system/nginx.service
Write the following (the path is changed to its own)[Unit]description=nginxafter=Network.target[service]type=Forkingexecstart= /www/lnmp/nginx/sbin/nginx-c/www/lnmp/nginx/conf/nginx.confexecreload=/www/lnmp/nginx/sbin/nginx- S reloadexecstop=/www/lnmp/nginx/sbin/nginx-s quitprivatetmp=true[Install]wantedby =multi-user.target
Create a Php-fpm.service file in the System services directoryvi /lib/systemd/system/php-fpm.service
Write the following (the path is changed to its own)[unit]description=php-fpmafter=Network.target[service]type=Forkingexecstart =/www/lnmp/php/sbin/php-fpmprivatetmp=true[Install]wantedby=multi-user.target
[Unit]: Description of the service
Description: Description Service
After: Describe the service category
settings for the [service] service run parameter
Type=forking is the form of a background run
Execstart specific run commands for the service
Execreload Reset Command
Execstop for Stop command
Privatetmp=true represents a separate temporary space allocated to the service
Note: The start, restart, and stop commands for [Service] all require absolute paths
Settings for service installation under [Install] run level, can be set to multi-user, i.e. system run level is 3
- Test and add power-on self-start
Close NGINX,PHP-FPM First
Use the following command to turn onsystemctl start Nginx.service #如果服务是开启状态, using this command will fail. Systemctl Start PHP-fpm.service
Open successfully, add service to boot
systemctl enable Nginx.service #注意后面不能跟空格systemctl enable PHP-fpm.service
Restart the server to see if it starts
Shutdown-R now #重启systemctl list-units--type=service #查看运行的服务
Other commands
systemctl start Nginx.service #启动nginx服务systemctl enable Nginx.service #设置开机自启动systemctl Disable Nginx.service #停止开机自启动systemctl status nginx.service #查看服务当前状态systemctl restart Nginx.service # Restart the service Systemctl list-units--type=service #查看所有已启动的服务
转载:78513521
Boot from boot NGINX,PHP-FPM