標籤:
本文示範:(一個主伺服器,一個備份伺服器,三個仲裁伺服器)
官方推薦複本集的成員數量為奇數,最多12個複本集節點,最多7個節點參與選舉。
本文示範基於本機,用連接埠區分服務(每個伺服器下建立db檔案夾用於儲存資料,mongodb.conf檔案配置啟動參數)
各個伺服器設定檔內容如下:
27000主伺服器
dbpath=D:\MongoDB\Server27000\3.2\db
port=27000
replSet=datamip/127.0.0.1:27001
//複本集下面有其他伺服器27001
27001備份伺服器
dbpath=D:\MongoDB\Server27001\3.2\db
port=27001
replSet=datamip/127.0.0.1:27000
//主伺服器
27002仲裁伺服器
dbpath=D:\MongoDB\Server27002\3.2\db
port=27002
replSet=datamip/127.0.0.1:27001
//主伺服器
27003仲裁伺服器
dbpath=D:\MongoDB\Server27003\3.2\db
port=27003
replSet=datamip/127.0.0.1:27001
//主伺服器
27004仲裁伺服器
dbpath=D:\MongoDB\Server27004\3.2\db
port=27004
replSet=datamip/127.0.0.1:27001
//主伺服器
27000主伺服器27001備份伺服器27002仲裁伺服器27003仲裁伺服器27004仲裁伺服器建立服務sc.exe create MongoDB27000 binPath= "C:\MongoDB\Server27000\bin\mongod.exe --service --config=\"C:\MongoDB\Server27000\mongodb.conf"" DisplayName= "MongoDB27000" start= "auto"sc.exe create MongoDB27001 binPath= "C:\MongoDB\Server27001\bin\mongod.exe --service --config=\"C:\MongoDB\Server27001\mongodb.conf"" DisplayName= "MongoDB27001" start= "auto"sc.exe create MongoDB27002 binPath= "C:\MongoDB\Server27002\bin\mongod.exe --service --config=\"C:\MongoDB\Server27002\mongodb.conf"" DisplayName= "MongoDB27002" start= "auto"sc.exe create MongoDB27003 binPath= "C:\MongoDB\Server27003\bin\mongod.exe --service --config=\"C:\MongoDB\Server27003\mongodb.conf"" DisplayName= "MongoDB27003" start= "auto"sc.exe create MongoDB27004 binPath= "C:\MongoDB\Server27004\bin\mongod.exe --service --config=\"C:\MongoDB\Server27004\mongodb.conf"" DisplayName= "MongoDB27004" start= "auto"啟動服務>mongo 192.168.200.111:27000/admin//串連primary>db.runCommand({"replSetInitiate":{"_id":"datamip","members":[{"_id":1,"host":"192.168.200.111:27000"},{"_id":2,"host":"192.168.200.111:27001"}]}}) 稍等片刻,等待27000變為primary時添加如下配置>mongo 192.168.200.111:27000/admin>rs.addArb("192.168.200.111:27002")>rs.addArb("192.168.200.11127003")>rs.addArb("192.168.200.111:27004")
MongoDB叢集配置