gpt4 book ai didi

mongodb - MongoError : no primary found in replicaset

转载 作者:行者123 更新时间:2023-12-03 17:04:08 24 4
gpt4 key购买 nike

我有 2 个应用程序服务器,它们连接到一个副本集(主要、次要和仲裁者)。

我面临的问题是

 [ 'MongoError: no primary found in replicaset',
' at ../server/node_modules/mongodb-core/lib/topologies/replset.js:524:28',
' at null.<anonymous> (../server/node_modules/mongodb-core/lib/topologies/replset.js:303:24)',
' at g (events.js:260:16)',
' at emitOne (events.js:77:13)',
' at emit (events.js:169:7)',
' at null.<anonymous> (../server/node_modules/mongodb-core/lib/topologies/server.js:326:21)',
' at emitOne (events.js:77:13)',
' at emit (events.js:169:7)',
' at null.<anonymous> (../server/node_modules/mongodb-core/lib/connection/pool.js:270:12)',
' at g (events.js:260:16)',
' at emitTwo (events.js:87:13)',
' at emit (events.js:172:7)',
' at Socket.<anonymous> (../server/node_modules/mongodb-core/lib/connection/connection.js:175:49)',
' at Socket.g (events.js:260:16)',
' at emitOne (events.js:77:13)',
' at Socket.emit (events.js:169:7)',
' at connectErrorNT (net.js:996:8)',
' at nextTickCallbackWith2Args (node.js:442:9)',
' at process._tickCallback (node.js:356:17)' ]

应用程序上的 ReplicaSet 配置:
 "mongodb" : { 
"replicaset": {
"db" : "test",
"user" : "admin",
"password" : "*********",
"name":"rs1",
"replicas": [{"host":"App1Box.dmz.mytest.com.au","port":27017}, {"host":"App2Box.dmz.mytest.com.au","port":27018}]
}

rs.status() 输出
rs1:PRIMARY> rs.status()
{
"set" : "rs1",
"date" : ISODate("2018-05-17T03:50:01Z"),
"myState" : 1,
"members" : [
{
"_id" : 2,
"name" : "App3Box:27018",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 7180,
"lastHeartbeat" : ISODate("2018-05-17T03:50:00Z"),
"lastHeartbeatRecv" : ISODate("2018-05-17T03:50:00Z"),
"pingMs" : 0
},
{
"_id" : 3,
"name" : "App2Box:27018",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 7528,
"optime" : Timestamp(1526521846, 1),
"optimeDate" : ISODate("2018-05-17T01:50:46Z"),
"electionTime" : Timestamp(1526521798, 1),
"electionDate" : ISODate("2018-05-17T01:49:58Z"),
"self" : true
},
{
"_id" : 4,
"name" : "App1Box:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 7139,
"optime" : Timestamp(1526521846, 1),
"optimeDate" : ISODate("2018-05-17T01:50:46Z"),
"lastHeartbeat" : ISODate("2018-05-17T03:50:01Z"),
"lastHeartbeatRecv" : ISODate("2018-05-17T03:50:01Z"),
"pingMs" : 0,
"syncingTo" : "App2Box:27018"
}
],
"ok" : 1
}

但是,我只从连接到 MongoDB 的应用服务器之一(例如 App1Box)看到了这一点。我在 App2Box 上没有看到这个问题。

我已经尝试从 replicaSets 中删除成员并重新添加,问题仍然存在。

Mongo version : 2.6.8 node version : 4.4.3 npm version : 3.8.9



在主要和次要上执行 rs.status() 时,我可以从 mongo 控制台看到 replicaSet 中的所有成员。

谢谢你的帮助。

最佳答案

发现问题出在向 replicaSet 添加成员时未使用完全限定的 DNS 名称。感谢@Neil Lunn。

关于mongodb - MongoError : no primary found in replicaset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50382346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com