nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)

#检查Nginx配置
[email protected]:/usr/local/nginx# ./sbin/nginx -t -c ./conf/nginx.conf
nginx: the configuration file /usr/local/nginx/./conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/./conf/nginx.conf test is successful

#不依靠残留进程,重新启动Nginx
[email protected]:/usr/local/nginx# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
nginx: [emerg] still could not bind()

#强制性杀死进程
[email protected]:/usr/local/nginx# pkill -9 nginx
[email protected]:/usr/local/nginx# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#查看系统日志
[email protected]:/usr/local/nginx# journalctl -xe

Oct 08 02:01:37 ubuntu systemd[1]: Reloading.
Oct 08 02:01:37 ubuntu systemd[1]: Reloading.
Oct 08 02:01:37 ubuntu systemd[1]: Reloading.
Oct 08 02:05:02 ubuntu CRON[5289]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 08 02:05:02 ubuntu CRON[5290]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Oct 08 02:05:02 ubuntu CRON[5289]: pam_unix(cron:session): session closed for user root
Oct 08 02:06:20 ubuntu dhclient[52158]: DHCPREQUEST of 192.168.121.128 on ens33 to 192.168.121.254 port 67 (xid=0x3360b9fd)
Oct 08 02:06:20 ubuntu dhclient[52158]: DHCPACK of 192.168.121.128 from 192.168.121.254
Oct 08 02:06:20 ubuntu dhclient[52158]: bound to 192.168.121.128 – renewal in 896 seconds.
Oct 08 02:09:01 ubuntu CRON[5449]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 08 02:09:01 ubuntu CRON[5450]: (root) CMD ( [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
Oct 08 02:09:03 ubuntu CRON[5449]: pam_unix(cron:session): session closed for user root
Oct 08 02:15:01 ubuntu CRON[5559]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 08 02:15:01 ubuntu CRON[5560]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Oct 08 02:15:01 ubuntu CRON[5559]: pam_unix(cron:session): session closed for user root
Oct 08 02:17:01 ubuntu CRON[11067]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 08 02:17:01 ubuntu CRON[11068]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Oct 08 02:17:01 ubuntu CRON[11067]: pam_unix(cron:session): session closed for user root
Oct 08 02:17:06 ubuntu sudo[11070]: root : TTY=pts/0 ; PWD=/usr/local/nginx ; USER=root ; COMMAND=/bin/systemctl enable nginx.service
Oct 08 02:17:06 ubuntu sudo[11070]: pam_unix(sudo:session): session opened for user root by wzq(uid=0)
Oct 08 02:17:06 ubuntu sudo[11070]: pam_unix(sudo:session): session closed for user root
Oct 08 02:17:20 ubuntu sudo[11076]: root : TTY=pts/0 ; PWD=/usr/local/nginx ; USER=root ; COMMAND=/bin/systemctl status nginx.service
Oct 08 02:17:20 ubuntu sudo[11076]: pam_unix(sudo:session): session opened for user root by wzq(uid=0)
Oct 08 02:17:20 ubuntu sudo[11076]: pam_unix(sudo:session): session closed for user root
Oct 08 02:21:16 ubuntu dhclient[52158]: DHCPREQUEST of 192.168.121.128 on ens33 to 192.168.121.254 port 67 (xid=0x3360b9fd)
Oct 08 02:21:16 ubuntu dhclient[52158]: DHCPACK of 192.168.121.128 from 192.168.121.254
Oct 08 02:21:16 ubuntu dhclient[52158]: bound to 192.168.121.128 – renewal in 705 seconds.
Oct 08 02:25:01 ubuntu CRON[11201]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 08 02:25:01 ubuntu CRON[11202]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Oct 08 02:25:01 ubuntu CRON[11201]: pam_unix(cron:session): session closed for user root
Oct 08 02:26:25 ubuntu sudo[11217]: root : TTY=pts/0 ; PWD=/usr/local/nginx ; USER=root ; COMMAND=/usr/local/nginx/sbin/nginx
Oct 08 02:26:25 ubuntu sudo[11217]: pam_unix(sudo:session): session opened for user root by wzq(uid=0)
Oct 08 02:26:28 ubuntu sudo[11217]: pam_unix(sudo:session): session closed for user root
Oct 08 02:26:34 ubuntu sudo[11223]: root : TTY=pts/0 ; PWD=/usr/local/nginx ; USER=root ; COMMAND=/usr/local/nginx/sbin/nginx restart
Oct 08 02:26:34 ubuntu sudo[11223]: pam_unix(sudo:session): session opened for user root by wzq(uid=0)
Oct 08 02:26:34 ubuntu sudo[11223]: pam_unix(sudo:session): session closed for user root
Oct 08 02:33:01 ubuntu dhclient[52158]: DHCPREQUEST of 192.168.121.128 on ens33 to 192.168.121.254 port 67 (xid=0x3360b9fd)
Oct 08 02:33:01 ubuntu dhclient[52158]: DHCPACK of 192.168.121.128 from 192.168.121.254
Oct 08 02:33:01 ubuntu dhclient[52158]: bound to 192.168.121.128 – renewal in 826 seconds.
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)

#-lt 列出监听的TCP端口, -u 或 --udp 显示UDP传输协议的连线状况,-n 输出中不解析主机、端口、名称, -p 显示进程ID和名称
[email protected]:/usr/local/nginx# netstat -ltunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4784/sshd
tcp 0 0 127.0.0.1:5433 0.0.0.0:* LISTEN 36359/postgres
tcp 0 0 0.0.0.0:66 0.0.0.0:* LISTEN 11291/nginx.conf
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 5178/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 76323/zabbix_server
tcp6 0 0 :::22 ::???? LISTEN 4784/sshd
tcp6 0 0 :::88 ::???? LISTEN 76404/apache2
tcp6 0 0 ::1:5433 ::???? LISTEN 36359/postgres
tcp6 0 0 :::10050 ::???? LISTEN 5178/zabbix_agentd
tcp6 0 0 :::10051 ::???? LISTEN 76323/zabbix_server
udp 0 0 0.0.0.0:68 0.0.0.0:* 52158/dhclient
udp 0 0 0.0.0.0:53356 0.0.0.0:* 36547/snmpd
udp 0 0 127.0.0.1:161 0.0.0.0:* 36547/snmpd

#杀死指定PID的进程

[[email protected] nginx]# kill 812

#检验进程是否杀死
nginx: [emerg] bind() to 0.0.0.0:66 failed (98: Address already in use)
#重启Nginx,此时没有残留进程占用80端口了

[[email protected] nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf