首页 > 数据库 >mongodb副本集(PSA模式)修改节点信息

mongodb副本集(PSA模式)修改节点信息

时间:2023-07-17 10:02:07浏览次数:34  
标签:votes 副本 false mongodb PSA priority true id myrepl

环境:
OS:Centos7
mongodb:4.4.22

 

我们在副本集扩容的情况下,新加入节点一般设置priority和votes都为0,待新节点数据同步完成后再进行修改:
主库上执行新增新的节点:
myrepl:PRIMARY>rs.add({ host: "192.168.1.107:29001", priority: 0, votes: 0 })
待同步完成后查看副本集配置

 

myrepl:PRIMARY> rs.config()
{
        "_id" : "myrepl",
        "version" : 23819,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.1.102:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

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

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

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

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("64b0a3f881b811c4931d4d4c")
        }
}

 

可以看到id=4的节点,priority和votes都为0,下面进行修改
members的下标数字对对应数组的序号(这里是0,1,2),我们这里是要修改数组序号为2的member

myrepl:PRIMARY>var cfg = rs.conf()
myrepl:PRIMARY>cfg.members[2].priority = 1
myrepl:PRIMARY>cfg.members[2].votes = 1
myrepl:PRIMARY> rs.reconfig(cfg)
{
        "ok" : 0,
        "errmsg" : "Rejecting reconfig where the new config has a PSA topology and the secondary is electable, but the old config contains only one writable node. Refer to https://docs.mongodb.com/manual/reference/method/rs.reconfigForPSASet/ for next steps on reconfiguring a PSA set.",
        "code" : 103,
        "codeName" : "NewReplicaSetConfigurationIncompatible"
}

这里报错误了,提示说明psa拓扑不能使用这种方式修改,尝试使用如下方式修改

 

myrepl:PRIMARY>cfg = rs.conf();
myrepl:PRIMARY>cfg["members"] = 
[
                {
                        "_id" : 0,
                        "host" : "192.168.1.102:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

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

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

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
]

myrepl:PRIMARY> rs.reconfigForPSASet(2, cfg);
Running first reconfig to give member at index 2 { votes: 1, priority: 0 }
Running second reconfig to give member at index 2 { priority: 1 }
{ "ok" : 1 }

 

rs.reconfigForPSASet( memberIndex, config, { options } )的使用方法

memberIndex为member数组的序号

 

查看新配置

myrepl:PRIMARY> rs.conf()
{
        "_id" : "myrepl",
        "version" : 23821,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.1.102:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

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

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 4,
                        "host" : "192.168.1.107:29001",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "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("64b0a3f881b811c4931d4d4c")
        }
}

 

标签:votes,副本,false,mongodb,PSA,priority,true,id,myrepl
From: https://www.cnblogs.com/hxlasky/p/17559209.html

相关文章

  • mongodb从库无法启动一例(replication_recovery.cpp)
    环境:OS:centos7mongodb:4.4.22背景:1主1从1仲裁的环境,修改从库的集群ip后,执行如下操作后发现无法启动myrepl:PRIMARY>rs.remove("192.168.1.104:29001")myrepl:PRIMARY>conf=rs.conf()myrepl:PRIMARY>conf.members[1].host="192.168.1.107:29001"myrepl:PRIMARY>rs.r......
  • MongoDB导入导出
    物理备份物理备份是指将MongoDB数据库文件复制到备份服务器或存储设备上。MongoDB使用的是一种称为"copy-on-write"的技术,这意味着当修改MongoDB数据库时,MongoDB会将数据复制到一个新的文件中,而原始文件仍然保留不变。这使得可以在不中断服务的情况下备份MongoDB数据库。 物理......
  • mongodb报错Sort exceeded memory limit of 104857600 bytes
    mongodb运行过程中,遇到错误信息:2023-07-14T09:29:33.853ERRFailedtoQueryBsPoolUnivStaterror="(QueryExceededMemoryLimitNoDiskUseAllowed)Executorerrorduringfindcommand::causedby::Sortexceededmemorylimitof104857600bytes,butdidnotoptinto......
  • mongodb4.4.22主从(副本集附仲裁节点)部署带认证模式
    环境:OS:CentOS7DB:4.4.22机器角色:192.168.1.102:29001主192.168.1.104:29001从192.168.1.105:29001仲裁节点 1.下载相应的版本https://www.mongodb.com/download-center/community我这里下载的是mongodb-linux-x86_64-rhel70-4.4.22.tgz 2.创建安装目录192.168.1.102......
  • mongodb 入门 和 php示例
    内容太多了,感觉不好写,就写点入门的吧,其他参考参考_MonogDB中文网(mongodb.net.cn)虽然内容是机器翻译的,但也还好,基本能看. 相关概念: database数据库collection集合,相当于数据库表document文档,相当于数据记录行 dockerrun-d--namemongo-p27017:27......
  • 13-MongoDB 集成:如何在响应式应用中访问 NoSQL 数据库
    上一讲开始,我们进入了响应式数据访问这一模块的学习,并且引出了Spring家族中专门用于实现数据访问的SpringData框架及其响应式版本。我们知道SpringData支持多种响应式Repository用来构建全栈响应式编程模型,而MongoDB就是其中具有代表性的一种数据存储库。今天,我就将结......
  • ubuntu20.04安装mongodb步骤
    注:虚拟机无法运行mongodb5.0以上的版本1、wget-qO-https://www.mongodb.org/static/pgp/server-4.4.asc|apt-keyadd-导入并设置公钥2、echo"deb[arch=amd64,arm64]https://repo.mongodb.org/apt/ubuntufocal/mongodb-org/4.4multiverse"|tee/ect/apt/sources.list.......
  • logstash+Elasticseach单节点 让logstash生成单副本索引
    要让Logstash和Elasticsearch生成单副本索引,请按照以下步骤更改Logstash的输出配置文件:打开Logstash配置文件,该文件默认位于 logstash/config 目录下。找到输出部分配置,并添加以下行:output{elasticsearch{hosts=>["localhost"]index=>"your......
  • mongodb4集合操作
    Mongodb集合操作1.查看当前数据库下所有集合showcollectionsshowtables2.新建集合db.createCollection("product")3.新建集合并插入文档db.girl.insert({"name":"小花","age":"33","address":"chengdu"})4.查看文档内容db.girl.find()5.删除......
  • mongodb5文档操作1-插入数据
    mongodb插入文档数据1.insert插入单条数据info={ "name":"teacher01","num":01,"age":33,"sex":"man","phone":18782940194,"address":"成都龙泉"}db.teacher.insert......