mongodb sharding ( replica set + sharding) 移除shard节点

os: centos 7.4
monggo: 3.6.6

mongodb replicat set + sharding 规划如下:

192.168.56.101 node1 configserver replset(27017、27018、27019)

192.168.56.102 node2 mongos(27017、27018、27019)

192.168.56.103 node3 shard1 replset(27017、27018、27019)
192.168.56.104 node4 shard2 replset(27017、27018、27019)
192.168.56.105 node5 shard3 replset(27017、27018、27019)
192.168.56.106 node6 shard4 replset(27017、27018、27019)

现在移除一个 shard4

node6 从 mongodb sharding 移除

node2 登录 mongos

$ mongo --port 27017

mongos> use admin
mongos> db.auth('root','rootroot')
mongos> show dbs
mongos> use config
mongos> sh.status()

mongos> db.adminCommand({removeShard:"shard4"})
{
    "msg" : "draining started successfully",
    "state" : "started",
    "shard" : "shard4",
    "note" : "you need to drop or movePrimary these databases",
    "dbsToMove" : [ ],
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1532426167, 3),
        "signature" : {
            "hash" : BinData(0,"tp0QX4bjy1hJ4Xt29XDYOKoxwuQ="),
            "keyId" : NumberLong("6581372726341009427")
        }
    },
    "operationTime" : Timestamp(1532426167, 3)
}

mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5b55bba0b4856e5663e0a7ad")
  }
  shards:
        {  "_id" : "shard1",  "host" : "shard1/192.168.56.103:27017,192.168.56.103:27018,192.168.56.103:27019",  "state" : 1 }
        {  "_id" : "shard2",  "host" : "shard2/192.168.56.104:27017,192.168.56.104:27018,192.168.56.104:27019",  "state" : 1 }
        {  "_id" : "shard3",  "host" : "shard3/192.168.56.105:27017,192.168.56.105:27018,192.168.56.105:27019",  "state" : 1 }
        {  "_id" : "shard4",  "host" : "shard4/192.168.56.106:27017,192.168.56.106:27018,192.168.56.106:27019",  "state" : 1,  "draining" : true }

可以看到 shard4 显示为 draining ,等把 shard4 分散到其余shard节点后,这个节点就算移除完成了。

验证

node2 登录mongos

$ mongo --port 27018

mongos> use admin
mongos> db.auth('root','rootroot')
mongos> show dbs
mongos> use config
mongos> db.getCollectionNames()
[
    "actionlog",
    "changelog",
    "chunks",
    "collections",
    "databases",
    "lockpings",
    "locks",
    "migrations",
    "mongos",
    "settings",
    "shards",
    "tags",
    "transactions",
    "version"
]

mongos> db.mongos.find()
{ "_id" : "node2:27017", "advisoryHostFQDNs" : [ ], "mongoVersion" : "3.6.6", "ping" : ISODate("2018-07-23T20:24:55.557Z"), "up" : NumberLong(9356), "waiting" : true }
{ "_id" : "node2:27018", "advisoryHostFQDNs" : [ ], "mongoVersion" : "3.6.6", "ping" : ISODate("2018-07-23T20:24:55.558Z"), "up" : NumberLong(9351), "waiting" : true }
{ "_id" : "node2:27019", "advisoryHostFQDNs" : [ ], "mongoVersion" : "3.6.6", "ping" : ISODate("2018-07-23T20:24:55.559Z"), "up" : NumberLong(9346), "waiting" : true }

mongos> db.shards.find()
{ "_id" : "shard1", "host" : "shard1/192.168.56.103:27017,192.168.56.103:27018,192.168.56.103:27019", "state" : 1 }
{ "_id" : "shard2", "host" : "shard2/192.168.56.104:27017,192.168.56.104:27018,192.168.56.104:27019", "state" : 1 }
{ "_id" : "shard3", "host" : "shard3/192.168.56.105:27017,192.168.56.105:27018,192.168.56.105:27019", "state" : 1 }

mongos> sh.status()

参考:
https://docs.mongodb.com/v3.6/sharding/
https://docs.mongodb.com/v3.6/reference/command/removeShard/#dbcmd.removeShard
http://www.mongoing.com/

posted @ 2018-07-24 18:24  peiybpeiyb  阅读(452)  评论(0编辑  收藏  举报