2015-08-25 51 views
41

我在Ubuntu14.04服務器上安裝MongoDB的MongoDB的失敗:錯誤連接到數據庫服務器:沒有可以訪問的服務器

我無法連接通過「mongoimport」,「mongodump」,「mongostat」等方面的MongoDB它總是顯示「無可達服務器」

mongoimport --db test --collection restaurants --drop --file dataset.json 
2015-08-25T13:08:29.802+0800 [........................] test.restaurants 0.0 B/11.3 MB (0.0%) 
2015-08-25T13:08:30.306+0800 Failed: error connecting to db server: no reachable servers 
2015-08-25T13:08:30.306+0800 imported 0 documents 

不知怎的,我能夠連接與蒙戈外殼

mongo --port 27017 
MongoDB shell version: 3.0.6 
connecting to: 127.0.0.1:27017/test 

起初,我如果被我的iptables引起懷疑,所以我刷新所有iptables規則和創建規則都接受,但它仍然同樣

sudo iptables -S 
    -P INPUT ACCEPT 
    -P FORWARD ACCEPT 
    -P OUTPUT ACCEPT 
    -A INPUT -j ACCEPT 
    -A INPUT -i lo -j ACCEPT 
    -A FORWARD -j ACCEPT 
    -A OUTPUT -j ACCEPT 
    -A OUTPUT -o lo -j ACCEPT 

我搜索計算器和谷歌有人告訴劃分出 bind_ip或設置bind_ip爲0.0.0.0,我嘗試了所有,但還是失敗了。

下面是我的mangodb配置,有人可以幫我檢查嗎? 感謝您的幫助

[email protected]:~$ cat /etc/mongod.conf 
# mongod.conf 

# Where to store the data. 

# Note: if you run mongodb as a non-root user (recommended) you may 
# need to create and set permissions for this directory manually, 
# e.g., if the parent directory isn't mutable by the mongodb user. 
dbpath=/var/lib/mongodb 

#where to log 
logpath=/var/log/mongodb/mongod.log 

logappend=true 

port = 27017 

# Listen to local interface only. Comment out to listen on all interfaces. 
#bind_ip = 127.0.0.1 
# Disables write-ahead journaling 
# nojournal = true 

# Enables periodic logging of CPU utilization and I/O wait 
#cpu = true 

# Turn on/off security. Off is currently the default 
#noauth = true 
#auth = true 

# Verbose logging output. 
verbose = true 

# Inspect all client data for validity on receipt (useful for 
# developing drivers) 
#objcheck = true 

# Enable db quota management 
#quota = true 

# Set oplogging level where n is 
# 0=off (default) 
# 1=W 
# 2=R 
# 3=both 
# 7=W+some reads 
#diaglog = 0 

# Ignore query hints 
#nohints = true 

# Enable the HTTP interface (Defaults to port 28017). 
#httpinterface = true 

# Turns off server-side scripting. This will result in greatly limited 
# functionality 
#noscripting = true 

# Turns off table scans. Any query that would do a table scan fails. 
#notablescan = true 

# Disable data file preallocation. 
#noprealloc = true 

# Specify .ns file size for new databases. 
# nssize = <size> 

# Replication Options 

# in replicated mongo databases, specify the replica set name here 
#replSet=setname 
# maximum size in megabytes for replication operation log 
#oplogSize=1024 
# path to a key file storing authentication info for connections 
# between replica set members 
#keyFile=/path/to/keyfile 
+0

您的'mongod'進程顯然沒有運行。查看日誌'/ var/log/mongodb/mongod.log'是爲什麼。還要確保你遵循了[在Ubuntu上安裝MongoDB]的所有說明(http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/)。嘗試啓動該服務,或重新啓動機器。如有必要,請安裝。 –

+0

將此作爲答案提交,因爲我無權發表評論。我有一個3成員副本集(版本3.4),並面臨與下面的命令相同的問題。 mongoimport --db test --drop rides.json與[whythecode](https://stackoverflow.com/users/5000167/whythecode),
mongoimport --host = 127.0.0.1建議的以下命令有相同的錯誤 - -db test rides.json以下命令能夠導入mongoimport --host = 127.0.0.1:27018 --db test rides.json請注意,主節點正在27018上運行。此外,沒有必要重置副本設置或運行它作爲獨立。 –

回答

73

暫時的解決辦法是將host PARAM添加到您的通話mongoimport,讓蒙戈知道問題主機是你自己的機器(127.0.0.1):

mongoimport --host=127.0.0.1 

你的情況完整的命令則是:

mongoimport --host=127.0.0.1 \ 
    --db test --collection restaurants --drop --file dataset.json 

(來源:ranjeetcao @ mongorestore Failed: no reachable servers


更新:

更新到蒙戈> = 3.0.7應該解決該問題

(來源:Colin Marshall @ mongorestore Failed: no reachable servers


Update 2:

看來是Bug is still happening for some users

還有一個開放的JIRA問題here

(來源:James Chien @ this question thread


更新3:

在某些情況下,這可以通過運行蒙戈作爲ReplicaSet引起。爲了解決這個問題,據我所見,可以禁用ReplicaSet功能或重置它。請參閱:

(來源:Maxim Yefremov @ mongorestore Failed: no reachable servers

+1

解決方法效果很好。如果你想進一步解決問題,所以你不必使用解決方法,然後在這裏看到我的答案:http://stackoverflow.com/a/33139963/2755888 –

+0

嘿,謝謝你的提醒!我會更新答案來反映它 – whythecode

+0

沒問題!乾杯! –

1

我覺得這個答案鏈接https://jira.mongodb.org/browse/TOOLS-620 這似乎是一個還不解決的MongoDB的工具的bug。 不確定是否有人知道最新的工具是否解決了這個問題?

BTW,我卸載的MongoDB工具3.x和重新安裝到2.6.0是解決

sudo apt-get purge mongodb-org-tools 
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list 
sudo apt-get update 
sudo apt-get install -y mongodb-org-tools=2.6.0 

mongoimport --db test --collection restaurants --drop --file dataset.json 
connected to: 127.0.0.1 
2015-08-25T15:19:59.494+0800 dropping: test.restaurants 
2015-08-25T15:20:00.089+0800 check 9 25359 
2015-08-25T15:20:00.089+0800 imported 25359 objects 
1

完整的命令:

mongoimport --host=127.0.0.1 -d testdb -c testc --file test.txt 
+0

這不會提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/ review/low-quality-posts/11097993) – cviejo

+0

爲什麼不呢?主要答案只有「mongoimport --host = 127.0.0.1」,所以新人會對此感到困惑,他們可以使用完整的命令。 –

+1

@shemeermali你是對的,最好是規定完整的命令 - 答案已經更新。謝謝! – whythecode

-2
mongorestore --db <thedb> --host=127.0.0.1 --port=<port> --drop path/db 
+0

你應該詳細解釋你的答案,以便將來的人可以理解你在這裏做什麼(只需編輯問題) – Machavity

+0

這將失敗以及'MongoDB外殼版本:3.2.3' – loretoparisi

+0

偉大的@Machavity。 – Jekayode

0

如果您在通過自制停滯不前MongoDB的,那麼你可以簡單地啓動MongoDB中通過

brew services start mongodb 

然後通過

mongo 

你可以關閉你的數據庫由

brew services stop mongodb 

訪問殼更多選項

brew info mongodb 
相關問題