问题描述
我用下面的 mongod.conf [Primary1,Secondary1,Secondary2] 创建了 3 个 mongodb 实例
net:
port: 27017
bindIp: 0.0.0.0
replication:
replSetName: Replica1
我已经使用“ sudo service mongod start ”启动了 3 个实例 如果我使用 mongo –host "ip" –port 27017 将主服务器连接到其他 2 个服务器..它正在工作并已连接。
问题 1:
在我执行 rs.initiate() 和 rs.conf() 之后 次要 1 包含在成员中,但是当我使用 rs.status() 但显示 stateStr" : "STARTUP" 如果我检查它的日志意味着以下错误:
"msg":"获取事务表失败","attr":{"error":"NotYetinitialized: 复制尚未配置"}}
问题 2:
由于问题 1,如果我尝试将 rs.add() 用于中学 2,它不起作用
rs.status() 响应
{
"_id" : 0,"name" : "primary:27017","health" : 1,"state" : 1,"stateStr" : "PRIMARY",.......
}
{
"_id" : 1,"name" : "secondary1:27017","state" : 0,"stateStr" : "STARTUP","uptime" : 1579,"optime" : {
"ts" : Timestamp(0,0),"t" : NumberLong(-1)
},"optimeDurable" : {
"ts" : Timestamp(0,"optimeDate" : ISODate("1970-01-01T00:00:00Z"),"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),"lastHeartbeat" : ISODate("2021-01-08T04:47:35.455Z"),"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),"pingMs" : NumberLong(0),"lastHeartbeatMessage" : "","syncSourceHost" : "","syncSourceId" : -1,"infoMessage" : "","configVersion" : -2,"configTerm" : -1
}
辅助 1 的 mongodb.log 的日志输出
{"t":{"$date":"2021-01-08T04:39:16.634+00:00"},"s":"I","c":"CONNPOOL","id":22576,"ctx":"ReplNetwork","msg":"Connecting","attr":{"hostAndPort":"primary:27017"}}
{"t":{"$date":"2021-01-08T04:39:18.004+00:00"},"c":"CONTROL","id":20714,"ctx":"LogicalSessionCacheRefresh","msg":"Failed to refresh session cache,will try again at the next refresh interval","attr":{"error":"NotYetinitialized: Replication has not yet been configured"}}
{"t":{"$date":"2021-01-08T04:39:18.004+00:00"},"id":20712,"ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
{"t":{"$date":"2021-01-08T04:39:36.634+00:00"},"attr":{"hostAndPort":"primary:27017"}}
解决方法
问题已解决。主数据库能够连接到辅助主机,但作为回报辅助主机不能。所以我调整了安全组并连接。外卖是所有主要和次要主机都应该能够在mongodb端口(27017)中相互连接