How to set mongod.conf bind_ip with multiple ip address

前端 未结 16 583
情书的邮戳
情书的邮戳 2020-12-09 01:22

I am a newbie for setting up the server environment and mongoDB. This may sounds something really simple, however, I really need your help on it.

I am trying to conn

相关标签:
16条回答
  • 2020-12-09 02:23

    Amazon-linux2 | Cent OS | MongoDB shell version: 3.0.15

    This is how it needs to be done in the latest config

    #network interfaces
    net:
      port: 27017
      bindIp: [xxx.xxx.xxx.xxx,127.0.0.1]  # Listen to local interface only, comment to listen on all interfaces.
    

    Cheers!!

    0 讨论(0)
  • 2020-12-09 02:25

    With MongoDB server version: 3.6.8 plain comma separated list worked for me. With or without spaces after comma.

    bind_ip = 127.0.0.1, 192.168.0.104
    bind_ip = 127.0.0.1,192.168.0.104
    

    However, adding enclosing in [] fails with following error in MongoDB log

    bind_ip = [127.0.0.1,192.168.0.104]
    getaddrinfo("[127.0.0.1") failed: Name or service not known
    
    bind_ip = [127.0.0.1, 192.168.0.104]
    getaddrinfo("[127.0.0.1") failed: Name or service not known
    
    0 讨论(0)
  • 2020-12-09 02:27

    You can do that by:

    bindIp: [172.31.60.184,127.0.0.1]
    

    Remember to not put a space after the comma.

    0 讨论(0)
  • 2020-12-09 02:27

    The case in mongodb version 3.6 on my Ubuntu16.04 LTS is that you do not need to put the IP addresses in the square brackets "[]". Delete the space after the comma solve the failed connection problem in the mongod log (/var/log/mongodb/mongod.log)

    NETWORK  [initandlisten] getaddrinfo(" xxx.xxx.xxx.xxx") failed: Name or service not known
    

    After modify the bindIp: 127.0.0.1 to bindIp: 127.0.0.1,xxx.xxx.xxx.xxx (notice no comma between IPs), the host IP is listening as below:

    xxx@xxxx:/var/log/mongodb$ sudo netstat -plnt |egrep mongod
    tcp        0      0 xxx.xxx.xxx.xxx:27017   0.0.0.0:*               LISTEN      30747/mongod    
    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      30747/mongod 
    
    0 讨论(0)
提交回复
热议问题