Mongodb副本集--切换主从节点

it2022-05-05  237

思路: 1.为了保证数据的一致性,必须先关闭应用的写服务。 2.提升要升级为Primary节点的Secondary节点的优先级。 操作如下:

点击(此处)折叠或打开

arps:PRIMARY> config=rs.conf()                //查看当前配置,存入config变量中。 arps:PRIMARY> config.members[2].priority =//修改config变量,第三组成员的优先级为3. arps:PRIMARY> rs.reconfig(config)             //配置生效                        ...... ...... 2017-12-22T15:19:56.596+0800 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2017-12-22T15:19:56.597+0800 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok arps:SECONDARY> rs.conf()                    //查看当前配置 {         "_id" : "arps",         "version" : 4,         "members" : [                 {                         "_id" : 0,                         "host" : "172.17.4.37:27017",                         "arbiterOnly" : false,                         "buildIndexes" : true,                         "hidden" : false,                         "priority" : 1,                         "tags" : {                         },                         "slaveDelay" : 0,                         "votes" : 1                 },                 {                         "_id" : 1,                         "host" : "172.17.4.38:27017",                         "arbiterOnly" : false,                         "buildIndexes" : true,                         "hidden" : false,                         "priority" : 1,                         "tags" : {                         },                         "slaveDelay" : 0,                         "votes" : 1                 },                 {                         "_id" : 2,                         "host" : "172.17.4.39:27017",                         "arbiterOnly" : false,                         "buildIndexes" : true,                         "hidden" : false,                         "priority" : 3,             //优先级变为3                         "tags" : {                         },                         "slaveDelay" : 0,                         "votes" : 1                 }         ],         "settings" : {                 "chainingAllowed" : true,                 "heartbeatTimeoutSecs" : 10,                 "getLastErrorModes" : {                 },                 "getLastErrorDefaults" : {                         "w" : 1,                         "wtimeout" : 0                 }         } } arps:SECONDARY> rs.status() {         "set" : "arps",         "date" : ISODate("2017-12-22T07:25:04.641Z"),         "myState" : 2,         "syncingTo" : "172.17.4.39:27017",         "members" : [                 {                         "_id" : 0,                         "name" : "172.17.4.37:27017",                         "health" : 1,                         "state" : 2,                         "stateStr" : "SECONDARY",                         "uptime" : 7597536,                         "optime" : Timestamp(1513927481, 3),                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),                         "syncingTo" : "172.17.4.39:27017",                         "configVersion" : 4,                         "self" : true                 },                 {                         "_id" : 1,                         "name" : "172.17.4.38:27017",                         "health" : 1,                         "state" : 2,                         "stateStr" : "SECONDARY",                         "uptime" : 7597426,                         "optime" : Timestamp(1513927481, 3),                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),                         "lastHeartbeat" : ISODate("2017-12-22T07:25:02.961Z"),                         "lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.091Z"),                         "pingMs" : 0,                         "syncingTo" : "172.17.4.39:27017",                         "configVersion" : 4                 },                 {                         "_id" : 2,                         "name" : "172.17.4.39:27017",                         "health" : 1,                         "state" : 1,                         "stateStr" : "PRIMARY",    //最后一个节点升级为PRIMARY                         "uptime" : 3202,                         "optime" : Timestamp(1513927481, 3),                         "optimeDate" : ISODate("2017-12-22T07:24:41Z"),                         "lastHeartbeat" : ISODate("2017-12-22T07:25:02.951Z"),                         "lastHeartbeatRecv" : ISODate("2017-12-22T07:25:04.344Z"),                         "pingMs" : 0,                         "electionTime" : Timestamp(1513927190, 2),                         "electionDate" : ISODate("2017-12-22T07:19:50Z"),                         "configVersion" : 4                 }         ],         "ok" : 1 }

最新回复(0)