需求:因为端口调整,需要改变副本的备份集
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
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Where Wizards Stay Up Late
Katie Hafner / Simon & Schuster / 1998-1-21 / USD 16.00
Twenty five years ago, it didn't exist. Today, twenty million people worldwide are surfing the Net. "Where Wizards Stay Up Late" is the exciting story of the pioneers responsible for creating the most......一起来看看 《Where Wizards Stay Up Late》 这本书的介绍吧!