1

首先谢谢你看我的问题。

我已经安装了 MongoDB 集群:

  • mdb0.domain.com - 仲裁
  • mdb1.domain.com - 主要(优先级 3)
  • mdb2.domain.com - 次要(优先级 2)
  • mdb3.domain.com - 次要(优先级 1)

启用授权(配置的一部分):

security:
  authorization: enabled
  keyFile: /etc/mongodb.key

replication:
  replSetName: prodreplset

它工作正常。rs.status()显示所有节点及其信息。我可以使用以下命令通过命令行(amd robo3t 也可以)连接到副本集:

./mongo --host mongodb://mdb1.domain.com:27017,mdb2.domain.com:27017,mdb3.domain.com:27017/db_production?replicaSet=prodreplset -u dbuser -p dbpass --authenticationDatabase db_production

它工作正常:

2018-07-25T16:32:29.525+0300 I NETWORK  [js] Starting new replica set monitor for prodreplset/mdb1.domain.com:27017,mdb2.domain.com:27017,mdb3.domain.com:27017
2018-07-25T16:32:29.578+0300 I NETWORK  [js] Successfully connected to mdb2.domain.com:27017 (1 connections now open to mdb2.domain.com:27017 with a 5 second timeout)
2018-07-25T16:32:29.578+0300 I NETWORK  [ReplicaSetMonitor-TaskExecutor] Successfully connected to mdb1.domain.com:27017 (1 connections now open to mdb1.domain.com:27017 with a 5 second timeout)
2018-07-25T16:32:29.648+0300 I NETWORK  [ReplicaSetMonitor-TaskExecutor] Successfully connected to mdb3.domain.com:27017 (1 connections now open to mdb3.domain.com:27017 with a 5 second timeout)
MongoDB server version: 4.0.0
prodreplset:PRIMARY> 

当我手动停止 mdb1.domain.com(重现可能的问题)时,replicaset 投票支持新的“Primary”,我可以看到新的主 mdb2.domain.com。那时 mdb1.domain.com 节点的状态"stateStr" : "(not reachable/healthy)"

那时我正在尝试连接副本集并收到以下错误:

MongoDB shell version v4.0.0
connecting to: mongodb://mdb1.domain.com:27017,mdb2.domain.com:27017,mdb3.domain.com:27017/db_production?replicaSet=prodreplset
2018-07-25T16:42:01.466+0300 I NETWORK  [js] Starting new replica set monitor for prodreplset/mdb1.domain.com:27017,mdb2.domain.com:27017,mdb3.domain.com:27017
2018-07-25T16:42:01.506+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:01.506+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2018-07-25T16:42:02.072+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:02.072+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2018-07-25T16:42:02.632+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:02.632+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2018-07-25T16:42:03.192+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:03.192+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 4 checks in a row.
2018-07-25T16:42:03.752+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:03.752+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 5 checks in a row.
2018-07-25T16:42:04.314+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:04.314+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 6 checks in a row.
2018-07-25T16:42:04.874+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:04.874+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 7 checks in a row.
2018-07-25T16:42:05.434+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:05.434+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 8 checks in a row.
2018-07-25T16:42:05.996+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:05.996+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 9 checks in a row.
2018-07-25T16:42:06.560+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:06.560+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 10 checks in a row.
2018-07-25T16:42:07.120+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:07.120+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 11 checks in a row.
2018-07-25T16:42:07.681+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:09.303+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:09.866+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:10.425+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:10.990+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:11.550+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:12.110+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:12.670+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:13.231+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:13.800+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:13.800+0300 I NETWORK  [js] Cannot reach any nodes for set prodreplset. Please check network connectivity and the status of the set. This has happened for 21 checks in a row.
2018-07-25T16:42:14.360+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:14.924+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:15.484+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:16.048+0300 W NETWORK  [js] Unable to reach primary for set prodreplset
2018-07-25T16:42:16.048+0300 E QUERY    [js] Error: connect failed to replica set prodreplset/mdb1.domain.com:27017,mdb2.domain.com:27017,mdb3.domain.com:27017 :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

但是当我启动 mdb1.domain.com 并且它开始成为 Primary 时,我可以再次连接!

为什么我不能在没有一台服务器和新的 Primary 的情况下连接 seplicaset?

4

0 回答 0