MongoDB 运行 在本地但尝试远程访问时失败

MongoDB running locally but when trying to access remotely it failed

能够在本地运行 MongoDB,但在尝试远程访问时却失败了。还没有完成任何防火墙设置。可能是什么问题?如何解决问题?

同时 MongoDB 状态显示 运行ning

service mongod status
mongod (pid 25342) is running...

但是当尝试重新启动服务时它说

service mongod restart
Stopping mongod:                                           [  OK  ]
Starting mongod:                                           [FAILED]

但是进程还是运行宁

更新

尝试了 mongod --repair 这里是更新

2015-01-10T10:46:33.109-0500 [initandlisten] MongoDB starting : pid=29018 port=2                                                                                        7017 dbpath=/data/db 64-bit host=ns4008927.ip-192-99-3.net
2015-01-10T10:46:33.109-0500 [initandlisten] db version v2.6.6
2015-01-10T10:46:33.109-0500 [initandlisten] git version: 608e8bc319627693b04cc7                                                                                        da29ecc300a5f45a1f
2015-01-10T10:46:33.109-0500 [initandlisten] build info: Linux build10.nj1.10gen                                                                                        .cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LI                                                                                        B_VERSION=1_49
2015-01-10T10:46:33.109-0500 [initandlisten] allocator: tcmalloc
2015-01-10T10:46:33.109-0500 [initandlisten] options: { repair: true }
2015-01-10T10:46:33.112-0500 [initandlisten] finished checking dbs
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit:
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close listening                                                                                         sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to flush diaglog...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: waiting for fs preallocat                                                                                        or...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: closing all files...
2015-01-10T10:46:33.112-0500 [initandlisten] closeAllFiles() finished
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: removing fs lock...
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit: really exiting now

您需要从 mongo 的配置文件中删除此行(在 Ubuntu 上,我的在 /etc/mongod.conf):

bind_ip = 127.0.0.1

或者,如果是 YAML,

bindIp: 127.0.0.1

来源:http://docs.mongodb.org/manual/reference/configuration-options/

"Changed in version 2.6.0: The deb and rpm packages include a default configuration file that sets net.bindIp to 127.0.0.1."

bindIp/bind_ip 的默认值是 "all interfaces" - 因此删除就派上用场了。