/lib/systemd/system/
目录shellcd /lib/systemd/system
nginx.service
文件,并编辑shellvim nginx.service
輸入下面內容
[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
Description
:描述服务
After
:描述服务类别
[Service]
:服务运行参数的设置
Type=forking
:是后台运行的形式
ExecStart
:为服务的具体运行命令
ExecReload
:为重启命令
ExecStop
:为停止命令
PrivateTmp=True
:表示给服务分配独立的临时空间
注意
[Service]
的启动、重启、停止命令全部要求使用绝对路径
[Install]
运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
wq
保存退出。
systemctl enable nginx.service
如果不想开机自启动了,可以使用下面的命令取消开机自启动
systemctl disable nginx.service
# systemctl start nginx.service 启动nginx服务 # systemctl stop nginx.service 停止服务 # systemctl restart nginx.service 重新启动服务 # systemctl list-units --type=service 查看所有已启动的服务 # systemctl status nginx.service 查看服务当前状态 # systemctl enable nginx.service 设置开机自启动 # systemctl disable nginx.service 停止开机自启动
注意
一个常见的错误
Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.
直接按照提示执行命令systemctl daemon-reload
即可。
本文作者:澳门🇲🇴工作的IT人
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!