環(huán)境 Centos7
問題描述:在重啟虛擬機(jī)后,會刪除/var/run下的文件。會殺掉進(jìn)程,導(dǎo)致重新啟動后nginx服務(wù)器無法啟動。
# systemctl status nginx
>>>
● nginx.service - SYSV: nginx is a World Wide Web server. It is used to servea
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (exited) (Result: exit-code) since 二 2018-01-30 14:48:43 CST; 10min ago
Docs: man:systemd-sysv-generator(8)
Process: 2672 ExecReload=/etc/rc.d/init.d/nginx reload (code=exited, status=7)
Process: 1114 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
1月 30 14:48:43 bogon systemd[1]: Starting SYSV: nginx is a World Wide Web server. It is used to servea...
1月 30 14:48:43 bogon nginx[1114]: Starting nginx: [ 確定 ]
1月 30 14:48:43 bogon systemd[1]: Started SYSV: nginx is a World Wide Web server. It is used to servea.
1月 30 14:48:44 bogon nginx[1114]: nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
1月 30 14:50:32 bogon systemd[1]: nginx.service: control process exited, code=exited status=7
1月 30 14:50:32 bogon systemd[1]: Reload failed for SYSV: nginx is a World Wide Web server. It is used to servea.
1月 30 14:56:01 bogon systemd[1]: nginx.service: control process exited, code=exited status=7
1月 30 14:56:01 bogon systemd[1]: Reload failed for SYSV: nginx is a World Wide Web server. It is used to servea.
問題解決思路:
- 配置文件中指定nginx進(jìn)程文件,nginx.pid是nginx的進(jìn)程文件,文件中一般只會寫一個進(jìn)程的編號。所以我們先查看配置文件中的進(jìn)程文件的地址。查看 安裝目錄下的/conf/nginx.conf 在這里我的是 /opt/stx/soft/tengine2.2.0/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
pid logs/nginx.pid;
nginx的進(jìn)程目錄在logs/nginx.pid 如果這行被注釋,則pid文件在 /var/run/nginx 如果沒有這個目錄則創(chuàng)建這個目錄
mkdir -p /var/run/nginx
- 我們在重新運(yùn)行nginx的時候需要去告訴運(yùn)行環(huán)境去加載nginx的進(jìn)程配置。所以需要指定配置文件
在我的環(huán)境中:
/opt/stx/soft/tengine2.2.0/sbin/nginx -c /opt/stx/opt/tengine2.2.0/conf/nginx.conf
執(zhí)行后,再次查看會發(fā)現(xiàn)剛才指定的目錄下有了nginx.pid文件。然后重啟nginx就恢復(fù)正常了
systemctl reload nginx