连接到Atlas群集上的mongos以查看分片状态

时间:2017-12-12 16:31:21

标签: mongodb

我只需要执行sh.status()命令来查看我的mongodb数据库的分片状态。
这个命令需要在mongos上执行,而且我还不清楚如何执行它。我的猜测是我应该直接从mongos服务器启动一个mongo shell,但是Atlas似乎没有直接访问它们(我可能错了)。

编辑:

以下是从连接到群集的远程Mongo Shell执行命令时遇到的异常:

mongoc-shard-00-00-wddpo(mongos-3.6.0)[mongos] mydb> sh.status()
printStackTrace@src/mongo/shell/utils.js:73:15
DBCollection.prototype.aggregate@/Users/jondoe/.mongorc.js:98:13
sh.getRecentMigrations@/Users/jondoe/.mongorc.js:1388:28
printShardingStatus@/Users/jondoe/.mongorc.js:1497:30
sh.status@src/mongo/shell/utils_sh.js:89:5
@(shell):1:1

2017-12-12T16:31:59.985+0100 E QUERY    [thread1] uncaught exception:         aggregate failed: {
  "ok": 0,
  "errmsg": "The 'cursor' option is required, except for aggregate with the explain argument",
  "code": 9,
  "codeName": "FailedToParse",
  "$clusterTime": {
    "clusterTime": Timestamp(1513092719, 27),
    "signature": {
      "hash": BinData(0, "Ok0isqe1nHr+D/I9344pcNdxapA="),
      "keyId": NumberLong("6496824061736255491")
    }
  },
  "operationTime": Timestamp(1513092719, 27)
}

更新

由于我使用的是Mongo Shell 3.4,因此我更新到了3.6 经过一些清理(我必须在安装3.6之前手动删除home / .mongorc.js,否则它会弄得一团糟)一切都按预期工作

mongo "mongodb+srv://mongoc-wddpo.mongodb.net/mydb" --authenticationDatabase admin --username jondoe --password strongestpasswordever
MongoDB shell version v3.6.0
connecting to: mongodb+srv://mongoc-wddpo.mongodb.net/mydb
MongoDB server version: 3.6.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5a2953b4841c53c7b10a53f5")
  }
  shards:
        {  "_id" : "Mongoc-shard-0",  "host" : "Mongoc-shard-0/mongoc-shard-00-00-wddpo.mongodb.net:27017,mongoc-shard-00-01-wddpo.mongodb.net:27017,mongoc-shard-00-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-1",  "host" : "Mongoc-shard-1/mongoc-shard-01-00-wddpo.mongodb.net:27017,mongoc-shard-01-01-wddpo.mongodb.net:27017,mongoc-shard-01-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-2",  "host" : "Mongoc-shard-2/mongoc-shard-02-00-wddpo.mongodb.net:27017,mongoc-shard-02-01-wddpo.mongodb.net:27017,mongoc-shard-02-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-3",  "host" : "Mongoc-shard-3/mongoc-shard-03-00-wddpo.mongodb.net:27017,mongoc-shard-03-01-wddpo.mongodb.net:27017,mongoc-shard-03-02-wddpo.mongodb.net:27017",  "state" : 1 }
  active mongoses:
        "3.6.0" : 12
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                Mongoc-shard-0  1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : Mongoc-shard-0 Timestamp(1, 0) 
        {  "_id" : "mydb",  "primary" : "Mongoc-shard-1",  "partitioned" : false }

1 个答案:

答案 0 :(得分:1)

部署分片群集时,您可以连接到mongos并执行sh.status()

在群集概述中,单击“连接”,选择“使用Mongo Shell连接”,然后使用提供的连接字符串。

<强>更新

刚刚使用库存ubuntu客户端升级到v3.6和新的v3.6集群进行了测试。

客户:

$ mongo --version
MongoDB shell version v3.6.0
git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

从Atlas UI复制粘贴的连接字符串:

$ mongo "mongodb+srv://cluster14-74xqx.mongodb.net/test" --authenticationDatabase admin --username user --password password

shell:

MongoDB shell version v3.6.0
connecting to: mongodb+srv://cluster14-74xqx.mongodb.net/test
MongoDB server version: 3.6.0
mongos> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5a3106712d26976bf628d75b")
  }
  shards:
        {  "_id" : "Cluster14-shard-0",  "host" : "Cluster14-shard-0/cluster14-shard-00-00-74xqx.mongodb.net:27017,cluster14-shard-00-01-74xqx.mongodb.net:27017,cluster14-shard-00-02-74xqx.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Cluster14-shard-1",  "host" : "Cluster14-shard-1/cluster14-shard-01-00-74xqx.mongodb.net:27017,cluster14-shard-01-01-74xqx.mongodb.net:27017,cluster14-shard-01-02-74xqx.mongodb.net:27017",  "state" : 1 }
  active mongoses:
        "3.6.0" : 6
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
相关问题