[英]Error remote access MongoDB on Ubuntu server
我有一台Ubuntu 14.04 Linux服務器,其中MongoDB 3.2.4作為一個小滴(一鍵式Apps)在Digital Ocean上運行。
對服務器執行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機器。如果可以,則與您的應用有關。 如果沒有,則說明有什么阻塞該連接。 一些防火牆之類的東西。 你在哭嗎?
根據netstat,您可以嘗試mongo 198.199.125.101:27017/test -u "test" -p "test"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.