英文:
MongoDB addShard doesn't add a new shard to the cluster
问题
我有一个由2个节点组成的MongoDB集群。这2个节点分别托管:
- 一个配置服务器
- 一个分片服务器
- 一个mongos实例
当我连接到机器1上的mongos并执行以下命令:
sh.status()
我可以在shards部分看到:
shards
[
{
_id: 'replicaSetShardServer1',
host: 'replicaSetShardServer1/machine1:port',
state: 1,
topologyTime: Timestamp({ t: 1669040465, i: 2 })
}
]
但我看不到机器2。
因此,我按照添加机器2到副本集的步骤进行操作。
- 连接到mongos实例
- 执行
sh.addShard("replicaSetShardServer1/machine2:port")
它返回:
{
shardAdded: 'replicaSetShardServer1',
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1675869627, i: 1 }),
signature: {
hash: Binary(Buffer.from("323787680faa463455c0aea72d3d9c722575dfda", "hex"), 0),
keyId: Long("7168472318795055129")
}
},
operationTime: Timestamp({ t: 1675869627, i: 1 })
}
然后我再次执行sh.status(),但仍然只有一个分片(与上面相同)显示在分片部分,因此我认为分片没有被考虑进去。
我是否做错了什么?
db.adminCommand("getShardMap").map命令的结果是
{
replicaSetShardServer1: 'replicaSetShardServer1/machine1:27018',
config: 'replicaSetConfigServer1/machine1:27019,machine2:27019'
}
英文:
I have a MongoDB cluster of 2 nodes. The 2 nodes are hosting each:
- one config server
- one shard server
- one mongos instance
When I connect to the machine 1 on a mongos and execute:
> sh.status()
I can see in the sections shards:
shards
[
{
_id: 'replicaSetShardServer1',
host: 'replicaSetShardServer1/machine1:port',
state: 1,
topologyTime: Timestamp({ t: 1669040465, i: 2 })
}
]
But I can't see the machine 2.
So I follow the procedure to add the machine 2 to the replica set.
- Connect on the mongos instance
- Execute
> sh.addShard("replicaSetShardServer1/machine2:port
It returns :
{
shardAdded: 'replicaSetShardServer1',
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1675869627, i: 1 }),
signature: {
hash: Binary(Buffer.from("323787680faa463455c0aea72d3d9c722575dfda", "hex"), 0),
keyId: Long("7168472318795055129")
}
},
operationTime: Timestamp({ t: 1675869627, i: 1 })
}
Then I execute the sh.status() again but I still have one shard only (the same as above) indicated in the shard section, therefor I assume the shard isn't taking into consideration.
Am I doing something wrong ?
The result of the command db.adminCommand("getShardMap").map is
{
replicaSetShardServer1: 'replicaSetShardServer1/machine1:27018',
config: 'replicaSetConfigServer1/machine1:27019,machine2:27019'
}
答案1
得分: 0
-
我面临了两个问题:
- 我不得不使用 rs.add("replicationSet/node2:27018") 来将节点添加到复制集中。
- 我不得不为分片服务器复制集添加用户,以便使用 rs.add("replicationSet/node2:27018")。
对于第一个问题,方程的遗漏部分是我首先必须将分片服务器添加到复制集分片服务器,然后调用添加分片。在调用addShard()时没有出现错误响应。
对于第二个问题,在MongoDB分片集群中,有两种类型的用户。
一种是通过mongos创建并用于处理数据和集合操作(查询集合,向其写入等)。
还有分片本地用户,这些用户是直接连接到mongod实例时创建的。它们用于管理任务。
https://www.mongodb.com/docs/manual/core/security-users/#sharded-cluster-users
英文:
I faced 2 issues:
- I had to use the rs.add("replicationSet/node2:27018") to add the node to the replication set.
- I had to add a user for the shard server replication set in order to use the rs.add("replicationSet/node2:27018")
For the first point, the missing part of the equation was that I had to firstly add the shard server to the replica set shard server and then call add shard. No error was prompted to the response of the addShard() call.
For the second point, in a mongoDB sharded cluster, there is 2 kind of users.
One that is created through the mongos and used to deal with data and collection operation (query a collection, write to it etc..).
And there is the shard local users, those are created connecting directly to a mongod instance. Those are used for administrative tasks.
https://www.mongodb.com/docs/manual/core/security-users/#sharded-cluster-users
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论