Linux运维之路


将编译的nginx添加到 systemctl管理中

admin 2019-08-18 176浏览 0条评论
首页/正文
分享到: / / / /

将编译的nginx添加到 systemctl管理中

1. 编译安装nginx

略,不会编译安装,之后的操作不用看了

2. 添加到 centos7中的 系统管理中

编辑文件: vim /usr/lib/systemd/system/nginx.service 添加如下内容

WorkingDirectory= "nginx安装目录"

ExecStart="nginx可执行文件sbin路径"

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target remote-fs.target nss-lookup.target



[Service]

Type=forking

WorkingDirectory=/application/nginx/

ExecStart=/application/nginx/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s QUIT $MAINPID

PrivateTmp=true


[Install]

WantedBy=multi-user.target

3. 测试

查看状态: systemctl status nginx.service  
停止nginx: systemctl stop nginx.service  
启动nginx: systemctl start nginx.service 

设置开机启动: systemctl enable nginx.service 
关闭开机启动: systemctl disable nginx.service 

设置开机启动后,重新开机效果:

看到这个,证明nginx已经运行了

[root@web01 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-08-18 07:30:39 CST; 49s ago
     Docs: http://nginx.org/en/docs/
  Process: 840 ExecStart=/application/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 854 (nginx)
   CGroup: /system.slice/nginx.service
           ├─854 nginx: master process /application/nginx/sbin/nginx
           └─855 nginx: worker process

Aug 18 07:30:39 web01 systemd[1]: Starting nginx - high performance web server...
Aug 18 07:30:39 web01 systemd[1]: Started nginx - high performance web server.
最后修改:2019-08-18 07:36:52 © 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

上一篇

发表评论

评论列表

还没有人评论哦~赶快抢占沙发吧~