您的位置:首页 > 其它

Replica Set从副本集中删除成员

2017-06-27 19:45 274 查看

一、使用rs.remove()删除成员

1.Shut down the mongod instance for the member you wish to remove. To shut down the instance, connect using the mongo shell and the db.shutdownServer() method.

2.Connect to the replica set’s current primary. To determine the current primary, use db.isMaster() while connected to any member of the replica set.

3.Use rs.remove() in either of the following forms to remove the member:

rs.remove("mongod3.example.net:27017")

rs.remove("mongod3.example.net")

二、使用rs.reconfig()删除成员

1.Shut down the mongod instance for the member you wish to remove. To shut down the instance, connect using the mongo shell and the db.shutdownServer() method.

2.Connect to the replica set’s current primary. To determine the current primary, use db.isMaster() while connected to any member of the replica set.

3.Issue the rs.conf() method to view the current configuration document and determine the position in the members array of the member to remove:

例如:
{

    "_id" : "rs",

    "version" : 7,

    "members" : [

        {

            "_id" : 0,

            "host" : "mongod_A.example.net:27017"

        },

        {

            "_id" : 1,

            "host" : "mongod_B.example.net:27017"

        },

        {

            "_id" : 2,

            "host" : "mongod_C.example.net:27017"

        }

    ]

}

将当前配置文档分配给变量:cfg = rs.conf()

修改cfg变量以删除成员:cfg.members.splice(2,1)

通过发布以下新配置来覆盖副本集配置文档:rs.reconfig(cfg)

rs.conf()

{

    "_id" : "rs",

    "version" : 8,

    "members" : [

        {

            "_id" : 0,

            "host" : "mongod_A.example.net:27017"

        },

        {

            "_id" : 1,

            "host" : "mongod_B.example.net:27017"

        }

    ]

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: