分片的mongodb集群仅使用一个分片

时间:2018-07-27 09:54:00

标签: mongodb sharding replicaset

我正在尝试创建一个分片的mongodb集群,我要使用3个VM,并且试图进行以下设置:

  

VM1)Node.js应用程序+ mongos实例

     

VM2)CSRS主+分片

     

VM3)CSRS次要+碎片

我对复制不感兴趣,但是我需要分片,因为我将不得不查询大量结果。 为了实现上述目的,我做了以下工作:

在VM2和VM3上

mongod –configsvr  --replSet configM4C –bind_ip <ipVM2/3> --port 27040
mongod –shardsvr --replSet shardM4C --bind_ip <ipVM2/3> --port 27041

然后,连接到VM2上的configM4C( mongo --host --port 27040 )并运行

rs.initiate({
    _id:”configM4C”,
    configsvr: true,
    members: [
        {_id: 0, host: “<ipVM2>:27040”},
        {_id:1, host: “<ipVM3>:27040”}
    ]
})

然后,连接到VM2上的shardM4C( mongo --host --port 27041 )并运行

rs.initiate({
    _id: shardM4C,
    members: [
        {_id: 0, host: “<ip1>:27041”},
        {_id:1, host: “<ip2>:27041”}
    ]
})

在VM1上启动mongos

mongos –configdb configM4C/<ipVM2>:27040,<ipVM3>:27040 --port 27042

已连接到VM1上的mongos( mongo --port 27042 ):

sh.addShard("<ipVM2>:27041)
sh.addShard("<ipVM3>:27041)
sh.enableSharding("pings")
sh.shardCollection("pings.pings", {provider:1, from_zone: 1, to_zone: 1})

无论如何,如果我运行 db.pings.getShardDistribution(),我都会得到:

Shard shardM4C at shardM4C/<ipVM3>:27041,<ipVM2>:27041
data : 19.47MiB docs : 102876 chunks : 1
estimated data per chunk : 19.47MiB
estimated docs per chunk : 102876

Totals
data : 19.47MiB docs : 102876 chunks : 1
Shard shardM4C contains 100% data, 100% docs in cluster, avg obj size on shard : 198B

sh.status():

 sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5b58a6b4986cc2d94694a3f9")
  }
  shards:
        {  "_id" : "shardM4C",  "host" : "shardM4C/10.0.0.4:27041,10.0.0.7:27041",  "state" : 1 }
  active mongoses:
        "3.6.3" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  5
        Last reported error:  Could not find host matching read preference { mode: "primary" } for set shardM4C
        Time of Reported error:  Wed Jul 25 2018 21:44:24 GMT+0000 (UTC)
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shardM4C    1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shardM4C Timestamp(1, 0) 
        {  "_id" : "pings",  "primary" : "shardM4C",  "partitioned" : true }
                pings.pings
                        shard key: { "provider" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shardM4C    1
                        { "provider" : { "$minKey" : 1 } } -->> { "provider" : { "$maxKey" : 1 } } on : shardM4C Timestamp(1, 0) 
        {  "_id" : "test",  "primary" : "shardM4C",  "partitioned" : false }

如果我在executionStats中运行查询,我会得到:

...
"queryPlanner" : {
        "mongosPlannerVersion" : 1,
        "winningPlan" : {
            "stage" : "SINGLE_SHARD",
            "shards" : [
                {
                    "shardName" : "shardM4C",
                    "connectionString" : "shardM4C/<ipVM3>:27041,<ipVM2>:27041",
                    "serverInfo" : {
                        "host" : "dpiscaglia-2",
                        "port" : 27041,
                        "version" : "3.6.3",
                        "gitVersion" : "9586e557d54ef70f9ca4b43c26892cd55257e1a5"
                    },
...

这两个结果都使我认为查询实际上仅在一个分片上工作,第二个仅用于复制并作为备份(这不是我想要的),对吗?

如果可以,请您帮助我了解我做错了什么?

非常感谢您的帮助 祝你有美好的一天

0 个答案:

没有答案