修改mongodb(帶仲裁節點的副本集)各機器端口
需求:因為端口調整,需要改變副本的備份集
1.查看當前的副本集信息
[root@localhost bin]# ./mongo 192.168.1.134:10001
repltest:PRIMARY> use admin
repltest:PRIMARY> db.auth("sa","123456")
repltest:PRIMARY> rs.config()
{
"_id" : "repltest",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "192.168.1.134:10001",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 1,
"host" : "192.168.1.135:10002" ,
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 2,
"host" : "192.168.1.135:10003" ,
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatTimeoutSecs" : 10,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
}
}
}
我們需要將這裏各機器的端口10001,10002,10003分別修改為20001,20002,20003
2.修改從庫192.168.1.135:10002為192.168.1.135:20002
2.1 停掉該從庫
[root@localhost bin]# ./mongo localhost:10002
repltest:SECONDARY> use admin
repltest:SECONDARY> db.auth("sa","123456")
repltest:SECONDARY> db.shutdownServer()
2.2修改配置文件(mongo.cnf)將端口10002修改為20002
port = 20002
2.3啟動該重庫
[root@localhost bin]# ./mongod -f /opt/mongodb3015_slave/conf/mongo.cnf
2.4登陸主庫執行如下命令
repltest:PRIMARY> rs.remove("192.168.1.135:10002") ##移除原配置文件中的已經變更地址的主機
repltest:PRIMARY> rs.add("192.168.1.135:20002") ##添加變更後的端口
2.5查看配置是否生效
rs.config()
rs.status()
3.修改仲裁節點的端口
3.1停掉仲裁節點
[root@localhost bin]# ./mongo localhost:10003
MongoDB shell version: 3.0.15
connecting to: localhost:10003/test
repltest:ARBITER> use admin
switched to db admin
repltest:ARBITER> db.auth("sa","123456")
Error: 18 Authentication failed.
0
repltest:ARBITER> db.shutdownServer()
3.2修改配置文件(mongo.cnf)將端口10003修改為20003
port = 20002
3.3啟動該重庫
[root@localhost bin]# ./mongod -f /opt/mongodb3015_arbiter/conf/mongo.cnf
3.4登陸主庫執行如下命令
repltest:PRIMARY> rs.remove("192.168.1.135:10003") ##移除原配置文件中的已經變更地址的主機
repltest:PRIMARY> rs.addArb("192.168.1.135:20003") ##添加仲裁節點
3.5查看配置是否生效
rs.config()
rs.status()
4.修改主庫192.168.1.134:10001為192.168.1.134:10002
4.1 停掉該主庫
[root@localhost bin]# ./mongo localhost:10001
repltest:PRIMARY> use admin
repltest:PRIMARY> db.auth("sa","123456")
repltest:PRIMARY> db.shutdownServer()
這個時候該另外一個從庫會變更為主庫
4.2修改配置文件(mongo.cnf)將端口10001修改為20001
port = 20001
4.3啟動該庫
[root@localhost bin]# ./mongod -f /opt/mongodb3015/conf/mongo.cnf
4.4登陸主庫執行如下命令
root@localhost bin]# ./mongo 192.168.1.135:20002
repltest:PRIMARY> use admin
repltest:PRIMARY> db.auth("sa","123456")
repltest:PRIMARY> rs.remove("192.168.1.134:10001") ##移除原配置文件中的已經變更地址的主機
repltest:PRIMARY> rs.add("192.168.1.134:20001") ##添加變更後的端口
5.整個配置完成後查看配置和狀態
repltest:PRIMARY> rs.conf()
{
"_id" : "repltest",
"version" : 7,
"members" : [
{
"_id" : 3,
"host" : "192.168.1.135:20002",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 4,
"host" : "192.168.1.135:20003",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : 0,
"votes" : 1
},
{
"_id" : 5,
"host" : "192.168.1.134:20001",
"arbiterOnly" : false,
"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-21T01:13:14.107Z"),
"myState" : 1,
"members" : [
{
"_id" : 3,
"name" : "192.168.1.135:20002",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1504,
"optime" : Timestamp(1550711569, 1),
"optimeDate" : ISODate("2019-02-21T01:12:49Z"),
"electionTime" : Timestamp(1550711217, 1),
"electionDate" : ISODate("2019-02-21T01:06:57Z"),
"configVersion" : 7,
"self" : true
},
{
"_id" : 4,
"name" : "192.168.1.135:20003",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 596,
"lastHeartbeat" : ISODate("2019-02-21T01:13:13.747Z"),
"lastHeartbeatRecv" : ISODate("2019-02-21T01:13:12.451Z"),
"pingMs" : 0,
"configVersion" : 7
},
{
"_id" : 5,
"name" : "192.168.1.134:20001",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 22,
"optime" : Timestamp(1550711569, 1),
"optimeDate" : ISODate("2019-02-21T01:12:49Z"),
"lastHeartbeat" : ISODate("2019-02-21T01:13:13.791Z"),
"lastHeartbeatRecv" : ISODate("2019-02-21T01:13:13.851Z"),
"pingMs" : 0,
"syncingTo" : "192.168.1.135:20002",
"configVersion" : 7
}
],
"ok" : 1
}
修改mongodb(帶仲裁節點的副本集)各機器端口