对mongodb修改成为主节点权重

有些时候可以会对一个mongodb集群里的某一节点的机器设置成为主(读)节点,可以用以下方式:


rs.conf();

列出该集群下的所有节点信息如:


dbset1:PRIMARY> rs.conf()
{
        "_id" : "dbset1",
        "version" : 21,
        "members" : [
                {
                        "_id" : 1,
                        "host" : "10.161.12.122:38257",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                },
                {
                        "_id" : 4,
                        "host" : "10.163.236.70:38257",
                        "arbiterOnly" : true,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                }


这个时个,如果想_id为1的机器在选举中可以优先成主节点的话,可以进行以下设置

  1. cfg = rs.conf()

  2. cfg.members[0].priority = 100

  3. rs.reconfig(cfg)

其中members[x],x是指rs.conf()后member数据的下标,由0开始

该值范围在0-100之间,数值超高,权重越大。


你可能感兴趣的:(对mongodb修改成为主节点权重)