程序媛on the way

nginx、php-fpm开机自启动

2018-11-05  本文已影响20人  Sonia_Du

1.在系统服务目录里创建xxx.service文件

vi /lib/systemd/system/xxx.service

nginx.service

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

php-fpm.service

[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:
[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

2.使用方法

\#开机自启动
systemctl enable xxx.service
\#停止开机自启动
systemctl disable xxx.service
\#查询当前状态
systemctl status xxx.service
\#启动服务
systemctl start xxx.service
\#重新启动服务
systemctl restart xxx.service
\#停止服务
systemctl stop xxx.service
\#重新加载配置
systemctl reload xxx.service
\#重启服务器
reboot
\#查看所有已启动的服务
systemctl list-units --type=service
已启动服务列表
上一篇 下一篇

猜你喜欢

热点阅读