IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

MongoDB副本集replica set(三)–添加删除成员

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

上一篇文章中,我们搭建了3个节点的副本集,集群信息如下:

rstest:PRIMARY> rs.config()
{
    "_id" : "rstest",
    "version" : 2,
    "protocolVersion" : NumberLong(1),
    "writeConcernMajorityJournalDefault" : true,
    "members" : [
        {
            "_id" : 0,
            "host" : "192.168.10.41:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 2,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        },
        {
            "_id" : 1,
            "host" : "192.168.10.42:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        },
        {
            "_id" : 2,
            "host" : "192.168.10.43:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 0,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }
    ],
    "settings" : {
        "chainingAllowed" : true,
        "heartbeatIntervalMillis" : 2000,
        "heartbeatTimeoutSecs" : 10,
        "electionTimeoutMillis" : 10000,
        "catchUpTimeoutMillis" : -1,
        "catchUpTakeoverDelayMillis" : 30000,
        "getLastErrorModes" : {

        },
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        },
        "replicaSetId" : ObjectId("5ef1b03c01bba8d9a6759c18")
    }
}

(一)删除副本集成员

删除副本集成员可以使用rs.remove()或者rs.reconfig()。

方法一:使用rs.remove删除”IP为192.168.10.42″的成员

STEP1:关闭要删除节点的实例

[root@mongodbserver2 ~]# mongo -u replica -p replica --authenticationDatabase admin 
 MongoDB shell version v4.2.7
 connecting to: mongodb://127.0.0.1:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
 Implicit session: session { "id" : UUID("946853b3-ad91-44d0-b7df-3001cbfc1af0") }
 MongoDB server version: 4.2.7

rstest:SECONDARY> use admin
 switched to db admin
 rstest:SECONDARY> db.shutdownServer()
 2020-06-28T23:47:02.129+0800 I  NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:27017 - HostUnreachable: Connection closed by peer
 server should be down...
 2020-06-28T23:47:02.134+0800 I  NETWORK  [js] trying reconnect to 127.0.0.1:27017 failed
 2020-06-28T23:47:02.134+0800 I  NETWORK  [js] reconnect 127.0.0.1:27017 failed failed 
 2020-06-28T23:47:02.137+0800 I  NETWORK  [js] trying reconnect to 127.0.0.1:27017 failed
 2020-06-28T23:47:02.137+0800 I  NETWORK  [js] reconnect 127.0.0.1:27017 failed failed 
 >

STEP2:连接到主节点,不知道主节点,可以使用db.isMaster()确认

STEP3:在主节点上删除成员

rstest:PRIMARY> rs.remove("192.168.10.42:27017")
{
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1593359559, 1),
        "signature" : {
            "hash" : BinData(0,"UpD/BEf5OF484ZeHTHCEDReiJKw="),
            "keyId" : NumberLong("6841443127941660675")
        }
    },
    "operationTime" : Timestamp(1593359559, 1)
}
rstest:PRIMARY>

方法二:使用rs.reconfig删除成员

这里不再演示,见官方文档:https://docs.mongodb.com/manual/tutorial/remove-replica-set-member/

(二)添加副本集成员

这里演示如何把上面已经删除的节点重新添加回来。

STEP1:启动节点,节点的启动参数必须含有集群参数。主要参数如下:

# network interfaces
 net:
    port: 27017
    bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

 security:
    authorization: enabled
    keyFile: /mongo/mongo-keyfile

 replication:
  replSetName: rstest

STEP2:在主节点上执行添加节点命令

rs.add( { host: "192.168.10.42:27017", priority: 0, votes: 0 } )

注意:当新添加服务器的priority和votes大于0时,在其初始同步期间,即使该服务器由于数据不一致而无法提供读取服务或成为主服务器,但是他仍会作为有表决权的成员,这可能会导致多数投票成员在线但是无法选举主成员的情况。

STEP3:确保新加入的成员状态已经转变为SECONDARY

rs.status()

STEP4:如果新成员状态已经转变为SECONDARY,如果需要,可以使用rs.reconfig()更改新成员的priority和votes。

var cfg = rs.conf();
cfg.members[3].priority = 1
cfg.members[3].votes = 1
rs.config(cfg)

【完】

文章永久链接:https://tech.souyunku.com/?p=35418


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(74) 打赏



未经允许不得转载:搜云库技术团队 » MongoDB副本集replica set(三)–添加删除成员

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367