他的回复:
主从编写[root@chinaskill-sql-1 local]# vi /usr/local/mongodb/mongod.confbind_ip=0.0.0.0replSet=rs[root@chinaskill-sql-1 local]# mongod -f /usr/local/mongodb/mongod.conf &[root@chinaskill-sql-2 local]# vi /usr/local/mongodb/mongod.confbind_ip=0.0.0.0replSet=rs[root@chinaskill-sql-2 local]# mongod -f /usr/local/mongodb/mongod.conf &[root@chinaskill-sql-1 local]# mongo> rs.status(){ "operationTime" : Timestamp(0, 0), "ok" : 0, "errmsg" : "no replset config has been received", "code" : 94, "codeName" : "NotYetInitialized", "$clusterTime" : { "clusterTime" : Timestamp(0, 0), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }}> var config={_id:"rs",members:[{_id:0,host:"172.16.2.76:27017"},{_id:1,host:"172.16.2.45:27017"}]}> rs.initiate(config)……rs:PRIMARY> rs.status(){ "set" : "rs", "date" : ISODate("2022-09-08T06:49:13.414Z"), "myState" : 1, "term" : NumberLong(1), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "readConcernMajorityOpTime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) } }, "lastStableCheckpointTimestamp" : Timestamp(1662619698, 1), "members" : [ { "_id" : 0, "name" : "172.16.2.76:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 284, "optime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-09-08T06:49:08Z"), "syncingTo" : "", "syncSourceHost" : "", "syncSourceId" : -1, "infoMessage" : "could not find member to sync from", "electionTime" : Timestamp(1662619696, 1), "electionDate" : ISODate("2022-09-08T06:48:16Z"), "configVersion" : 1, "self" : true, "lastHeartbeatMessage" : "" }, { "_id" : 1, "name" : "172.16.2.45:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 68, "optime" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1662619748, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2022-09-08T06:49:08Z"), "optimeDurableDate" : ISODate("2022-09-08T06:49:08Z"), "lastHeartbeat" : ISODate("2022-09-08T06:49:12.328Z"), "lastHeartbeatRecv" : ISODate("2022-09-08T06:49:12.582Z"), "pingMs" : NumberLong(0), "lastHeartbeatMessage" : "", "syncingTo" : "172.16.2.76:27017", "syncSourceHost" : "172.16.2.76:27017", "syncSourceId" : 0, "infoMessage" : "", "configVersion" : 1 } ], "ok" : 1, "operationTime" : Timestamp(1662619748, 1), "$clusterTime" : { "clusterTime" : Timestamp(1662619748, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }}rs:PRIMARY> exitbye