今天我的服务器突然挂了,上不去了,吓得我赶紧排查了一下。
出现了下面这种错误
Nov 26 08:22:32 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] bind() to 0.0.0.0:80 failed (...e)
Nov 26 08:22:33 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] bind() to 0.0.0.0:443 failed ...e)
Nov 26 08:22:33 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] bind() to 0.0.0.0:80 failed (...e)
Nov 26 08:22:33 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] bind() to 0.0.0.0:443 failed ...e)
Nov 26 08:22:33 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] bind() to 0.0.0.0:80 failed (...e)
Nov 26 08:22:34 ip.ap-east-1.compute.internal nginx[1291]: nginx: [emerg] still could not bind()
Nov 26 08:22:34 ip.ap-east-1.compute.internal systemd[1]: nginx.service: control process exited, code=e...=1
Nov 26 08:22:34 ip.ap-east-1.compute.internal systemd[1]: Failed to start nginx - high performance web ...r.
Nov 26 08:22:34 ip.ap-east-1.compute.internal systemd[1]: Unit nginx.service entered failed state.
Nov 26 08:22:34 ip.ap-east-1.compute.internal systemd[1]: nginx.service failed.
然后我赶紧查资料,说是端口被占用,用了下面的命令查。
看看 80 端口是不是被占用了
netstat -anp |grep 80
返回
tcp 0 0 10.0.0.1:26638 10.0.0.2:80 ESTABLISHED 1040/netrelay
tcp6 0 0 :::80 :::* LISTEN 1040/netrelay
这结果我没看太懂,又用了另外一个命令查
netstat -ltunp
这次看明白了一点,是 1040/netrelay 这个进程占用了端口
tcp6 0 0 :::443 :::* LISTEN 1040/netrelay
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 1040/netrelay
谷歌了一下这个进程名没查出来它是干啥的,直接 kill 了这个进程,重启 nginx
kill 1040
重启 nginx,恢复正常。