首页 > 解决方案 > 数据不移动到新的分片服务器 mongodb

问题描述

我在我的 mongodb 集群中添加了一个分片服务器。添加新的分片服务器后,我在主节点上收到此错误。

DBException thrown :: caused by :: 
CannotImplicitlyCreateCollection{ ns: "config.system.sessions" }: 
request doesn't allow collection to be created implicitly

新的分片服务器是新的,之前没有任何数据。

我是如何添加分片服务器的?

我创建了一个文件 /etc/mongod.conf (就像我的其他分片服务器一样)

sharding:
  clusterRole: shardsvr
replication:
  replSetName: shardReplicaSet10
storage:
  dbPath: /mnt/mongodb
systemLog:
  traceAllExceptions: true
  path: /mnt/log/mongodb/out.log
  logAppend: true
  logRotate: rename
  destination: file
processManagement:
  fork: true
net:
  bindIp: localhost,172.6.7.5

然后我在这个replicaSet中有另一个成员具有相同的配置文件,只是bindIp被改变了。

我连接到我的 mongos 节点并添加了副本集

sh.addShard("shardReplicaSet10/172.6.7.5:27018,172.6.7.6:27018")

我可以确认我已经使用 rs.initiate() 启动了副本集

标签: mongodbsharding

解决方案


事实证明,每当我们添加一个新的分片副本集时,我们都需要手动给它一个身份。我尝试了这个答案中给出的步骤

https://dba.stackexchange.com/a/227877

它奏效了。在分片副本集的主节点上,只需执行以下操作:

use admin

并添加身份

  db.system.version.insert({
    "_id" : "shardIdentity",
    "clusterId" : ObjectId("5f098ac1077eb0e078fd5c1e"),
    "shardName" : "NameOfYourShardReplicaSet",
    "configsvrConnectionString" : "configReplicaSet/ipofconfigserver:27019,ipofotherconfigserver:27019"
})

您可以通过使用获取集群 ID

sh.status()

在任何 mongos 集群上。


推荐阅读