无法在 mongodb 中启用分片
Unable to enable sharding in mongodb
我们创建了 3 个分片,每个分片有 2 个副本,mongodb 版本为 3.6.21。然后我们在不同节点上的每个分片的主节点创建具有root权限的admin用户。我们可以使用 user/pass auth 直接登录 mongod 服务。现在我们想在应用程序 dB 上启用分片,为此我们使用以下命令。
[root@MONGODB01 ~]# mongo --port 27017
MongoDB shell version v3.6.21
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("45c58424-422c-4a73-9d18-027718aa0a36") }
MongoDB server version: 3.6.21
mongos> use dsyh_mongo
switched to db dsyh_mongo
mongos> sh.enableSharding("dsyh_mongo")
{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { enableSharding: \"dsyh_mongo\", lsid: { id: UUID(\"45c58424-422c-4a73-9d18-027718aa0a36\") }, $clusterTime: { clusterTime: Timestamp(1634624354, 1), signature: { hash: BinData(0, 3F3BBFE3DD659B7E0FAEE493345496D9DAB9B2A4), keyId: 7020363352299798554 } }, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized",
"operationTime" : Timestamp(1634624352, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1634624354, 1),
"signature" : {
"hash" : BinData(0,"Pzu/491lm34PruSTNFSW2dq5sqQ="),
"keyId" : NumberLong("7020363352299798554")
}
}
}
但是我们遇到了上述错误。这里 mongos 在端口 27017 上 运行 并且 mongodb 在端口 37017 上在同一台服务器上 运行 请指出这里出了什么问题,因为我们能够使用之前的类似步骤?
我假设您混合了“普通”用户和“分片本地”用户。来自我在评论中提供的教程:
Users
In general, to create users for a sharded clusters, connect to the
mongos
and add the sharded cluster users.
However, some maintenance operations require direct connections to
specific shards in a sharded cluster. To perform these operations, you
must connect directly to the shard and authenticate as a shard-local
administrative user.
Shard-local users exist only in the specific shard and should only be
used for shard-specific maintenance and configuration. You cannot
connect to the mongos
with shard-local users.
我们创建了 3 个分片,每个分片有 2 个副本,mongodb 版本为 3.6.21。然后我们在不同节点上的每个分片的主节点创建具有root权限的admin用户。我们可以使用 user/pass auth 直接登录 mongod 服务。现在我们想在应用程序 dB 上启用分片,为此我们使用以下命令。
[root@MONGODB01 ~]# mongo --port 27017
MongoDB shell version v3.6.21
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("45c58424-422c-4a73-9d18-027718aa0a36") }
MongoDB server version: 3.6.21
mongos> use dsyh_mongo
switched to db dsyh_mongo
mongos> sh.enableSharding("dsyh_mongo")
{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { enableSharding: \"dsyh_mongo\", lsid: { id: UUID(\"45c58424-422c-4a73-9d18-027718aa0a36\") }, $clusterTime: { clusterTime: Timestamp(1634624354, 1), signature: { hash: BinData(0, 3F3BBFE3DD659B7E0FAEE493345496D9DAB9B2A4), keyId: 7020363352299798554 } }, $db: \"admin\" }",
"code" : 13,
"codeName" : "Unauthorized",
"operationTime" : Timestamp(1634624352, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1634624354, 1),
"signature" : {
"hash" : BinData(0,"Pzu/491lm34PruSTNFSW2dq5sqQ="),
"keyId" : NumberLong("7020363352299798554")
}
}
}
但是我们遇到了上述错误。这里 mongos 在端口 27017 上 运行 并且 mongodb 在端口 37017 上在同一台服务器上 运行 请指出这里出了什么问题,因为我们能够使用之前的类似步骤?
我假设您混合了“普通”用户和“分片本地”用户。来自我在评论中提供的教程:
Users
In general, to create users for a sharded clusters, connect to the
mongos
and add the sharded cluster users.However, some maintenance operations require direct connections to specific shards in a sharded cluster. To perform these operations, you must connect directly to the shard and authenticate as a shard-local administrative user.
Shard-local users exist only in the specific shard and should only be used for shard-specific maintenance and configuration. You cannot connect to the
mongos
with shard-local users.