config数据库中的集合:

 

mongos> show dbs
admin 0.000GB
athena 157.194GB
config 0.014GB

#############################
mongos> use config
switched to db config

##################################
mongos> show tables
actionlog
changelog
chunks
collections
databases
lockpings
locks
migrations
mongos
shards
system.profile
tags
transactions
version

 

 

查看数据库的默认存储分片(主分片)和支持分片的数据库:

               这个primary与replica set里面的primary不是一回事,这里的primary是primary shard的意思,我们知道即使在sharded cluster环境中,一些数据量比较小的db也是无需分片的,这些db默认就存放在primary shard上面。

 


mongos> use config
mongos> db.databases.find()
{ "_id" : "athena", "primary" : "bwactivity_shard", "partitioned" : true, "version" : { "uuid" : UUID("d3c927c5-29ee-4d27-b8ad-ac69332d3059"), "lastMod" : 1 } }
mongos> db.databases.find().pretty()
{
"_id" : "athena",
"primary" : "bwactivity_shard",
"partitioned" : true,
"version" : {
"uuid" : UUID("d3c927c5-29ee-4d27-b8ad-ac69332d3059"),
"lastMod" : 1
}
}

 

 

查看分片集群中哪些集合开启了分片和片键:

 

mongos> db.collections.find().pretty()
{
"_id" : "config.system.sessions",
"lastmodEpoch" : ObjectId("5f89496f82b8dec4f83d5506"),
"lastmod" : ISODate("1970-02-19T17:02:47.296Z"),
"dropped" : false,
"key" : {
"_id" : 1
},
"unique" : false,
"uuid" : UUID("48dfd0fb-7fcd-44dd-bb26-55e09050d60c")
}
{
"_id" : "athena.athena_user_task_new",
"lastmodEpoch" : ObjectId("5f8e4c9382b8dec4f808aefb"),
"lastmod" : ISODate("1970-02-19T17:02:47.299Z"),
"dropped" : false,
"key" : {
"uid" : "hashed"
},
"unique" : false,
"uuid" : UUID("a6bae3e6-4428-4f61-b7a8-30d7a99628e9")
}
{
"_id" : "athena.athena_user_task_v2",
"lastmodEpoch" : ObjectId("5fa4e12582b8dec4f8802392"),
"lastmod" : ISODate("1970-02-19T17:02:47.299Z"),
"dropped" : false,
"key" : {
"uid" : "hashed"
},
"unique" : false,
"uuid" : UUID("d1c674ab-3194-4944-8b49-48e0cd511ea3")
}
{
"_id" : "athena.athena_user_task_v3",
"lastmodEpoch" : ObjectId("000000000000000000000000"),
"lastmod" : ISODate("2020-11-05T06:55:12.147Z"),
"dropped" : true
}
mongos>

 

 

查看分片集群中有哪些分片sharding:



mongos> use config
mongos> db.shards.find().pretty()
{
"_id" : "bwactivity_shard",
"host" : "bwactivity_shard/aaa:28001,bbb:28001,ccc:28001",
"state" : 1
}
{
"_id" : "bwactivity_shard2",
"host" : "bwactivity_shard2/xxx:28002,yyy:28002,zzz:28002",
"state" : 1
}

 

 

 查看分片集群有哪些路由mongos:

 

mongos> db.mongos.find().pretty()
{
"_id" : "ddd:30000",
"advisoryHostFQDNs" : [
"c4-internet3-bwaward-mgdb01.bj"
],
"mongoVersion" : "4.0.14-8",
"ping" : ISODate("2020-11-11T08:20:27.119Z"),
"up" : NumberLong(541006),
"waiting" : true
}
{
"_id" : "eee:30000",
"advisoryHostFQDNs" : [
"c4-internet3-bwaward-mgdb02.bj"
],
"mongoVersion" : "4.0.14-8",
"ping" : ISODate("2020-11-11T08:20:27.121Z"),
"up" : NumberLong(541113),
"waiting" : true
}
{
"_id" : "fff:30000",
"advisoryHostFQDNs" : [
"c4-internet3-bwaward-mgdb03.bj"
],
"mongoVersion" : "4.0.14-8",
"ping" : ISODate("2020-11-11T08:20:35.613Z"),
"up" : NumberLong(541052),
"waiting" : true
}
mongos>

 

 

查看分片集群的分片信息汇总:

 

mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5f893d07fe296990bc8a1f50")
}
shards:
{ "_id" : "bwactivity_shard", "host" : "bwactivity_shard/aaa:28001,bbb:28001,ccc:28001", "state" : 1 }
{ "_id" : "bwactivity_shard2", "host" : "bwactivity_shard2/xxx:28002,yyy:28002,zzz:28002", "state" : 1 }
active mongoses:
"4.0.14-8" : 3
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:
41 : Success
1 : Failed with error 'aborted', from bwactivity_shard to bwactivity_shard2
databases:
{ "_id" : "athena", "primary" : "bwactivity_shard", "partitioned" : true, "version" : { "uuid" : UUID("d3c927c5-29ee-4d27-b8ad-ac69332d3059"), "lastMod" : 1 } }
athena.athena_user_task_new
shard key: { "uid" : "hashed" }
unique: false
balancing: true
chunks:
bwactivity_shard 295
bwactivity_shard2 294
too many chunks to print, use verbose if you want to force print
athena.athena_user_task_v2
shard key: { "uid" : "hashed" }
unique: false
balancing: true
chunks:
bwactivity_shard 1332
bwactivity_shard2 1335
too many chunks to print, use verbose if you want to force print
{ "_id" : "config", "primary" : "config", "partitioned" : true }
config.system.sessions
shard key: { "_id" : 1 }
unique: false
balancing: true
chunks:
bwactivity_shard 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : bwactivity_shard Timestamp(1, 0)

mongos>

 

 

###############################################################