修改副本集端口(带仲裁节点)
需求:因为端口调整,需要改变副本的备份集
1.查看当前副本集配置情况
[root@localhost bin]# ./mongo localhost:20001
repltest:PRIMARY> use admin
repltest:PRIMARY> db.auth("sa","123456")
repltest:PRIMARY> rs.conf()
{
"_id" : "repltest",
"version" : 134592,
"members" : [
{
"_id" : 5,
"host" : "192.168.1.134:20001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 7,
"host" : "192.168.1.135:20002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 8,
"host" : "192.168.1.135:20003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
注意这里的_id,代表的是记录的id,而不是members[]对应的索引值,members的索引值是根据显示出来的按照0,1,2这样排序的
如上面的输出_id与members索引值的对应关系如下:
"_id" : 5 -->members[0]
"_id" : 7 -->members[1]
"_id" : 8 -->members[2]
2.配置从节点192.168.1.135
需求:端口由原来的20002修改为10002
2.1停掉该节点
[root@localhost bin]# ./mongo localhost:20002
repltest:SECONDARY> use admin
repltest:SECONDARY> db.auth("sa","123456")
repltest:SECONDARY> db.shutdownServer()
2.2修改配置文件(mongo.cnf)将端口20002修改为10002
port = 10002
2.3启动该重库
[root@localhost bin]# ./mongod -f /opt/mongodb3015_slave/conf/mongo.cnf
2.4登陆主库执行如下命令
[root@localhost bin]# ./mongo localhost:20001
repltest:PRIMARY> use admin
repltest:PRIMARY> db.auth("sa","123456")
我们这里修改的"_id"为7的记录,对应的members索引值为[1]
repltest:PRIMARY> conf=rs.conf()
repltest:PRIMARY> conf.members[1].host="192.168.1.135:10002"
192.168.1.135:10002
repltest:PRIMARY> rs.reconfig(conf,{"force":true})
2.5查看配置是否生效
repltest:PRIMARY> rs.config()
{
"_id" : "repltest",
"version" : 161200,
"members" : [
{
"_id" : 5,
"host" : "192.168.1.134:20001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 7,
"host" : "192.168.1.135:10002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 8,
"host" : "192.168.1.135:20003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
repltest:PRIMARY> rs.status()
{
"set" : "repltest",
"date" : ISODate("2019-02-22T05:46:16.932Z"),
"myState" : 1,
"members" : [
{
"_id" : 5,
"name" : "192.168.1.134:20001",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 102966,
"optime" : Timestamp(1550806716, 1),
"optimeDate" : ISODate("2019-02-22T03:38:36Z"),
"electionTime" : Timestamp(1550804772, 1),
"electionDate" : ISODate("2019-02-22T03:06:12Z"),
"configVersion" : 161200,
"self" : true
},
{
"_id" : 7,
"name" : "192.168.1.135:10002",
"health" : 1,
"state" : 5,
"stateStr" : "STARTUP2",
"uptime" : 3,
"optime" : Timestamp(1550806716, 1),
"optimeDate" : ISODate("2019-02-22T03:38:36Z"),
"lastHeartbeat" : ISODate("2019-02-22T05:46:15.786Z"),
"lastHeartbeatRecv" : ISODate("2019-02-22T05:46:15.851Z"),
"pingMs" : 1,
"configVersion" : 161200
},
{
"_id" : 8,
"name" : "192.168.1.135:20003",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 7658,
"lastHeartbeat" : ISODate("2019-02-22T05:46:15.765Z"),
"lastHeartbeatRecv" : ISODate("2019-02-22T05:46:15.483Z"),
"pingMs" : 0,
"configVersion" : 161200
}
],
"ok" : 1
}
按照上面的方法分表修改其他机器