前言
上一篇博客中我们讨论了nginx的热部署相关,当然在配置过程中也存在一些问题,比如,启动比较麻烦,每次都要到/usr/local/nginx/sbin/下执行脚本。因此接下来我们简单说说如何使用systenmctl命令来控制nginx。
配置过程
1.安装httpd服务,安装后httpd的启动脚本会在 /usr/lib/systemd/system 目录下
我们这一步的目的是为了获得一份启动脚本模板
[root@server1 ~]# yum install -y httpd
[root@server1 ~]# cd /usr/lib/systemd/system
[root@server1 system]# ls
2.将httpd的启动脚本复制给nginx (一般系统中自定义的启动脚本放在/etc/systemd/system/目录下)
[root@server1 system]# cp httpd.service /etc/systemd/system/nginx.service
[root@server1 system]#
[root@server1 system]# cd /etc/systemd/system
[root@server1 system]# ls
3.修改复制过来的启动脚本
高亮区域为修改部分
4.先用原来的方式关闭nginx服务
/usr/local/nginx/sbin/nginx -s stop
我关了两次才关掉
5.打开服务
[root@server1 system]# systemctl start nginx.service
[root@server1 system]# systemctl status nginx.service
6.关闭服务
[root@server1 system]# systemctl stop nginx.service
[root@server1 system]# systemctl status nginx.service