Shard cluster状态查询:
mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("5b7b700b1cfaf6f26d2d0284") } shards: { "_id" : "myShard_1", "host" : "myShard_1/hdp06.thinkjoy.tt:27019,hdp07.thinkjoy.tt:27019,hdp08.thinkjoy.tt:27019", "state" : 1 } { "_id" : "myShard_2", "host" : "myShard_2/hdp06.thinkjoy.tt:27020,hdp07.thinkjoy.tt:27020,hdp08.thinkjoy.tt:27020", "state" : 1 } { "_id" : "myShard_3", "host" : "myShard_3/hdp06.thinkjoy.tt:27021,hdp07.thinkjoy.tt:27021,hdp08.thinkjoy.tt:27021", "state" : 1 } active mongoses: "4.0.1" : 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: No recent migrations databases: { "_id" : "MyDB", "primary" : "myShard_2", "partitioned" : true, "version" : { "uuid" : UUID("202a1d72-aa92-403d-a2a6-c7c3aa273323"), "lastMod" : 1 } } MyDB.chapter shard key: { "id" : 1, "subjectId" : 1 } unique: false balancing: true chunks: myShard_2 1 { "id" : { "$minKey" : 1 }, "subjectId" : { "$minKey" : 1 } } -->> { "id" : { "$maxKey" : 1 }, "subjectId" : { "$maxKey" : 1 } } on : myShard_2 Timestamp(1, 0) MyDB.question_knowledge_basic_id shard key: { "knowledge_basic_id" : 1, "question_id" : 1 } unique: false balancing: true chunks: myShard_2 1 { "knowledge_basic_id" : { "$minKey" : 1 }, "question_id" : { "$minKey" : 1 } } -->> { "knowledge_basic_id" : { "$maxKey" : 1 }, "question_id" : { "$maxKey" : 1 } } on : myShard_2 Timestamp(1, 0) { "_id" : "config", "primary" : "config", "partitioned" : true } config.system.sessions shard key: { "_id" : 1 } unique: false balancing: true chunks: myShard_1 1 { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : myShard_1 Timestamp(1, 0) 5、对库启用分片这里创建了一个mydb库,使用以下命令对其启用分片功能。
mongos>sh.enableSharding("MyDB") { "ok" : 1, "operationTime" : Timestamp(1534837173, 2214), "$clusterTime" : { "clusterTime" : Timestamp(1534837173, 2408), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }下面对mydb的chapter启用分片技术:
--创建一个索引 mongos> use MyDB switched to db MyDB mongos> db.chapter.createIndex({"id" : 1,"subjectId" : 1},{"name" : "new_idx"}) --对表进行分片 mongos> sh.shardCollection('MyDB.chapter',{id:1,subjectId:1}) { "collectionsharded" : "MyDB.chapter", "collectionUUID" : UUID("a5f3b95c-ced6-4ae5-82d8-06d36176cbef"), "ok" : 1, "operationTime" : Timestamp(1535077873, 13), "$clusterTime" : { "clusterTime" : Timestamp(1535077873, 13), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } } 6、Shard集群监控针对MongoDB的监控除了使用第三方软件外,强烈推荐是官方提供的Ops Manager,如下图所示:
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx