How to replace node in sharded replica set?

蹲街弑〆低调 提交于 2019-12-11 12:08:18

问题


I got sharded mongodb setup with two replica sets:

mongos> db.runCommand( { listShards : 1 } )
{
    "shards" : [
        {
            "_id" : "rs01",
            "host" : "rs01/10.133.250.140:27017,10.133.250.154:27017"
        },
        {
            "_id" : "rs02",
            "host" : "rs02/10.133.242.7:27017,10.133.242.8:27017"
        }
    ],
    "ok" : 1
}

Node 10.133.250.140 just went down, and I replaced it with another one (ip-address changed). Replica set reconfiguration was pretty easy, just rs.remove() and rs.add() Now I have to update host config for shard rs01. What is proper way to do it?


回答1:


Many times you would need to modify the host string for a shard. The simplest way to change host string is to run an update operation.

Connect to mongos and do this -

> use config
> db.shards.update({ "_id" : "rs01"},{$set : { "host" : "rs01/newip:27017,anothernewip:27017"} })

You might need to restart all mongos.

Hope this helps :-)




回答2:


Well, removing problem shard and adding it again seems the only option.



来源:https://stackoverflow.com/questions/29918216/how-to-replace-node-in-sharded-replica-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!