V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
rogwan
V2EX  ›  问与答

nginx 不停的报 could not bind() 的 error log,实际又不影响访问,是神马情况?

  •  
  •   rogwan · 2017-07-07 23:32:23 +08:00 · 4009 次点击
    这是一个创建于 2698 天前的主题,其中的信息可能已经有所发展或是发生改变。
    一段时间发现某个文件夹怎么那么大,一看才发现是 nginx 的 error.log 已经 6.5G 啦,因为访问都正常,没发现异常情况,就是不断的出现下面的重复 error log

    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:8888 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:99 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:8888 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:99 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:8888 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:99 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:8888 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:99 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:80 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to [::]:443 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:8888 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: bind() to 0.0.0.0:99 failed (98: Address already in use)
    2017/07/02 10:43:27 [emerg] 1766#0: still could not bind()

    上面的这些端口 80 99 8888 443 都是在正常访问的状态,不知道为什么还要记录这样的 error log?
    15 条回复    2017-07-08 14:26:51 +08:00
    wellsc
        1
    wellsc  
       2017-07-08 00:20:57 +08:00
    sudo lsof -i tcp:80 试试看
    fuxkcsdn
        2
    fuxkcsdn  
       2017-07-08 00:23:26 +08:00 via iPhone
    是不是启动了多个 nginx ? ps 找找看
    johnlui
        3
    johnlui  
       2017-07-08 00:30:26 +08:00 via Android
    目测是启动了多个 master 进程
    ETiV
        4
    ETiV  
       2017-07-08 03:40:28 +08:00 via iPhone
    装 gitlab 了?
    cxbig
        5
    cxbig  
       2017-07-08 04:20:52 +08:00 via iPhone
    master 进程有多个 +1
    ghostheaven
        6
    ghostheaven  
       2017-07-08 06:32:57 +08:00 via Android
    0.0.0.0 是绑定本机所有 ip,可能有一个 ip 的 80 和 443 被别的占用了
    rogwan
        7
    rogwan  
    OP
       2017-07-08 08:48:32 +08:00
    @wellsc

    查看了下,是 ipv4 和 ipv6 抢抢同一个端口造成的?
    # sudo lsof -i tcp:80
    nginx 1306 root 9u IPv4 10290 0t0 TCP *:http (LISTEN)
    nginx 1306 root 10u IPv6 10291 0t0 TCP *:http (LISTEN)
    nginx 1312 nobody 9u IPv4 10290 0t0 TCP *:http (LISTEN)
    nginx 1312 nobody 10u IPv6 10291 0t0 TCP *:http (LISTEN)
    rogwan
        8
    rogwan  
    OP
       2017-07-08 08:51:49 +08:00
    @ETiV

    确实是装了 gitlab,但是我分配了一个专门的 9596 端口,没有出现上面的冲突 log 中呀
    kn007
        9
    kn007  
       2017-07-08 11:24:48 +08:00
    ipv4 和 ipv6 同事监听 80,要以这种方式:

    listen 80;
    listen [::]:80 ipv6only=on;
    rogwan
        10
    rogwan  
    OP
       2017-07-08 11:54:38 +08:00
    @kn007 是这样写的,这两个没冲突。

    @fuxkcsdn
    @johnlui

    这个机器上跑了一个 nginx web,还跑了一个 gitlab,看了进程记录显示,gitlab 里面也有一个 nginx 的 master 进程在跑,虽然指定了端口给 gitlab 用,但估计 gitlab 的 nginx 还默认监听了其他端口,造成已经被 nginx web 占用的端口就 bind 不了。
    wellsc
        11
    wellsc  
       2017-07-08 12:01:39 +08:00 via iPad
    @rogwan 应该是同时跑了两个人 Nginx 造成的 ,pwdx pid 看一下分别是那两个 nginx
    johnlui
        12
    johnlui  
       2017-07-08 12:03:38 +08:00
    netstat -tulpn

    一看便知
    iConnect
        13
    iConnect  
       2017-07-08 12:15:08 +08:00
    @johnlui 这个是看在监听状态的端口,楼主说的没有 bind 上报错,那就看不到了

    @rogwan 看看这个 https://stackoverflow.com/questions/25393370/gitlab-nginx-problems-nginx-emerg-bind-to-0-0-0-080-failed-98-address
    johnlui
        14
    johnlui  
       2017-07-08 14:01:17 +08:00
    @iConnect bind 上报错是因为别的进程已经监听了呀。。。用这个命令可以准确的找到是哪个进程监听了。
    ETiV
        15
    ETiV  
       2017-07-08 14:26:51 +08:00 via iPhone
    LZ 貌似已经解决了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4344 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 04:08 · PVG 12:08 · LAX 20:08 · JFK 23:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.