昊鼎王五:如何查看mongodb副本集的priority优先级?(通俗讲就是“权重”)

#昊鼎王五:如何查看mongodb副本集的priority优先级?(通俗讲就是“权重”)

关于mongodb副本集的priority

#1.基础知识:
##1.1.mongodb的priority可以用来控制副本集的
##1.2.优先级:

如果在建立config配置时候没有指定 副本集所有成员默认 priority=1,投票选举与优先级没有关系
冲裁节点和延迟节点 priority=0 不参与主的竞争
其他每个节点都有个优先权,可以手动设置优先权来决定谁的成为primay的权重最大。副本集中通过设置priority的值来决定优先权的大小,这个值的范围是0--100,值越大,优先权越高。

##1.3.修改过程:

rs.conf查看副本集成员的priority值 重点看members集合
cfg = rs.conf()
rs.members[_id].priority=
rs.reconfig(cfg)
#注意:修改现有副本集成员时候一定要注意,不能高于主库的priority,否则会导致手动的primiary切换

#2.操作命令:

[hd205@MongDB1 ~]$ mongo -port 90109
MongoDB shell version: 3.2.12
connecting to: 127.0.0.1:90109/test
shard1:PRIMARY> use admin
switched to db admin
shard1:PRIMARY> db.auth('abc','123');
1
shard1:PRIMARY> rs.status();
{
    "set" : "shard1",
    "date" : ISODate("2017-04-13T03:51:43.724Z"),
    "myState" : 1,
    "term" : NumberLong(15),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
        {
            "_id" : 0,
            "name" : "192.168.1.11:90109",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 236595,
            "optime" : {
                "ts" : Timestamp(1491819707, 1),
                "t" : NumberLong(15)
            },
            "optimeDate" : ISODate("2017-04-10T10:21:47Z"),
            "electionTime" : Timestamp(1491819706, 1),
            "electionDate" : ISODate("2017-04-10T10:21:46Z"),
            "configVersion" : 1,
            "self" : true
        },
        {
            "_id" : 1,
            "name" : "192.168.1.12:90109",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 235955,
            "optime" : {
                "ts" : Timestamp(1491819707, 1),
                "t" : NumberLong(15)
            },
            "optimeDate" : ISODate("2017-04-10T10:21:47Z"),
            "lastHeartbeat" : ISODate("2017-04-13T03:51:42.192Z"),
            "lastHeartbeatRecv" : ISODate("2017-04-13T03:51:42.192Z"),
            "pingMs" : NumberLong(0),
            "syncingTo" : "192.168.1.11:90109",
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "192.168.1.244:90109",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 235758,
            "optime" : {
                "ts" : Timestamp(1491819707, 1),
                "t" : NumberLong(15)
            },
            "optimeDate" : ISODate("2017-04-10T10:21:47Z"),
            "lastHeartbeat" : ISODate("2017-04-13T03:51:43.566Z"),
            "lastHeartbeatRecv" : ISODate("2017-04-13T03:51:42.102Z"),
            "pingMs" : NumberLong(239),
            "configVersion" : 1
        },
        {
            "_id" : 3,
            "name" : "192.168.1.245:90109",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 235774,
            "optime" : {
                "ts" : Timestamp(1491819707, 1),
                "t" : NumberLong(15)
            },
            "optimeDate" : ISODate("2017-04-10T10:21:47Z"),
            "lastHeartbeat" : ISODate("2017-04-13T03:51:42.536Z"),
            "lastHeartbeatRecv" : ISODate("2017-04-13T03:51:39.338Z"),
            "pingMs" : NumberLong(8),
            "configVersion" : 1
        },
        {
            "_id" : 4,
            "name" : "192.168.1.246:90109",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 235807,
            "optime" : {
                "ts" : Timestamp(1491819707, 1),
                "t" : NumberLong(15)
            },
            "optimeDate" : ISODate("2017-04-10T10:21:47Z"),
            "lastHeartbeat" : ISODate("2017-04-13T03:51:41.940Z"),
            "lastHeartbeatRecv" : ISODate("2017-04-13T03:51:41.100Z"),
            "pingMs" : NumberLong(12),
            "configVersion" : 1
        }
    ],
    "ok" : 1
}
shard1:PRIMARY> rs.config();
{
    "_id" : "shard1",
    "version" : 1,
    "protocolVersion" : NumberLong(1),
    "members" : [
        {
            "_id" : 0,
            "host" : "192.168.1.11:90109",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 2,
            "tags" : {

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

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

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

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

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

        },
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        },
        "replicaSetId" : ObjectId("58e4c9c3333c649c118771d5")
    }
}
shard1:PRIMARY>

好了,聪明如你,知道了如何查看mongodb副本集的priority优先级,是不是很欢喜 _

还有其他问题的可以在评论区留言或者扫码加博主获取资源或者提问。
昊鼎王五:如何查看mongodb副本集的priority优先级?(通俗讲就是“权重”)_第1张图片

你可能感兴趣的:(mongodb)