CentOS7添加Nginx为系统服务

1.编辑系统服务

1
2
3
4
5
6
7
8
9
10
11
12
vim /usr/lib/systemd/system/nginx.service 
[unit]
Description=Web Service
After=network.target
[Service]
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
PrivateTmp=true
[INSTALL]
WantedBy=default.target

2.修改权限

1
chmod 755 /usr/lib/systemd/system/nginx.service

3.测试是否成功

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@nginx ~]# systemctl start nginx 
[root@nginx ~]# systemctl status nginx
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; static; vendor preset: disabled)
   Active: active (running) since Wed 2017-07-26 15:37:34 CST; 8min ago
  Process: 24964 ExecReload=/usr/local/nginx/sbin/nginx -s reload (code=exited, status=0/SUCCESS)
 Main PID: 24956 (nginx)
   CGroup: /system.slice/nginx.service
           ├─24956 nginx: master process /usr/local/nginx/sbin/ngin...
           └─24965 nginx: worker process
Jul 26 15:37:34 nginx systemd[1]: Started nginx.service.
Jul 26 15:37:34 nginx systemd[1]: Starting nginx.service...
Jul 26 15:37:36 nginx systemd[1]: Reloaded nginx.service.
1
2
3
4
5
6
7
8
[root@nginx ~]# systemctl reload nginx
[root@nginx ~]# ss -tln
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128     *:80                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@nginx ~]# systemctl stop nginx
[root@nginx ~]# systemctl status nginx
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; static; vendor preset: disabled)
   Active: inactive (dead)
Jul 26 15:37:36 nginx systemd[1]: Reloaded nginx.service.
Jul 26 15:46:16 nginx systemd[1]: Reloaded nginx.service.
Jul 26 15:46:47 nginx systemd[1]: Stopping nginx.service...
Jul 26 15:46:47 nginx systemd[1]: Stopped nginx.service.
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:49 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:49 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Hint: Some lines were ellipsized, use -l to show in full.
1
[root@nginx ~]# systemctl enable nginx




本文转自 PowerMichael 51CTO博客,原文链接:http://blog.51cto.com/huwho/1950925,如需转载请自行联系原作者
上一篇:潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据


下一篇:死磕synchronized底层原理