简体   繁体   English

无法在 mongodb 中启用分片

[英]Unable to enable sharding in mongodb

We have created 3 shards and each shard has 2 replicas with mongodb version 3.6.21.我们创建了 3 个分片,每个分片有 2 个副本,mongodb 版本为 3.6.21。 Then we created admin user with root privileges in the primary node of each shard on different nodes.然后我们在不同节点的每个分片的主节点中创建具有 root 权限的 admin 用户。 We are able to login to mongod service directly by using user/pass auth.我们可以使用 user/pass auth 直接登录到 mongod 服务。 Now we would like to enable sharding on an application dB and for that we are using below commands.现在我们想在应用程序 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")
                }
        }
}

But we are facing above error.但我们正面临上述错误。 Here mongos is running on port 27017 and mongodb is running on port 37017 on the same server Please suggest what went wrong here as we were able to use the similar steps earlier?这里 mongos 在端口 27017 上运行,mongodb 在同一台服务器上的端口 37017 上运行 请指出这里出了什么问题,因为我们之前可以使用类似的步骤?

I assume you mix "normal" user and "shard-local" user.我假设您将“普通”用户和“分片本地”用户混合使用。 From the tutorial I provided in my comment:从我在评论中提供的教程:

Users用户

In general, to create users for a sharded clusters, connect to the mongos and add the sharded cluster users.通常,要为分片集群创建用户,请连接到mongos并添加分片集群用户。

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. Shard-local 用户只存在于特定的分片中,应该只用于特定分片的维护和配置。 You cannot connect to the mongos with shard-local users.您无法使用分片本地用户连接到mongos

Or see Sharded Cluster Users或查看分片集群用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM