服务器信息
ip | 系统 | 配置 | 服务 | 目录 |
---|---|---|---|---|
172.24.32.201 | centos7.7 | 2c4g | mongo-primary | /var/lib/mongo (the data directory) /var/log/mongodb (the log directory) |
172.24.32.201 | centos7.7 | 2c4g | mongo-secondary | /var/lib/mongo27018 (the data directory) /var/log/mongodb27018 (the log directory) |
172.24.32.201 | centos7.7 | 2c4g | mongo-abiter | /var/lib/mongo27019 (the data directory) /var/log/mongodb27019 (the log directory) |
1、关闭 primary 节点,连接数据库,验证数据库主备切换状态,并再次进行查询操作,验证数据库可用性。
systemctl stop mongod
连接之前secondary节点,发现已经变成了主
mongo 172.24.32.201:27018
MongoDB shell version v3.4.24
connecting to: mongodb://172.24.32.201:27018/test
MongoDB server version: 3.4.24
lugotestrepl:PRIMARY>
查看是否为主
lugotestrepl:PRIMARY> rs.isMaster();
{
"hosts" : [
"172.24.32.201:27017",
"172.24.32.201:27018"
],
"arbiters" : [
"172.24.32.201:27019"
],
"setName" : "lugotestrepl",
"setVersion" : 3,
"ismaster" : true,
"secondary" : false,
"primary" : "172.24.32.201:27018",
"me" : "172.24.32.201:27018",
"electionId" : ObjectId("7fffffff0000000000000003"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1589446106, 1),
"t" : NumberLong(3)
},
"lastWriteDate" : ISODate("2020-05-14T08:48:26Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2020-05-14T08:48:31.108Z"),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"readOnly" : false,
"ok" : 1
}
查询数据
switched to db lugotest
lugotestrepl:PRIMARY> db.auth('lugo','test123')
1
lugotestrepl:PRIMARY> db.movie.find().pretty()
{
"_id" : ObjectId("5ebbbca5692adbface98b2af"),
"moviename" : "大侦探福尔摩斯",
"points" : "9.5"
}
{
"_id" : ObjectId("5ebbbca5692adbface98b2b0"),
"moviename" : "掠夺",
"points" : "9.2"
}
{
"_id" : ObjectId("5ebbbca5692adbface98b2b1"),
"moviename" : "摇滚黑帮",
"points" : "9.9"
}
{
"_id" : ObjectId("5ebbbca5692adbface98b2b2"),
"moviename" : "两杆大烟枪",
"points" : "9.1"
}
{
"_id" : ObjectId("5ebcff34df72ed1bb0505234"),
"moviename" : "杀死比尔",
"points" : "9.0"
}
数据可查
2、重新启用原先的 primary 节点,并使其重新被选为集群的主节点。
systemctl start mongod
进入mongo27017,查看主从状态
lugotestrepl:SECONDARY> rs.status();
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T08:52:19.050Z"),
"myState" : 2,
"term" : NumberLong(3),
"syncingTo" : "172.24.32.201:27018",
"syncSourceHost" : "172.24.32.201:27018",
"syncSourceId" : 1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
},
"appliedOpTime" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
},
"durableOpTime" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 51,
"optime" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2020-05-14T08:52:16Z"),
"syncingTo" : "172.24.32.201:27018",
"syncSourceHost" : "172.24.32.201:27018",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 3,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 49,
"optime" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
},
"optimeDurable" : {
"ts" : Timestamp(1589446336, 1),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2020-05-14T08:52:16Z"),
"optimeDurableDate" : ISODate("2020-05-14T08:52:16Z"),
"lastHeartbeat" : ISODate("2020-05-14T08:52:17.939Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T08:52:18.081Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1589445905, 1),
"electionDate" : ISODate("2020-05-14T08:45:05Z"),
"configVersion" : 3
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 49,
"lastHeartbeat" : ISODate("2020-05-14T08:52:17.939Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T08:52:17.410Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 3
}
],
"ok" : 1
}
发现只是变成了从,没有重新变为主
我们这里先重启现在的主节点,让其变成从,恢复成以前的架构
systemctl restart mongod27018
- 27017 primary
- 27018 secondary
- 27019 abiter
进入主节点
mongo 172.24.32.201:27017
修改priority
lugotestrepl:PRIMARY> config=rs.conf()
{
"_id" : "lugotestrepl",
"version" : 3,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "172.24.32.201:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "172.24.32.201:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "172.24.32.201:27019",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5ebcb9e6ae7887a3e356b850")
}
}
lugotestrepl:PRIMARY> config.members[0].priority = 33
33
lugotestrepl:PRIMARY> rs.reconfig(config)
{ "ok" : 1 }
查看修改后的priority信息
lugotestrepl:PRIMARY> rs.conf()
{
"_id" : "lugotestrepl",
"version" : 4,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "172.24.32.201:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 33,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "172.24.32.201:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "172.24.32.201:27019",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5ebcb9e6ae7887a3e356b850")
}
}
我们现在关掉主27017
systemctl stop mongod
30s后启动
systemctl start mongod
lugotestrepl:PRIMARY> rs.status()
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:08:31.676Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 33,
"optime" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:08:31Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1589447289, 1),
"electionDate" : ISODate("2020-05-14T09:08:09Z"),
"configVersion" : 4,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 32,
"optime" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1589447311, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:08:31Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:08:31Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:08:31.654Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:08:30.045Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 4
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 32,
"lastHeartbeat" : ISODate("2020-05-14T09:08:31.652Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:08:26.863Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 4
}
],
"ok" : 1
}
发现27017又恢复成了主
3、将 arbiter 替换为一个独立的 secondary 节点。并验证数据库集群状态。
先移除arbiter节点
[root@test02 lib]# mongo 172.24.32.201:27017
MongoDB shell version v3.4.24
connecting to: mongodb://172.24.32.201:27017/test
MongoDB server version: 3.4.24
lugotestrepl:PRIMARY> db.auth('root','test123')
1
lugotestrepl:PRIMARY> rs.remove('172.24.32.201:27019');
{ "ok" : 1 }
查看状态
lugotestrepl:PRIMARY> rs.status();
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:23:27.667Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 929,
"optime" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:23:21Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1589447289, 1),
"electionDate" : ISODate("2020-05-14T09:08:09Z"),
"configVersion" : 5,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 928,
"optime" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1589448201, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:23:21Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:23:21Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:23:27.117Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:23:27.116Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 5
}
],
"ok" : 1
}
停止27019实例
systemctl stop mongod27019
初始化这个实例,即删除data
mkdir -p /tmp/27919data
mv /var/lib/mongo27019/* /tmp/27919data/
重启这个实例
systemctl start mongod27019
变成seconday
[root@test02 lib]# mongo 172.24.32.201:27017
MongoDB shell version v3.4.24
connecting to: mongodb://172.24.32.201:27017/test
MongoDB server version: 3.4.24
lugotestrepl:PRIMARY> db.auth('root','test123')
1
lugotestrepl:PRIMARY> rs.add('172.24.32.201:27019');
{ "ok" : 1 }
查看集群状态
lugotestrepl:PRIMARY> rs.status();
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:30:32.881Z"),
"myState" : 1,
"term" : NumberLong(6),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1354,
"optime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:30:31Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1589447289, 1),
"electionDate" : ISODate("2020-05-14T09:08:09Z"),
"configVersion" : 6,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1353,
"optime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:30:31Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:30:31Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:30:31.498Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:30:32.538Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 6
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 39,
"optime" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"optimeDurable" : {
"ts" : Timestamp(1589448631, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:30:31Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:30:31Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:30:31.498Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:30:31.024Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 6
}
],
"ok" : 1
}
4、关闭数据库的两个 secondary 节点,并验证数据库可用性。
systemctl stop mongod27018
systemctl stop mongod27019
进入主节点27017
lugotestrepl:SECONDARY> rs.status()
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:36:18.312Z"),
"myState" : 2,
"term" : NumberLong(6),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589448701, 1),
"t" : NumberLong(6)
},
"appliedOpTime" : {
"ts" : Timestamp(1589448711, 1),
"t" : NumberLong(6)
},
"durableOpTime" : {
"ts" : Timestamp(1589448711, 1),
"t" : NumberLong(6)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1700,
"optime" : {
"ts" : Timestamp(1589448711, 1),
"t" : NumberLong(6)
},
"optimeDate" : ISODate("2020-05-14T09:31:51Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"configVersion" : 6,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:36:14.717Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:31:48.577Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : -1
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:36:14.717Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:31:49.067Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : -1
}
],
"ok" : 1
}
发现剩的主变成了从了,数据库不可用
5、重新启用一个 secondary 节点,并验证数据库可用性
systemctl start mongod27019
lugotestrepl:PRIMARY> rs.status();
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:51:59.187Z"),
"myState" : 1,
"term" : NumberLong(7),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
},
"appliedOpTime" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
},
"durableOpTime" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2641,
"optime" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
},
"optimeDate" : ISODate("2020-05-14T09:51:52Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1589449901, 1),
"electionDate" : ISODate("2020-05-14T09:51:41Z"),
"configVersion" : 6,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:51:59.030Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:31:48.577Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : -1
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 28,
"optime" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
},
"optimeDurable" : {
"ts" : Timestamp(1589449912, 1),
"t" : NumberLong(7)
},
"optimeDate" : ISODate("2020-05-14T09:51:52Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:51:52Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:51:59.014Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:51:58.448Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 6
}
],
"ok" : 1
}
27017实例变成了主,数据库可用。
6、重新启用第二个 sencondary 节点,并验证数据库可用性。
启动第二个从节点
systemctl start mongod27018
lugotestrepl:PRIMARY> rs.status();
{
"set" : "lugotestrepl",
"date" : ISODate("2020-05-14T09:53:46.174Z"),
"myState" : 1,
"term" : NumberLong(7),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"appliedOpTime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"durableOpTime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.24.32.201:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2748,
"optime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"optimeDate" : ISODate("2020-05-14T09:53:42Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1589449901, 1),
"electionDate" : ISODate("2020-05-14T09:51:41Z"),
"configVersion" : 6,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "172.24.32.201:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 63,
"optime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"optimeDurable" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"optimeDate" : ISODate("2020-05-14T09:53:42Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:53:42Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:53:45.152Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:53:44.451Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27019",
"syncSourceHost" : "172.24.32.201:27019",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 6
},
{
"_id" : 2,
"name" : "172.24.32.201:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 135,
"optime" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"optimeDurable" : {
"ts" : Timestamp(1589450022, 1),
"t" : NumberLong(7)
},
"optimeDate" : ISODate("2020-05-14T09:53:42Z"),
"optimeDurableDate" : ISODate("2020-05-14T09:53:42Z"),
"lastHeartbeat" : ISODate("2020-05-14T09:53:45.061Z"),
"lastHeartbeatRecv" : ISODate("2020-05-14T09:53:44.498Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "172.24.32.201:27017",
"syncSourceHost" : "172.24.32.201:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 6
}
],
"ok" : 1
}
数据库可用