2012-05-30 151 views
4

我一想這一個:蒙戈DB問題與複製集

mongod --replSet mySet --dbpath /data/r1 --port 27017 --oplogSize 700

mongod --replSet mySet --dbpath /data/r2 --port 27018 --oplogSize 700

mongod --replSet mySet --dbpath /data/r3 --port 27019 --oplogSize 700

然後在新的終端:

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

> cfg = { 

    _id : "mySet", 
    members : [ 
    { _id : 0, host : "localhost:27017" }, 
    { _id : 1, host : "localhost:27018" }, 
    { _id : 2, host : "localhost:27019" } ] } 

當我運行

rs.initiate(cfg)

我一收到此錯誤:

{ "errmsg" : "server is not running with --replSet", "ok" : 0 }

爲什麼我得到這個錯誤?

從日誌文件:

Fri Jun 01 15:05:11 [initandlisten] MongoDB starting : pid=5236 port=27017 dbpath=c:\mongodb\data 64-bit host=mami 
Fri Jun 01 15:05:11 [initandlisten] db version v2.0.4, pdfile version 4.5 
Fri Jun 01 15:05:11 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf 
Fri Jun 01 15:05:11 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 
Fri Jun 01 15:05:11 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } 
Fri Jun 01 15:05:11 [initandlisten] journal dir=c:/mongodb/data/journal 
Fri Jun 01 15:05:11 [initandlisten] recover : no journal files present, no recovery needed 
Fri Jun 01 15:05:12 [initandlisten] waiting for connections on port 27017 
Fri Jun 01 15:05:12 [websvr] admin web console waiting for connections on port 28017 
Fri Jun 01 15:05:12 [initandlisten] connection accepted from 127.0.0.1:49663 #1 
Fri Jun 01 15:05:56 [conn1] end connection 127.0.0.1:49663 
Fri Jun 01 15:06:02 [initandlisten] connection accepted from 127.0.0.1:49669 #2 
Fri Jun 01 15:06:11 [clientcursormon] mem (MB) res:22 virt:67 mapped:0 
Fri Jun 01 15:06:19 [conn2] terminating, shutdown command received 
Fri Jun 01 15:06:19 dbexit: shutdown called 
Fri Jun 01 15:06:19 [conn2] shutdown: going to close listening sockets... 
Fri Jun 01 15:06:19 [conn2] closing listening socket: 488 
Fri Jun 01 15:06:19 [conn2] closing listening socket: 492 
Fri Jun 01 15:06:19 [conn2] shutdown: going to flush diaglog... 
Fri Jun 01 15:06:19 [conn2] shutdown: going to close sockets... 
Fri Jun 01 15:06:19 [conn2] shutdown: waiting for fs preallocator... 
Fri Jun 01 15:06:19 [conn2] shutdown: lock for final commit... 
Fri Jun 01 15:06:19 [conn2] shutdown: final commit... 
Fri Jun 01 15:06:19 [conn2] shutdown: closing all files... 
Fri Jun 01 15:06:19 [conn2] closeAllFiles() finished 
Fri Jun 01 15:06:19 [conn2] journalCleanup... 
Fri Jun 01 15:06:19 [conn2] removeJournalFiles 
Fri Jun 01 15:06:19 [conn2] shutdown: removing fs lock... 
Fri Jun 01 15:06:19 dbexit: really exiting now 


***** SERVER RESTARTED ***** 


Fri Jun 01 15:06:19 [initandlisten] MongoDB starting : pid=6980 port=27017 dbpath=c:\mongodb\data 64-bit host=mami 
Fri Jun 01 15:06:19 [initandlisten] db version v2.0.4, pdfile version 4.5 
Fri Jun 01 15:06:19 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf 
Fri Jun 01 15:06:19 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 
Fri Jun 01 15:06:19 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } 
Fri Jun 01 15:06:19 [initandlisten] journal dir=c:/mongodb/data/journal 
Fri Jun 01 15:06:19 [initandlisten] recover : no journal files present, no recovery needed 
Fri Jun 01 15:06:19 [initandlisten] waiting for connections on port 27017 
Fri Jun 01 15:06:20 [websvr] admin web console waiting for connections on port 28017 
Fri Jun 01 15:06:20 [initandlisten] connection accepted from 127.0.0.1:49678 #1 
Fri Jun 01 15:06:22 [conn1] end connection 127.0.0.1:49678 
Fri Jun 01 15:06:30 [initandlisten] connection accepted from 127.0.0.1:49679 #2 
Fri Jun 01 15:06:36 [conn2] terminating, shutdown command received 
Fri Jun 01 15:06:36 dbexit: shutdown called 
Fri Jun 01 15:06:36 [conn2] shutdown: going to close listening sockets... 
Fri Jun 01 15:06:36 [conn2] closing listening socket: 488 
Fri Jun 01 15:06:36 [conn2] closing listening socket: 492 
Fri Jun 01 15:06:36 [conn2] shutdown: going to flush diaglog... 
Fri Jun 01 15:06:36 [conn2] shutdown: going to close sockets... 
Fri Jun 01 15:06:36 [conn2] shutdown: waiting for fs preallocator... 
Fri Jun 01 15:06:36 [conn2] shutdown: lock for final commit... 
Fri Jun 01 15:06:36 [conn2] shutdown: final commit... 
Fri Jun 01 15:06:36 [conn2] shutdown: closing all files... 
Fri Jun 01 15:06:36 [conn2] closeAllFiles() finished 
Fri Jun 01 15:06:36 [conn2] journalCleanup... 
Fri Jun 01 15:06:37 [conn2] removeJournalFiles 
Fri Jun 01 15:06:37 [conn2] shutdown: removing fs lock... 
Fri Jun 01 15:06:37 dbexit: really exiting now 


