我绑定指定的IP时无法启动MongoDB服务

时间:2018-02-02 03:30:05

标签: mongodb

我当前的MongoDB配置,

options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.0.204", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/var/lib/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }

这是我遇到的问题,

2018-02-02T19:16:32.017+0800 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2018-02-02T19:16:32.017+0800 I CONTROL  [initandlisten] now exiting
2018-02-02T19:16:32.017+0800 I CONTROL  [initandlisten] shutting down with code:48

2 个答案:

答案 0 :(得分:1)

First solution on *nix: You could bind_ip = 0.0.0.0 and use a firewall to block all incoming connections to port 27017, unless coming from local ip adress. Second solution

Restart mongo:

> service mongod restart

Go to to /var/logs/mongodb and give the information from logs.

Let try to test mongo, is it running localy with default options?

> service mongod status

That tells you the status of mongo. If it disactive, go to logs, in my case it /var/logs/mongodb get info from log.

Then, lets try to start mongo without remote IP option. goto /etc/mongod.conf and set up option only on local ip, bindIp 127.0.0.1 then

service mongod restart

and

service mongod status

Is it running? If everything is fine, You need determine what your's local lan ip addres.

in my case it was command, other commands link

LANG=c ifconfig | grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'

After that add it ip addres to mongo conf with comma separated option. like: bindIp 127.0.0.1, 192.168.1.66

than save config and simply restart mongo

service mongod restart

答案 1 :(得分:0)

bind_ip用于“仅本地接口”,将192.168.162.129(服务器A专用ip)放在同一LAN上足以供客户端(例如服务器B)访问。

使用这些步骤将起作用:

  1. sudo vim /etc/mongodb.conf
  2. bind_ip = 127.0.0.1,172.31.29.201
  3. 请注意172.31.29.201是私有IP,而不是公共IP。请在此处使用私有IP
  4. sudo服务mongodb重新启动
  5. sudo服务mongodb状态-检查mongodb服务是否正在运行
  6. 享受