我是Mongo的新手。我在我的ubuntu桌面上安装了mongo DB,并使用以下命令启动mongod服务 -
sudo service mongod start
root@monti-ThinkPad-L440:/home/monti# sudo service mongod start
root@monti-ThinkPad-L440:/home/monti# sudo service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2017-06-10 19:19:04 IST; 19s ago
Docs: https://docs.mongodb.org/manual
Main PID: 4407 (mongod)
CGroup: /system.slice/mongod.service
└─4407 /usr/bin/mongod --quiet --config /etc/mongod.conf
Jun 10 19:19:04 monti-ThinkPad-L440 systemd[1]: Started High-performance, schema-free document-oriented database.
但是当我启动mongo shell时,我遇到以下错误:
root@monti-ThinkPad-L440:/home/monti# mongo
MongoDB shell version: 3.2.13
connecting to: test
2017-06-10T19:20:44.363+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2017-06-10T19:20:44.363+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
任何帮助都非常赞赏!!!!谢谢!!!
答案 0 :(得分:1)
这个问题有很多好的和多个答案:
Connection refused to MongoDB errno 111
其中一个肯定会解决您的问题 通常由于/etc/mongod.conf中的一些配置错误或/var/lib/mongodb/mongod.lock中的锁定而发生
希望这有帮助!
答案 1 :(得分:0)
您可能需要在 /etc/mongod.conf 上将bind_ip更改为 0.0.0.0 将它绑定到127.0.0.1时无法访问您的计算机。
127.0.0.1只会绑定到loopback接口(所以你只能在本地访问它),而0.0.0.0会将它绑定到所有可以访问的网络接口。
这就是为什么你可以在将mongodb绑定到0.0.0.0而不是通过127.0.0.1时访问它。
对于本地服务器绑定到0.0.0.0可能会使它们在所有网络接口上可用。
在防火墙中,您应该确保仅打开27017 有权访问MongoDB服务器的人:如果您愿意 限制性更强,根据授权的IP范围更改0.0.0.0。
Example:
bindIp = [56.126.233.72, 172.29.19.240, 172.29.5.20/16]