【いじり1】
コマンドラインからレプリカセット作成と実行。
[pc3_centos7_k2]$ mkdir /tmp/rs0_{0,1,2}
[pc3_centos7_k2]$ mongod --replSet rs0 --port 27018 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_0 --oplogSize 128 &
[pc3_centos7_k2]$ mongod --replSet rs0 --port 27019 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_1 --oplogSize 128 &
[pc3_centos7_k2]$ mongod --replSet rs0 --port 27020 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_2 --oplogSize 128 &
... _id: "rs0",
... members: [
... {
... _id: 0,
... host: "localhost:27018"
... },
... {
... _id: 1,
... host: "localhost:27019"
... },
... {
... _id: 2,
... host: "localhost:27020"
... }
... ]
... }
> rs.initiate(rsconf)
rs0:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
rs0:PRIMARY> exit
bye
【いじり2】
別ホストからネットワーク越しに接続してみる
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27018
rs0:SECONDARY> exit
bye
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27019
rs0:PRIMARY> exit
bye
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27020
rs0:SECONDARY> exit
bye
root@192.168.101.32's password:
合計 800K
-rw-------. 1 root root 47 10月 19 14:51 WiredTiger
-rw-------. 1 root root 21 10月 19 14:51 WiredTiger.lock
-rw-------. 1 root root 1.3K 10月 19 16:24 WiredTiger.turtle
-rw-------. 1 root root 116K 10月 19 16:24 WiredTiger.wt
-rw-------. 1 root root 36K 10月 19 16:24 WiredTigerHS.wt
-rw-------. 1 root root 36K 10月 19 15:23 _mdb_catalog.wt
-rw-------. 1 root root 20K 10月 19 14:52 collection-0-5878475113836075537.wt
-rw-------. 1 root root 36K 10月 19 15:22 collection-10-5878475113836075537.wt
-rw-------. 1 root root 44K 10月 19 16:24 collection-16-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:22 collection-17-5878475113836075537.wt
-rw-------. 1 root root 36K 10月 19 16:24 collection-2-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:22 collection-21-5878475113836075537.wt
-rw-------. 1 root root 4.0K 10月 19 15:22 collection-23-5878475113836075537.wt
-rw-------. 1 root root 4.0K 10月 19 15:22 collection-25-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:23 collection-27-5878475113836075537.wt
-rw-------. 1 root root 24K 10月 19 15:29 collection-29-5878475113836075537.wt
-rw-------. 1 root root 36K 10月 19 16:24 collection-4-5878475113836075537.wt
-rw-------. 1 root root 36K 10月 19 15:22 collection-6-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 14:52 collection-8-5878475113836075537.wt
drwx------. 2 root root 71 10月 19 16:24 diagnostic.data
-rw-------. 1 root root 20K 10月 19 14:52 index-1-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:21 index-11-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:21 index-18-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:22 index-22-5878475113836075537.wt
-rw-------. 1 root root 4.0K 10月 19 15:22 index-24-5878475113836075537.wt
-rw-------. 1 root root 4.0K 10月 19 15:22 index-26-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:23 index-28-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 15:22 index-3-5878475113836075537.wt
-rw-------. 1 root root 24K 10月 19 15:29 index-30-5878475113836075537.wt
-rw-------. 1 root root 24K 10月 19 15:29 index-31-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 14:52 index-5-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 14:52 index-7-5878475113836075537.wt
-rw-------. 1 root root 20K 10月 19 14:52 index-9-5878475113836075537.wt
drwx------. 2 root root 110 10月 19 14:51 journal
-rw-------. 1 root root 5 10月 19 14:51 mongod.lock
-rw-------. 1 root root 36K 10月 19 16:24 sizeStorer.wt
-rw-------. 1 root root 114 10月 19 14:51 storage.bson
[pc3_centos7_k3]$ ssh 192.168.101.32 ls -lh /tmp/rs0_0/journal
root@192.168.101.32's password:
合計 300M
-rw-------. 1 root root 100M 10月 19 16:25 WiredTigerLog.0000000001
-rw-------. 1 root root 100M 10月 19 14:51 WiredTigerPreplog.0000000001
-rw-------. 1 root root 100M 10月 19 14:51 WiredTigerPreplog.0000000002
【いじり3】
上記の3台構成のレプリカセットでフェイルオーバすることを確認する
・レプリカセットの状態確認
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27019
rs0:PRIMARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2020-10-19T07:29:10.312Z"),
"myState" : 1,
"term" : NumberLong(1),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"votingMembersCount" : 3,
"writableVotingMembersCount" : 3,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1603092549, 1),
"t" : NumberLong(1)
},
"lastCommittedWallTime" : ISODate("2020-10-19T07:29:09.414Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1603092549, 1),
"t" : NumberLong(1)
},
"readConcernMajorityWallTime" : ISODate("2020-10-19T07:29:09.414Z"),
"appliedOpTime" : {
"ts" : Timestamp(1603092549, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1603092549, 1),
"t" : NumberLong(1)
},
"lastAppliedWallTime" : ISODate("2020-10-19T07:29:09.414Z"),
"lastDurableWallTime" : ISODate("2020-10-19T07:29:09.414Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1603092489, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2020-10-19T06:21:59.060Z"),
"electionTerm" : NumberLong(1),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1603088508, 1),
"t" : NumberLong(-1)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2020-10-19T06:21:59.215Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-10-19T06:22:00.471Z")
},
"members" : [
{
"_id" : 0,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4041,
"optime" : {
"ts" : Timestamp(1603092539, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1603092539, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-10-19T07:28:59Z"),
"optimeDurableDate" : ISODate("2020-10-19T07:28:59Z"),
"lastHeartbeat" : ISODate("2020-10-19T07:29:09.128Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:29:08.652Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "localhost:27019",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 1
},
{
"_id" : 1,
"name" : "localhost:27019",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 5821,
"optime" : {
"ts" : Timestamp(1603092549, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-10-19T07:29:09Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1603088519, 1),
"electionDate" : ISODate("2020-10-19T06:21:59Z"),
"configVersion" : 1,
"configTerm" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "localhost:27020",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 4041,
"optime" : {
"ts" : Timestamp(1603092539, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1603092539, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-10-19T07:28:59Z"),
"optimeDurableDate" : ISODate("2020-10-19T07:28:59Z"),
"lastHeartbeat" : ISODate("2020-10-19T07:29:09.127Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:29:08.651Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "localhost:27019",
"syncSourceId" : 1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1603092549, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1603092549, 1)
}
・データ挿入
rs0:PRIMARY> use chinko
rs0:PRIMARY> db.createCollection("chinko0")
rs0:PRIMARY> show dbs
admin 0.000GB
chinko 0.000GB
config 0.000GB
local 0.000GB
rs0:PRIMARY> show collections
chinko0
rs0:PRIMARY> db.chinko0.insertOne({name:"うんこっこ",age:20})
rs0:PRIMARY> db.chinko0.find()
{ "_id" : ObjectId("5f8d423d22c4e4d8bd644b8d"), "name" : "うんこっこ", "age" : 20 }
rs0:PRIMARY> exit
bye
mongodを実行してるホストでTCP27019でリスニングしてるインスタンスを落とす
[pc3_centos7_k2]$ ps -ef | grep mong[o]
mongod 6858 1 1 11:22 ? 00:03:12 /usr/bin/mongod -f /etc/mongod.conf
root 7055 6727 0 14:51 pts/0 00:00:53 mongod --replSet rs0 --port 27018 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_0 --oplogSize 128
root 7101 6727 1 14:52 pts/0 00:01:05 mongod --replSet rs0 --port 27019 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_1 --oplogSize 128
root 7150 6727 0 14:53 pts/0 00:00:53 mongod --replSet rs0 --port 27020 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_2 --oplogSize 128
[pc3_centos7_k2]$ kill 7101;echo $?
0
[pc3_centos7_k2]$ ps -ef | grep mong[o]
mongod 6858 1 1 11:22 ? 00:03:14 /usr/bin/mongod -f /etc/mongod.conf
root 7055 6727 0 14:51 pts/0 00:00:55 mongod --replSet rs0 --port 27018 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_0 --oplogSize 128
root 7150 6727 0 14:53 pts/0 00:00:54 mongod --replSet rs0 --port 27020 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_2 --oplogSize 128
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27020
rs0:SECONDARY> exit
bye
[pc3_centos7_k3]$ mongo --host 192.168.101.32 --port 27018
rs0:PRIMARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2020-10-19T07:46:16.122Z"),
"myState" : 1,
"term" : NumberLong(2),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"votingMembersCount" : 3,
"writableVotingMembersCount" : 3,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"lastCommittedWallTime" : ISODate("2020-10-19T07:46:01.995Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"readConcernMajorityWallTime" : ISODate("2020-10-19T07:46:01.995Z"),
"appliedOpTime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"lastAppliedWallTime" : ISODate("2020-10-19T07:46:01.995Z"),
"lastDurableWallTime" : ISODate("2020-10-19T07:46:01.995Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1603093520, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "stepUpRequestSkipDryRun",
"lastElectionDate" : ISODate("2020-10-19T07:43:10.909Z"),
"electionTerm" : NumberLong(2),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(1603093389, 1),
"t" : NumberLong(1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1603093389, 1),
"t" : NumberLong(1)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"priorPrimaryMemberId" : 1,
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2020-10-19T07:43:10.943Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2020-10-19T07:43:12.954Z")
},
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(1),
"lastVoteDate" : ISODate("2020-10-19T06:21:59.081Z"),
"electionCandidateMemberId" : 1,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1603088508, 1),
"t" : NumberLong(-1)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1603088508, 1),
"t" : NumberLong(-1)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "localhost:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 6916,
"optime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2020-10-19T07:46:01Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1603093390, 1),
"electionDate" : ISODate("2020-10-19T07:43:10Z"),
"configVersion" : 1,
"configTerm" : 2,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "localhost: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-10-19T07:46:15.099Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:43:11.629Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Error connecting to localhost:27019 (127.0.0.1:27019) :: caused by :: Connection refused",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 1
},
{
"_id" : 2,
"name" : "localhost:27020",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 5066,
"optime" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"optimeDurable" : {
"ts" : Timestamp(1603093561, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2020-10-19T07:46:01Z"),
"optimeDurableDate" : ISODate("2020-10-19T07:46:01Z"),
"lastHeartbeat" : ISODate("2020-10-19T07:46:14.944Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:46:15.088Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncSourceHost" : "localhost:27018",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 2
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1603093561, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1603093561, 1)
}
rs0:PRIMARY> show dbs
admin 0.000GB
chinko 0.000GB
config 0.000GB
local 0.000GB
rs0:PRIMARY> use chinko
rs0:PRIMARY> db.chinko0.find()
{ "_id" : ObjectId("5f8d423d22c4e4d8bd644b8d"), "name" : "うんこっこ", "age" : 20 }
3台構成のレプリカセットでは、ちゃんとレプリケーションされていて、かつ、プライマリーを落とすとちゃんとフェイルオーバーした。
【いじり4】
3台構成のレプリカセットでも1台落ちてて2台しかメンバーが居ないと、偶数台構成となっているが、この状態でプライマリを落としたらフェイルオーバーするか?
[pc3_centos7_k2]$ kill 7055;echo $?
0
[pc3_centos7_k2]$ ps -ef | grep mong[o]
mongod 6858 1 1 11:22 ? 00:03:22 /usr/bin/mongod -f /etc/mongod.conf
root 7150 6727 0 14:53 pts/0 00:01:05 mongod --replSet rs0 --port 27020 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_2 --oplogSize 128
[pc3_centos7_k2]$ mongo --port 27020
rs0:SECONDARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2020-10-19T08:00:08.594Z"),
"myState" : 2,
"term" : NumberLong(3),
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"votingMembersCount" : 3,
"writableVotingMembersCount" : 3,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1603094260, 1),
"t" : NumberLong(2)
},
"lastCommittedWallTime" : ISODate("2020-10-19T07:57:40.970Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1603094260, 1),
"t" : NumberLong(2)
},
"readConcernMajorityWallTime" : ISODate("2020-10-19T07:57:40.970Z"),
"appliedOpTime" : {
"ts" : Timestamp(1603094260, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1603094260, 1),
"t" : NumberLong(2)
},
"lastAppliedWallTime" : ISODate("2020-10-19T07:57:40.970Z"),
"lastDurableWallTime" : ISODate("2020-10-19T07:57:40.970Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1603094260, 1),
"electionParticipantMetrics" : {
"votedForCandidate" : true,
"electionTerm" : NumberLong(2),
"lastVoteDate" : ISODate("2020-10-19T07:43:10.920Z"),
"electionCandidateMemberId" : 0,
"voteReason" : "",
"lastAppliedOpTimeAtElection" : {
"ts" : Timestamp(1603093389, 1),
"t" : NumberLong(1)
},
"maxAppliedOpTimeInSet" : {
"ts" : Timestamp(1603093389, 1),
"t" : NumberLong(1)
},
"priorityAtElection" : 1
},
"members" : [
{
"_id" : 0,
"name" : "localhost: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-10-19T08:00:08.153Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:57:46.947Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Error connecting to localhost:27018 (127.0.0.1:27018) :: caused by :: Connection refused",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 2
},
{
"_id" : 1,
"name" : "localhost: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-10-19T08:00:08.154Z"),
"lastHeartbeatRecv" : ISODate("2020-10-19T07:43:11.627Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Error connecting to localhost:27019 (127.0.0.1:27019) :: caused by :: Connection refused",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 1
},
{
"_id" : 2,
"name" : "localhost:27020",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 7618,
"optime" : {
"ts" : Timestamp(1603094260, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2020-10-19T07:57:40Z"),
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1,
"configTerm" : 2,
"self" : true,
"lastHeartbeatMessage" : ""
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1603094260, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1603094260, 1)
}
→やはり偶数台構成になってるときはフェイルオーバーしなかった。
【いじり5】
もう一回起動
[pc3_centos7_k2]$ mongod --replSet rs0 --port 27018 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_0 --oplogSize 128 &
[pc3_centos7_k2]$ mongod --replSet rs0 --port 27019 --bind_ip localhost,192.168.101.32 --dbpath /tmp/rs0_1 --oplogSize 128 &
[pc3_centos7_k2]$ ps aux|egrep "mongo|RSS" | grep -v grep | awk '{printf "%6s%5s%5s%5s%8s%7s%6s%5s%6s%5s%9s%13s%7s%6s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12.$13,$14,$15}'
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mongod 6858 1.0 6.1 1941132 115352 ? Sl 11:22 3:38 /usr/bin/mongod-f/etc/mongod.conf
root 7150 0.9 7.1 2029120 133828 pts/0 Sl 14:53 1:25 mongod --replSetrs0 --port 27020
root 7761 0.8 6.6 1917520 125832 pts/0 Sl 17:05 0:10 mongod --replSetrs0 --port 27018
root 7847 0.8 6.5 1922884 123420 pts/0 Sl 17:06 0:09 mongod --replSetrs0 --port 27019
→負荷が小さいmongodbはリソースをほとんど食わない
【いじり6】
プライマリとセカンダリの選出
0.初期化時と初期化後共通
→レプリカセットが3メンバー構成の場合、プライマリを停止後、メンバーが残り2インスタンスになる場合ではプライマリが選出されるが、さらに1インスタンスを停止した場合停止したメンバーがプライマリ、セカンダリの違いに関係なく最後に起動してるメンバーはセカンダリになる。
※もともとプライマリだったメンバーも最後の1インスタンスになった場合やがてセカンダリに降格する。
1.初期化時
→初期化したインスタンスがプライマリになり、それ以外がセカンダリになる。
2.初期化後
2-1.プライマリ停止時
→idが最若番のセカンダリメンバーがプライマリになる
2-2.全メンバー落とし上げ時
→最初に起動したメンバーがプライマリになる。
すでに1インスタンスだけ起動している状態(このインスタンスは0.で確認したように
常にセカンダリ状態)で残り2メンバーを起動した場合は、もともと起動していたインス
タンスがプライマリになる。