***** SERVER RESTARTED ***** 


Fri Jun 01 15:06:37 [initandlisten] MongoDB starting : pid=7076 port=27017 dbpath=c:\mongodb\data 64-bit host=mami 
Fri Jun 01 15:06:37 [initandlisten] db version v2.0.4, pdfile version 4.5 
Fri Jun 01 15:06:37 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506cb21f8ebf 
Fri Jun 01 15:06:37 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_42 
Fri Jun 01 15:06:37 [initandlisten] options: { dbpath: "c:\mongodb\data", logappend: true, logpath: "c:\mongodb\logs\logfilename.log", service: true } 
Fri Jun 01 15:06:37 [initandlisten] journal dir=c:/mongodb/data/journal 
Fri Jun 01 15:06:37 [initandlisten] recover : no journal files present, no recovery needed 
Fri Jun 01 15:06:37 [initandlisten] waiting for connections on port 27017 
Fri Jun 01 15:06:37 [websvr] admin web console waiting for connections on port 28017 
Fri Jun 01 15:06:37 [initandlisten] connection accepted from 127.0.0.1:49680 #1 
Fri Jun 01 15:06:39 [conn1] end connection 127.0.0.1:49680 
Fri Jun 01 15:07:37 [clientcursormon] mem (MB) res:22 virt:66 mapped:0 
Fri Jun 01 15:53:55 [clientcursormon] mem (MB) res:0 virt:64 mapped:0 
Fri Jun 01 15:58:55 [clientcursormon] mem (MB) res:1 virt:64 mapped:0 
Fri Jun 01 15:59:24 [initandlisten] connection accepted from 127.0.0.1:50087 #2 
Fri Jun 01 15:59:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0 
Fri Jun 01 16:04:55 [clientcursormon] mem (MB) res:2 virt:65 mapped:0 
Fri Jun 01 16:06:07 [conn2] replSet replSetInitiate admin command received from client 

I`ve嘗試本教程replSet,但仍然沒有

,我能想到的

回答

16

原因之一是,你已經對端口27017運行的mongod沒有--replSet在嘗試開始之前的爭論。確保沒有mongod正在運行(ps aux |grep mongod),然後再嘗試。我也會檢查日誌文件,因爲它可能提供了一個線索,爲什麼它不以副本集模式啓動。

+0

嗨!仍然得到這個錯誤... – Kuralai

+0

你也還沒有提供更多的信息,或者你實際上已經做了什麼... – Derick

+0

沒有,這沒關係我已經解決了這個問題。問題是因爲我正在運行另一個mongod運行...謝謝! – Kuralai

2

我發現一個簡單的解決方案是爲--replSet指定一個子參數。

配置我蒙戈服務器與因爲它作爲PRYMARY只有一個節點ReplicaSet,也不會有爲READ效果影響不大,另一個節點。

這是什麼幫助我運行mongod服務。

/> sudo mongod --replSet myReplSet

有一次,我與蒙戈記錄則提示發生變化,那麼我可以正確地配置RS:

/myReplSet:PRIMARY> cfg = { _id : "mySet", members : [ { _id : 0, host : "localhost:27017" } ] }

/myReplSet:PRIMARY> rs.initiate(cfg)

,這把把戲!

我希望這可以幫助別人。

0

我有完全相同的問題,而這樣做我的MongoDB複製分片&功課.. 只需運行以下命令後:

./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork 

,然後做ps aux | grep mongo檢查我意識到沒有什麼實際上正在運行。 我做了什麼讓它的工作只是爲系統根所以最後我跑一樣的mongod進程運行這些命令:

sudo ./mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork 

這就是它! :)

希望它有幫助。

1

我注意到它的Linux許可問題,建議後above.To解決它,你需要設定數據許可目錄的命令,因爲這是sudo chown -R $USER /data。 我與npm有同樣的問題。

0

我設法解決這個問題。

  1. 我第一次刪除的MongoDB: sudo易於得到刪除MongoDB的

  2. I followed the MongoDB tutorial:

  3. 然而,步驟後...: sudo易於得到更新

  4. ...我決定重新安裝mongodb: sudo apt-get remove mongodb (在這一步我可能指定'mo ngodb服務器「)。

而且,神奇的是,replSet名稱能夠從mongodb.conf中加載。 我被留給rs.initiate() - 就是這樣。

注:我從2.4.9開始,並完成相同的2.4.9 - 只是工作。

0

有同樣的問題,所以在我的情況下,有一個更多的mongod進程在系統中運行(當然是運行沒有--replSet標誌在默認端口,這就是爲什麼我有這個錯誤)。

運行命令:

$ ps aux | grep mongod 
在我的情況下,它輸出

root 63434 0.3 0.1 2621328 12228 ?? S 5:53PM 0:03.44 mongod --replSet m101 --logpath 1.log --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork 

root 63442 0.2 0.1 2622352 12220 ?? S 5:54PM 0:03.37 mongod --replSet m101 --logpath 2.log --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork 

root 63448 0.2 0.1 2621312 12208 ?? S 5:54PM 0:03.35 mongod --replSet m101 --logpath 3.log --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork 

pavlo 683 0.0 0.0 3082276 6628 ?? S 31Aug14 11:27.70 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf 

pavlo 63522 0.0 0.0 2432784 624 s002 S+ 6:06PM 0:00.00 grep mongod 

所以ID爲683這個過程是一個方式,所以之後我殺了它一切正常:

$ kill 683 
0

是的,在我的Ubuntu 15.04上也一樣。並通過解決端口解決它。另外,請檢查日誌,以便執行狀態讓我們知道它的工作方式。