美文网首页
centos7 nginx 开机自启动

centos7 nginx 开机自启动

作者: 牍中玉的小木屋 | 来源:发表于2020-03-24 22:06 被阅读0次
    1. 在系统服务目录中创建 nginx.service 文件

vim /lib/systemd/system/nginx.service

    1. 编辑服务文件
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/home/work/study/soft/nginx/sbin/nginx -c /home/work/study/soft/nginx/conf/nginx.conf
ExecReload=/home/work/study/soft/nginx/sbin/nginx -s reload
ExecStop=/home/work/study/soft/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
    1. 查看服务状态

netsta -ntlp | grep nginx
ps -ef | grep nginx

    1. 关闭服务

pkill -9 nginx

    1. 启动服务

systemctl start nginx.service

    1. 开启成功后,将服务加入到开机自启动

systemctl enable nginx.service

创建成功的标识

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

  • 重启服务器

shutdown -r now
reboot

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

nginx 开机自启动:https://www.jianshu.com/p/d869d2f20a4f
php-fpm 开机自启动:https://www.jianshu.com/p/33b44a14ebf7

image.png

相关文章

网友评论

      本文标题:centos7 nginx 开机自启动

      本文链接:https://www.haomeiwen.com/subject/tgoayhtx.html