如何在mongodb集群中添加分片?

时间:2016-04-06 15:07:00

标签: mongodb cluster-computing

我在我的debian机器上设置了如下配置的mongodb 3.2集群

# Config Server - mongod.conf

storage:
  dbPath: /data/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27019
  bindIp: 0.0.0.0

replication:
 replSetName: rs0

sharding:
 clusterRole: "configsvr"


# Shard Server 1 - mongod.conf

storage:
  dbPath: /data/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 0.0.0.0

replication:
 replSetName: rs0


# Shard Server 2 - mongod.conf

storage:
  dbPath: /data/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 0.0.0.0

replication:
 replSetName: rs0

并运行mongos在查询路由器服务器上添加分片

$)mongos --configdb mongo-config:27019

但我无法添加碎片。

mongos> sh.addShard("rs0/mongo-db1:27017")
{
    "ok" : 0,
    "errmsg" : "Cannot add rs0/mongo-db1:27017 as a shard since it is part of a config server replica set",
    "code" : 96
}
mongos> sh.addShard("rs0/mongo-db1:27017")
{
    "ok" : 0,
    "errmsg" : "Surprised to discover that mongo-db1:27017 does not believe it is a config server",
    "code" : 72
}

getSharmap Command。

mongos> db.runCommand("getShardMap");
{
    "map" : {
        "config" : "rs0/mongo-db1:27017,mongo-db2:27017",
        "mongo-db1:27017" : "rs0/mongo-db1:27017,mongo-db2:27017",
        "mongo-db2:27017" : "rs0/mongo-db1:27017,mongo-db2:27017",
        "rs0/mongo-config:27019" : "rs0/mongo-config:27019",
        "rs0/mongo-db1:27017,mongo-db2:27017" : "rs0/mongo-db1:27017,mongo-db2:27017"
    },
    "ok" : 1
}

这里是mongos log

2016-04-06T15:05:14.243 + 0000 I SHARDING [Balancer]即将元数据事件记录到动作日志中:{_ id:" mongo-router1-2016-04-06T15:05:14.243 + 0000- 570525aa6b2b3378bb9daf56",服务器:" mongo-router1",clientAddr:"",时间:新日期(1459955114243),什么:" balancer.round", ns:"",详细信息:{executionTimeMillis:3,errorOccured:true,errmsg:"无法从配置服务器获取更新的分片列表,因为惊讶地发现mongo-db1:27017没有相信它是一个配置服务器" }}

我错过了什么。?

1 个答案:

答案 0 :(得分:0)

由于您尝试添加的分片是在rs0副本集中,并且由于rs0保留了您的配置服务器,因此它不会让您创建分片。尝试将其添加到不同的副本集,如rs1,这应该工作。