重要的提示:我不再需要重启服务器(我的 3 个 VPS!)来将 pid 文件放回到目录 /run/nginx.pid 中
我刚刚输入了命令:sudo fuser -k 443 / tcp && 服务 nginx 启动
解决了 24 小时内的问题,因为 pid 返回到 /run/nginx/,而无需重新启动服务,并且始终正常运行,但是每天 PID 都会消失!即使 nginx 进程正在进行并且服务器始终正常运行!
所以我可以使用服务 nginx start并且 pid 返回出现 monit 返回监视器 nginx 进程并且我回来控制命令:服务 nginx 状态、服务 nginx 停止等...
注意,我不是说 nginx 停止工作,网站继续在线,我说的是文件:/run/nginx.pid 每天都会消失,所以我不能再使用 nginx 相关的命令,即使我输入命令
sudo fuser-k 443/tcp
文件 /run/nginx.pid 的缺失带来了几个问题,其中最糟糕的是我无法使用命令、服务 nginx 状态、启动、停止等。
============================ 我需要 nginx pid 来与 monit 一起工作,pid 突然消失了,我必须重新启动 vps 才能恢复它!每天晚上都会发生这种情况!但即使他消失了,他仍然在运行!在线网站!但显然我无法监控状态、重新启动、停止……等等……我需要 pid!当我尝试通过终端查看状态时,我有
终端命令行上的错误输出:
service nginx status
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: failed (Result: exit-code) since Sun 2017-11-05 06:25:07 WET; 1h 50mi
Process: 5062 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 -
Process: 1527 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
Process: 1522 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 1486 (code=exited, status=0/SUCCESS)
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 faile
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 faile
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] still could not bind()
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Control process exited, code=exi
Nov 05 06:25:07 vps1 systemd[1]: Failed to start A high performance web server a
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Unit entered failed state.
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Failed with result 'exit-code'.
lines 1-18/18 (END)...skipping...
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: failed (Result: exit-code) since Sun 2017-11-05 06:25:07 WET; 1h 50mi
Process: 5062 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 -
Process: 1527 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
Process: 1522 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 1486 (code=exited, status=0/SUCCESS)
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 faile
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 faile
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 fail
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] still could not bind()
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Control process exited, code=exi
Nov 05 06:25:07 vps1 systemd[1]: Failed to start A high performance web server a
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Unit entered failed state.
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Failed with result 'exit-code'.
~
~
~
~
~
~
lines 1-18/18 (END)...skipping...
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2017-11-05 06:25:07 WET; 1h 50min ago
Process: 5062 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
Process: 1527 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 1522 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1486 (code=exited, status=0/SUCCESS)
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 failed (98: Address already in use)
Nov 05 06:25:06 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:80 failed (98: Address already in use)
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 06:25:07 vps1 nginx[1527]: nginx: [emerg] still could not bind()
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Control process exited, code=exited status=1
Nov 05 06:25:07 vps1 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Unit entered failed state.
Nov 05 06:25:07 vps1 systemd[1]: nginx.service: Failed with result 'exit-code'.
我的 /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server_names_hash_bucket_size 128;
client_max_body_size 100M;
client_body_buffer_size 16k;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Nginx 日志:
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:25:08 [emerg] 1703#1703: still could not bind()
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:27:39 [emerg] 1978#1978: still could not bind()
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:30:10 [emerg] 2076#2076: still could not bind()
2017/11/05 06:32:41 [emerg] 2208#2208: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:32:41 [emerg] 2208#2208: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:32:41 [emerg] 2208#2208: bind() to 141.14.14.41:80 failed (98: Address already in use)
2017/11/05 06:32:41 [emerg] 2208#2208: bind() to 141.14.14.41:443 failed (98: Address already in use)
2017/11/05 06:32:41 [emerg] 2208#2208: bind() to 141.14.14.41:80 failed (98: Address already in use)
Ubuntu 16.04-64b/nginx 1.10.3/php7.0-fpm
我尝试只查看状态:服务 nginx 状态:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2017-11-05 09:00:51 WET; 3h 5min ago
Process: 5062 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=1/FAILURE)
Process: 8636 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 8633 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1486 (code=exited, status=0/SUCCESS)
Nov 05 09:00:50 vps1 nginx[8636]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 09:00:50 vps1 nginx[8636]: nginx: [emerg] bind() to 141.14.14.41:80 failed (98: Address already in use)
Nov 05 09:00:50 vps1 nginx[8636]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 09:00:51 vps1 nginx[8636]: nginx: [emerg] bind() to 141.14.14.41:80 failed (98: Address already in use)
Nov 05 09:00:51 vps1 nginx[8636]: nginx: [emerg] bind() to 141.14.14.41:443 failed (98: Address already in use)
Nov 05 09:00:51 vps1 nginx[8636]: nginx: [emerg] still could not bind()
Nov 05 09:00:51 vps1 systemd[1]: nginx.service: Control process exited, code=exited status=1
Nov 05 09:00:51 vps1 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Nov 05 09:00:51 vps1 systemd[1]: nginx.service: Unit entered failed state.
Nov 05 09:00:51 vps1 systemd[1]: nginx.service: Failed with result 'exit-code'.
如果我强制重新启动机器,立即重新启动(我只是再次这样做),nginx pid 会重新出现(/run/nginx.pid),并且 monit 返回监视该过程:
https://i.stack.imgur.com/lvuA5.jpg
但是当然没有人必须重新启动 vps 只是为了执行 nginx 状态或 nginx 重新启动,因为 linux 服务器上没有更多的 nginx pid!
我非常感谢你的帮助。
答案1
第一次尝试:pkill nginx && service nginx restart
如果文件仍然被删除,那么您可以使用它ftrace
来查找哪个进程正在删除您的文件:
trace-cmd record -e \*unlink\*
等待文件被删除,按 CTRL+C 停止 trace-cmd 记录...,然后运行:
trace-cmd report
也可以看看:https://serverfault.com/a/310477/30946
还要确保 pid/usr/lib/systemd/system/nginx.service
或/etc/systemd/system/nginx.service
文件中的指向与/etc/nginx/nginx.conf