标签:服务 service 启动 centos7 nginx systemctl 开机
centos7中设置nginx的systemctl启动方式
1.建立服务文件
(1)文件路径
vim /usr/lib/systemd/system/nginx.service
(2)服务文件内容
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
(3)文件内容解释
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径
[Install]服务安装的相关设置,可设置为多用户
(4)使文件生效
systemctl daemon-reload
2.保存目录
(1)以754的权限保存在目录:
Chmod +754 /usr/lib/systemd/system
(2)设置开机自启动
systemctl enable nginx.service
(3)启动nginx服务
systemctl start nginx.service
(4)停止开机自启动
systemctl disable nginx.service
(5)查看服务当前状态
systemctl status nginx.service
(6)重新启动服务
systemctl restart nginx.service
(7)查看所有已启动的服务
systemctl list-units --type=service
3.命令集合
systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务
注:*代表某个服务的名字,如http的服务名为httpd
标签:服务,service,启动,centos7,nginx,systemctl,开机 来源: https://www.cnblogs.com/sanluorenjian/p/13196756.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。