Replication
在 ec2 問題上創建 mongo 3 節點副本集
我正在嘗試在 ec2 實例上創建一個 3 節點的 mongo 副本集群,內部 ips 為 10.168.xxx.xxx、10.166.xxx.xxx 和 10.188.xxx.xxx,我的配置文件是:
dbpath = /home/ubuntu/mongo-data/ logpath = /home/ubuntu/mongo-data/mongod.log logappend = true journal = true fork = true smallfiles = true pidfilepath = /home/ubuntu/mongo-data/mongod.pid replSet = appNameReplicaSet
我
mongod -f mongod.config
在每個實例上啟動,並在我嘗試過的一個實例上啟動:$ mongo > rs.initiate(); { "info2" : "no configuration explicitly specified -- making one", "me" : "ip-10-168-66-132:27017", "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } > rs.add('10.166.xxx.xxx:27017'); //after LONG pause { "errmsg" : "exception: need most members up to reconfigure, not ok : 10.188.22.254:27017", "code" : 13144, "ok" : 0 }
我也試過:
config = { _id: 'appNameReplicaSet', members: [ {_id: 0, host: '10.168.xxx.xxx:27017'}, {_id: 1, host: '10.166.xxx.xxx:27017'}, {_id: 2, host: '10.188.xxx.xxx:27017'} ] } rs.reconfig(config, {'force':true}) { "ok" : 0, "errmsg" : "a replSetReconfig is already in progress" }
.log 文件:
Sat Jul 27 01:33:59.149 [initandlisten] connection accepted from 127.0.0.1:36931 #4 (1 connection now open) Sat Jul 27 01:34:02.468 [conn4] replSet replSetInitiate admin command received from client Sat Jul 27 01:34:02.470 [conn4] replSet info initiate : no configuration specified. Using a default configuration for the set Sat Jul 27 01:34:02.470 [conn4] replSet created this configuration for initiation : { _id: "appNameReplicaSet", members: [ { _id: 0, host: "ip-10-168-xxx-xxx:27017" } ] } Sat Jul 27 01:34:02.470 [conn4] replSet replSetInitiate config object parses ok, 1 members specified Sat Jul 27 01:34:02.473 [conn4] replSet replSetInitiate all members seem up Sat Jul 27 01:34:02.473 [conn4] ****** Sat Jul 27 01:34:02.473 [conn4] creating replication oplog of size: 990MB... Sat Jul 27 01:34:02.474 [FileAllocator] allocating new datafile /home/ubuntu/mongo-data/local.1, filling with zeroes... Sat Jul 27 01:34:02.485 [FileAllocator] done allocating datafile /home/ubuntu/mongo-data/local.1, size: 511MB, took 0.01 secs Sat Jul 27 01:34:02.485 [FileAllocator] allocating new datafile /home/ubuntu/mongo-data/local.2, filling with zeroes... Sat Jul 27 01:34:02.491 [FileAllocator] done allocating datafile /home/ubuntu/mongo-data/local.2, size: 511MB, took 0.005 secs Sat Jul 27 01:34:02.491 [conn4] ****** Sat Jul 27 01:34:02.491 [conn4] replSet info saving a newer config version to local.system.replset Sat Jul 27 01:34:02.492 [conn4] replSet saveConfigLocally done Sat Jul 27 01:34:02.492 [conn4] replSet replSetInitiate config now saved locally. Should come online in about a minute. Sat Jul 27 01:34:08.435 [rsStart] replSet I am ip-10-168-xxx-xxx:27017 Sat Jul 27 01:34:08.435 [rsStart] replSet STARTUP2 Sat Jul 27 01:34:09.441 [rsSync] replSet SECONDARY Sat Jul 27 01:34:09.441 [rsMgr] replSet info electSelf 0 Sat Jul 27 01:34:10.440 [rsMgr] replSet PRIMARY Sat Jul 27 01:34:26.513 [conn4] replSet replSetReconfig config object parses ok, 2 members specified Sat Jul 27 01:37:45.835 [conn4] couldn't connect to 10.188.xxx.xxx:27017: couldn't connect to server 10.188.xxx.xxx:27017
更新:添加了 rs.initiate() 和日誌的輸出;
這可能是防火牆問題。長暫停是套接字連接在等待超時時掛起。
預設情況下,在 EC2 上,實例的安全組(例如防火牆規則)拒絕所有入站流量。您必須明確指定允許連接的 IP 範圍或安全組成員。
使用安全組而不是 IP 通常更易於維護。它允許您稍後添加/刪除其他伺服器,而無需擔心更新動態分配的 IP 地址。您只需要將它們包含在同一個安全組中。
要進行設置:
- 專門為您的 MongoDB 實例創建一個安全組。讓我們稱它為“我的 MongoDB SG”,並假設 AWS 給了它唯一的 id
sg-123456
。- 編輯安全組的入站防火牆規則以允許埠上來自同一安全組的流量。該條目應如下所示:
源埠 SG-123456 27017
- 將安全組添加到您的每個 MongoDB 實例
然後您可以重試啟動集群。