0

我對分片和configserver 3個節點(分片服務器上的標準端口27017和configserver運行在端口27019運行)MongoDB的分片副本

stage-mongo1-tmp, stage-mongo2-tmp, and stage-mongo3-tmp 

,並在我目前的查詢路由器

stage-query0-mongo 

建立。

Sharding正在按預期工作。

--- Sharding Status --- 
sharding version: { 
"_id" : 1, 
"version" : 3, 
"minCompatibleVersion" : 3, 
"currentVersion" : 4, 
"clusterId" : ObjectId("5321a5cc8a18e5280f7c9d5a") 
} 
shards: 
{ "_id" : "shard0000", "host" : "stage-mongo1-tmp:27017" } 
{ "_id" : "shard0001", "host" : "stage-mongo2-tmp:27017" } 
{ "_id" : "shard0002", "host" : "stage-mongo3-tmp:27017" } 
databases: 
{ "_id" : "admin", "partitioned" : false, "primary" : "config" } 
{ "_id" : "testdb", "partitioned" : true, "primary" : "shard0000" } 
    testdb.testcollection 
     shard key: { "_id" : "hashed" } 
     chunks: 
      shard0001 28 
      shard0002 31 
      shard0000 28 
     too many chunks to print, use verbose if you want to force print 

現在,我在這些節點上啓用了副本集。我登錄到舞臺mongo1-TMP,跑

rs.initiate() 

,並添加階段mongo2-TMP和階段mongo3-TMP的副本成員

rs.add("stage-mongo2-tmp") 

日誌文件說,啓用複製和選出一名小學生。 rs.conf() 中表現出良好的輸出

[rsBackgroundSync] replSet syncing to: stage-mongo1-tmp:27017 
[rsSync] oplog sync 2 of 3 
[rsSyncNotifier] replset setting oplog notifier to stage-mongo1-tmp:27017 
[rsSync] replSet initial sync building indexes 
[rsSync] replSet initial sync cloning indexes for : ekl_omniscient 
[rsSync] build index ekl_omniscient.serviceability { _id: "hashed" } 
[rsSync] build index done. scanned 571242 total records. 3.894 secs 
replSet RECOVERING 
replSet initial sync done 
replSet SECONDARY 

然而,當我通過採取一個節點向下測試高可用性,查詢節點上mongos將返回錯誤說

mongos> show dbs; 
    Thu Mar 13 20:17:04.394 listDatabases failed:{ 
"code" : 11002, 
"ok" : 0, 
"errmsg" : "exception: socket exception [CONNECT_ERROR] for stage-mongo1-tmp:27017"} at src/mongo/shell/mongo.js:46 

當我連接到另一個節點,其中一個自動選爲主節點。但仍然,我的查詢返回錯誤。 我在這裏做錯了副本集?爲什麼它不可用?我是否需要添加更多服務器以使其可用?我正在尋找一套最低限度的服務器來實現這一點。

回答

1

想通了。我們爲副本集添加碎片。

sh.addShard。(「RS 0 /:端口,..)

一旦做到這一點,我們需要啓用的分貝水平和收藏水平切分這將使分片和副本