#模拟主节点异常中断
[root@ba3b27d855f6 bin]# kill -9 199
[root@ba3b27d855f6 bin]#
#连接到其中一台备份节点
[root@ba3b27d855f6 bin]# ./mongo 172.17.0.4:27018
MongoDB shell version v3.6.3
connecting to: mongodb://172.17.0.4:27018/test
MongoDB server version: 3.6.3
Server has startup warnings:
2018-08-10T07:12:26.849+0000 I CONTROL [initandlisten]
2018-08-10T07:12:26.849+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-10T07:12:26.849+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-08-10T07:12:26.849+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-10T07:12:26.849+0000 I CONTROL [initandlisten]
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten]
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten]
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-10T07:12:26.850+0000 I CONTROL [initandlisten]
test:SECONDARY> rs.config()
{
"_id" : "test",
"version" : 88878,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "172.17.0.4:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "172.17.0.4:27018",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 0
},
{
"_id" : 2,
"host" : "172.17.0.4:27019",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 0
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5b6d3d7e3e136dadfa2a8181")
}
}
test:SECONDARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-08-10T07:42:56.040Z"),
"myState" : 2,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.17.0.4:27017",
"health" : 0,
"state" : 8, #8 代表DOWN
"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("2018-08-10T07:42:54.251Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:42:02.603Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "172.17.0.4:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1831,
"optime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:41:54Z"),
"infoMessage" : "could not find member to sync from",
"configVersion" : 88878,
"self" : true
},
{
"_id" : 2,
"name" : "172.17.0.4:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1151,
"optime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:41:54Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:41:54Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:42:54.245Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:42:54.245Z"),
"pingMs" : NumberLong(0),
"configVersion" : 88878
}
],
"ok" : 1,
"operationTime" : Timestamp(1533886914, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533886914, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:SECONDARY> rs.slaveOk()
test:SECONDARY> db.school.find()
{ "_id" : ObjectId("5b6d3436dc9a5ab161c121e1"), "name" : "xuaiqi", "date" : ISODate("2018-08-10T06:44:06.284Z") }
{ "_id" : ObjectId("5b6d37ce1a42350d380cb142"), "nme" : "ddddd" }
test:SECONDARY>
test:SECONDARY>
test:SECONDARY> var config = rs.config()
test:SECONDARY> config.members[1].priority = 1
1
test:SECONDARY> config.members[1].votes = 1
1
test:SECONDARY> config.members[0].priority = 0
0
test:SECONDARY> config.members[0].votes = 0
0
test:SECONDARY>
test:SECONDARY> rs.reconfig(config, {"force" : true})
{
"ok" : 1,
"operationTime" : Timestamp(1533886914, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533886914, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:SECONDARY>
test:SECONDARY>
test:SECONDARY>
test:SECONDARY>
test:SECONDARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-08-10T07:46:28.258Z"),
"myState" : 2,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.17.0.4:27017",
"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("2018-08-10T07:46:27.827Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:42:02.603Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "172.17.0.4:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 2043,
"optime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:41:54Z"),
"infoMessage" : "could not find member to sync from",
"configVersion" : 195180,
"self" : true
},
{
"_id" : 2,
"name" : "172.17.0.4:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1363,
"optime" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1533886914, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-08-10T07:41:54Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:41:54Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:46:27.811Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:46:27.817Z"),
"pingMs" : NumberLong(0),
"configVersion" : 195180
}
],
"ok" : 1,
"operationTime" : Timestamp(1533886914, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533886914, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:SECONDARY> rs.status()
{
"set" : "test",
"date" : ISODate("2018-08-10T07:46:36.524Z"),
"myState" : 1,
"term" : NumberLong(2),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"appliedOpTime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
}
},
"members" : [
{
"_id" : 0,
"name" : "172.17.0.4:27017",
"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("2018-08-10T07:46:34.526Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:42:02.603Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Connection refused",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "172.17.0.4:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 2051,
"optime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2018-08-10T07:46:29Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1533887188, 1),
"electionDate" : ISODate("2018-08-10T07:46:28Z"),
"configVersion" : 195180,
"self" : true
},
{
"_id" : 2,
"name" : "172.17.0.4:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1372,
"optime" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"optimeDurable" : {
"ts" : Timestamp(1533887189, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2018-08-10T07:46:29Z"),
"optimeDurableDate" : ISODate("2018-08-10T07:46:29Z"),
"lastHeartbeat" : ISODate("2018-08-10T07:46:36.519Z"),
"lastHeartbeatRecv" : ISODate("2018-08-10T07:46:32.819Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "172.17.0.4:27018",
"configVersion" : 195180
}
],
"ok" : 1,
"operationTime" : Timestamp(1533887189, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1533887189, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
test:PRIMARY> exit
bye
[root@ba3b27d855f6 bin]#