当前位置: 移动技术网 > 网络运营>服务器>nginx > nginx centos 服务开机启动设置实例详解

nginx centos 服务开机启动设置实例详解

2019年04月19日  | 移动技术网网络运营  | 我要评论

91 越狱,权术天下,微笑张杰

nginx centos 服务开机启动设置

建立服务文件

以nginx 为例

vim /lib/systemd/system/nginx.service 

在nginx.service 中插入一下内容

[unit] 
description=nginx 
after=network.target 

[service] 
type=forking 
execstart= 服务启动命令
execreload= 服务重启命令
execstop=服务停止命令
privatetmp=true 

[install] 
wantedby=multi-user.target 

[unit]:服务的说明
description:描述服务
after:描述服务类别
[service]服务运行参数的设置
type=forking是后台运行的形式
execstart为服务的具体运行命令
execreload为重启命令
execstop为停止命令
privatetmp=true表示给服务分配独立的临时空间
注意:[service]的启动、重启、停止命令全部要求使用绝对路径

以754的权限保存在目录:/lib/systemd/system 

设置开机自启动:

systemctl enable nginx.service

相关命令

功能                                       cnetos7以前                                          cnetos7
显示所有已启动的服务            chkconfig --list                 systemctl list-units --type=service

启动某服务       service nginx start systemctl             start nginx.service 或 systemctl start nginx

停止某服务       service nginx stop systemctl             stop nginx.service 或 systemctl stop nginx

重启某服务       service nginx restart                    systemctl restart nginx.service 或 systemctl restart nginx

使某服务自动启动     chkconfig --level 3 nginx  on       systemctl enable nginx.service 或 systemctl enable nginx

使某服务不自动启动     chkconfig --level 3 nginx off    systemctl disable nginx.service 或 systemctl disable nginx

检查服务状态       service nginx status                 systemctl is-active nginx.service (仅显示是否)activesystemctl status nginx.service (服务详细信息)

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网