Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot start MongoDB service as I bind a specified IP

Tags:

mongodb

My current MongoDB configuration,

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" } }

Here's the issue I am having,

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
like image 312
wgc Avatar asked Nov 17 '22 21:11

wgc


1 Answers

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

like image 158
Max Sherbakov Avatar answered Jan 13 '23 06:01

Max Sherbakov