mongodb副本集的驗(yàn)證

服務(wù)器信息

ip 系統(tǒng) 配置 服務(wù) 目錄
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、關(guān)閉 primary 節(jié)點(diǎn),連接數(shù)據(jù)庫,驗(yàn)證數(shù)據(jù)庫主備切換狀態(tài),并再次進(jìn)行查詢操作,驗(yàn)證數(shù)據(jù)庫可用性。

systemctl stop mongod

連接之前secondary節(jié)點(diǎn),發(fā)現(xiàn)已經(jīng)變成了主

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
}

查詢數(shù)據(jù)

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"
}

數(shù)據(jù)可查

2、重新啟用原先的 primary 節(jié)點(diǎn),并使其重新被選為集群的主節(jié)點(diǎn)。

systemctl start mongod

進(jìn)入mongo27017,查看主從狀態(tài)

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
}

發(fā)現(xiàn)只是變成了從,沒有重新變?yōu)橹?/p>

我們這里先重啟現(xiàn)在的主節(jié)點(diǎn),讓其變成從,恢復(fù)成以前的架構(gòu)

systemctl restart mongod27018
  • 27017 primary
  • 27018 secondary
  • 27019 abiter

進(jìn)入主節(jié)點(diǎn)

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")
    }
}

我們現(xiàn)在關(guān)掉主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
}

發(fā)現(xiàn)27017又恢復(fù)成了主

3、將 arbiter 替換為一個(gè)獨(dú)立的 secondary 節(jié)點(diǎn)。并驗(yàn)證數(shù)據(jù)庫集群狀態(tài)。

先移除arbiter節(jié)點(diǎn)

[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 }

查看狀態(tài)

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實(shí)例

systemctl stop mongod27019

初始化這個(gè)實(shí)例,即刪除data

mkdir -p /tmp/27919data
mv /var/lib/mongo27019/* /tmp/27919data/

重啟這個(gè)實(shí)例

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 }

查看集群狀態(tài)

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、關(guān)閉數(shù)據(jù)庫的兩個(gè) secondary 節(jié)點(diǎn),并驗(yàn)證數(shù)據(jù)庫可用性。

systemctl stop mongod27018
systemctl stop mongod27019

進(jìn)入主節(jié)點(diǎn)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
}

發(fā)現(xiàn)剩的主變成了從了,數(shù)據(jù)庫不可用

5、重新啟用一個(gè) secondary 節(jié)點(diǎn),并驗(yàn)證數(shù)據(jù)庫可用性

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實(shí)例變成了主,數(shù)據(jù)庫可用。

6、重新啟用第二個(gè) sencondary 節(jié)點(diǎn),并驗(yàn)證數(shù)據(jù)庫可用性。

啟動第二個(gè)從節(jié)點(diǎn)

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
}

數(shù)據(jù)庫可用

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容