Mongodb分片副本

Mongodb分片副本,mongodb,replication,database-replication,sharding,high-availability,Mongodb,Replication,Database Replication,Sharding,High Availability,我有3个用于分片和configserver的节点(分片服务器在标准端口27017上运行,configserver在端口27019上运行) 和一个查询路由器 stage-query0-mongo 在我当前的设置中 切分正如预期的那样完美地工作 --- Sharding Status --- sharding version: { "_id" : 1, "version" : 3, "minCompatibleVersion" : 3, "currentVersion" : 4, "cluste

我有3个用于分片和configserver的节点(分片服务器在标准端口27017上运行,configserver在端口27019上运行)

和一个查询路由器

stage-query0-mongo
在我当前的设置中

切分正如预期的那样完美地工作

--- 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
现在,我正在这些节点上启用副本集。我登录到stage-mongo1-tmp,然后运行

rs.initiate()
并添加stage-mongo2-tmp和stage-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
当我连接到另一个节点时,其中一个节点已自动选择为主节点。但是,我的查询仍然返回错误。
我在副本集中做错了什么?为什么它的可用性不高?我是否需要添加更多服务器以提高可用性?我正在寻找一个最小的服务器集来实现这一点。

解决了。我们为复制集添加碎片

sh.addShard(“rs0/:端口,…)

完成后,我们需要在数据库级别和集合级别启用分片。这将启用分片和副本

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