在 Ubuntu 服务器上远程访问 MongoDB 时出错
Error remote access MongoDB on Ubuntu server
我在 Digital Ocean 有一个 Ubuntu 14.04 Linux 服务器和 MongoDB 3.2.4 运行 作为 droplet(一键式应用程序)。
Ping 服务器有效(发布后 Droplet 被销毁):
ping 198.199.125.101
我创建了数据库 test
和用户:
db.createUser({"user": "test", "pwd": "test", "roles": ["dbOwner"]})
在 mongod.conf
我更改了 bindIp: 0.0.0.0
并重新启动 mongoDB
我禁用了防火墙并重新启动了服务器。只是为了测试,只是为了证明 iptables 不是问题(不要在常规服务器上这样做):
sudo ufw disable
问题是我无法远程访问 mongo 数据库
mongo 198.199.125.101:27021/test -u "test" -p "test"
错误消息(连接被拒绝):
MongoDB shell version: 3.2.0
connecting to: 198.199.125.101:27021/test
2016-05-11T22:05:35.876+0200 W NETWORK [thread1] Failed to connect to 198.199.125.101:27021, reason: errno:61 Connection refused
2016-05-11T22:05:35.879+0200 E QUERY [thread1] Error: couldn't connect to server 198.199.125.101:27021, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6
exception: connect failed
先在mongo机器上运行netstat
验证27021端口是否打开。 netstat -anp
应该这样做。
然后执行 "telnet 127.0.0.1 27021" 以确保它已打开。
一旦你确定端口是打开的,然后使用telnet 198.199.125.101 27021
验证你可以连接到端口27021上的mongo机器。如果你可以,那么它与你有关应用程序。如果不是,那么某些东西正在阻止连接。一些防火墙什么的。你在 aws 上吗?
根据 netstat,您可以试试 mongo 198.199.125.101:27017/test -u "test" -p "test"
我在 Digital Ocean 有一个 Ubuntu 14.04 Linux 服务器和 MongoDB 3.2.4 运行 作为 droplet(一键式应用程序)。
Ping 服务器有效(发布后 Droplet 被销毁):
ping 198.199.125.101
我创建了数据库 test
和用户:
db.createUser({"user": "test", "pwd": "test", "roles": ["dbOwner"]})
在 mongod.conf
我更改了 bindIp: 0.0.0.0
并重新启动 mongoDB
我禁用了防火墙并重新启动了服务器。只是为了测试,只是为了证明 iptables 不是问题(不要在常规服务器上这样做):
sudo ufw disable
问题是我无法远程访问 mongo 数据库
mongo 198.199.125.101:27021/test -u "test" -p "test"
错误消息(连接被拒绝):
MongoDB shell version: 3.2.0
connecting to: 198.199.125.101:27021/test
2016-05-11T22:05:35.876+0200 W NETWORK [thread1] Failed to connect to 198.199.125.101:27021, reason: errno:61 Connection refused
2016-05-11T22:05:35.879+0200 E QUERY [thread1] Error: couldn't connect to server 198.199.125.101:27021, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6
exception: connect failed
先在mongo机器上运行netstat
验证27021端口是否打开。 netstat -anp
应该这样做。
然后执行 "telnet 127.0.0.1 27021" 以确保它已打开。
一旦你确定端口是打开的,然后使用telnet 198.199.125.101 27021
验证你可以连接到端口27021上的mongo机器。如果你可以,那么它与你有关应用程序。如果不是,那么某些东西正在阻止连接。一些防火墙什么的。你在 aws 上吗?
根据 netstat,您可以试试 mongo 198.199.125.101:27017/test -u "test" -p "test"