开机启动配置
1 2 3 |
cd /lib/systemd/system/ #新建nginx.service文件 vim nginx.service |
脚本内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[Unit] Description=nginx service 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 |
解释:
[Unit]:服务的说明
- Description : 描述服务
- After : 描述服务类别
[Service] 服务运行参数的设置
- Type=forking:后台运行的形式
- ExecStart:服务的具体运行命令
- ExecReload:重启命令
- ExecStop:停止命令
- PrivateTmp =true:表示给服务分配独立的临时空间
- 注意:[Service]的启动、重启、停止命令全部要求使用绝对路径。
[install]
运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3。
开机启动
1 |
systemctl enable nginx |
重启测试
1 2 |
init 6 #优雅关机 systemctl status nginx.service |

可能会用到的命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
可能会用到的命令 启动 systemctl start nginx.service 停止 systemctl stop nginx.service 重新启动 systemctl restart nginx.service 查看状态 systemctl status nginx.service 设置开机自启 systemctl enable nginx.service 停止开机自启 systemctl disable nginx.service 查看所有已启动的 systemctl list-units --type=service |
- 本文固定链接: https://www.yoyoask.com/?p=636
- 转载请注明: shooter 于 SHOOTER 发表