0

MongoDB的設置。當我運行下面的命令:rs.initiate()創建副本在Linux中

我得到以下錯誤:

"info2" : "no configuration explicitly specified -- making one", 
     "me" : "ip-10-0-2-113:27017", 
     "ok" : 0, 
     "errmsg" : "No host described in new configuration 1 for replica set s-1-rs maps to this node", 
     "code" : 93 

我只是在本地主機上運行。我遵循本指南:http://docs.mongodb.org/manual/tutorial/convert-standalone-to-replica-set/

我剛剛跳過了他們命名副本集的地方。

無論如何,我該如何創建一個副本集以及我做錯了什麼?

感謝

+0

屬於[dba.stackexchange.com](http://dba.stackexchange.com)。 – zero323

回答

0
-- Replace your data and installation location accordingly. 
rm -rf ~/tmp/mongo_data 
mkdir -p ~/tmp/mongo_data/rs0_1 ~/tmp/mongo_data/rs0_2 ~/tmp/mongo_data/rs0_3 

nohup ~/Softwares/mongodb/bin/mongod --port 27017 --dbpath ~/tmp/mongo_data/rs0_1 --replSet rs0 & 
nohup ~/Softwares/mongodb/bin/mongod --port 27018 --dbpath ~/tmp/mongo_data/rs0_2 --replSet rs0 & 
nohup ~/Softwares/mongodb/bin/mongod --port 27019 --dbpath ~/tmp/mongo_data/rs0_3 --replSet rs0 & 

~/Softwares/mongodb/bin/mongo --port 27017 

rsconf = { 
     _id: "rs0", 
     members: [ 
        { 
        _id: 0, 
        host: "localhost:27017" 
        } 
       ] 
    } 

rs.initiate(rsconf) 
rs.conf() 


rs.add("localhost:27018") 
rs.add("localhost:27019") 

rs.status() 
1

給予整個過程對局部開始蒙戈複製。將來可能會幫助一個人。

爲三個mongod進程創建三個目錄。在unix上,可以這樣做:

mkdir -p /data/rs1 /data/rs2 /data/rs3 

現在啓動三個mongo實例,如下所示。請注意,有三個命令。

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

mongod --replSet s1 --logpath "2.log" --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork 

mongod --replSet s1 --logpath "3.log" --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork 

創建s1的複製集。

現在連接到mongo shell。

mongo --port 27017 

現在您將創建副本集。在mongo shell中輸入以下命令:

config = { _id: "s1", members:[ 
      { _id : 0, host : "localhost:27017"}, 
      { _id : 1, host : "localhost:27018"}, 
      { _id : 2, host : "localhost:27019"} ] 
}; 
rs.initiate(config); 

通過這個,您的副本集已啓動。您可以通過以下方式查看複製狀態:

rs.status()