分片 MongoDB

Sharding MongoDB

我有 6 个虚拟机(Master、3 个 configsvr 和两个分片);我想将副本集添加到我的分片中。

是否可以将一个分片设置为另一个分片的复制,反之亦然?或者我应该添加其他 VM 作为分片的副本集吗?

简而言之:您应该为新的副本集节点添加新的虚拟机,并且您需要小心配置分片集群。

回答你的第一个问题:

运行 单个主机上的两个 mongod 实例(作为不同副本集的两个节点)会让你陷入困境,例如 RAM 使用,所以你应该避免这种情况。相反,每个副本集节点应该在不同的主机(不同的 VM)上。

并在分片集群配置问题上展开:

目前,cluster configuration 会将每个分片注册为独立实例,例如

{ "_id" : "shard0000", "host" : "vms2:30000" }

在你拥有converted your standalone instance to a replica set, the shard cluster config will need to be updated to match之后:

Connect to one of the sharded cluster’s mongos instances and issue a command in the following form:

db.getSiblingDB("config").shards.save(
{_id: "«name»", host: "«replica-set»/«member,»«member,»«...»" }
)

Replace «name» with the name of the shard. Replace «replica-set» with the name of the replica set. Replace «member,»«member,»«...» with the list of the members of the replica set.

Restart all mongos instances. If possible, restart all components of the replica sets (i.e., all mongos and all shard mongod instances).