MongoDB-Verbindungszeichenfolge ReplicaSet funktioniert nicht

Ich habe ein MongoDB-Replikatset eingerichtet und dies ist die Struktur:

  • Ein primärer Knoten.
  • Ein sekundärer Knoten.
  • Ein Arbiter-Knoten.

Ich habe die Ausgabe von rs.status() am Ende dieses Beitrags eingefügt.

The problem I am having now is that when I have my application connected using the MongoDB connection string: mongodb://192.168.17.52:27017,192.168.17.223:27017,192.168.17.49:27017/?replicaSet=rs-nnt&readPreference=primary it will work if the primary node is specified first in the command separated list and in this instance 192.168.17.52:27017. If I was to stop the primary DB service, I would expect the application to use the secondary node but for some reason, it will not work and after some troubleshooting, I came to a conclusion that it will only take the first host specified in the connection string.

Bitte lassen Sie mich wissen, wenn weitere Informationen benötigt werden, und freuen Sie sich über jegliche Unterstützung!

rs.status():

rs-nnt:PRIMARY> rs.status()
{
        "set" : "rs-nnt",
        "date" : ISODate("2018-12-04T14:09:38.835Z"),
        "myState" : 1,
        "term" : NumberLong(8),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1543932576, 1),
                        "t" : NumberLong(8)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1543932576, 1),
                        "t" : NumberLong(8)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1543932576, 1),
                        "t" : NumberLong(8)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1543932576, 1),
                        "t" : NumberLong(8)
                }
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "192.168.17.52:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 10565,
                        "optime" : {
                                "ts" : Timestamp(1543932576, 1),
                                "t" : NumberLong(8)
                        },
                        "optimeDate" : ISODate("2018-12-04T14:09:36Z"),
                        "electionTime" : Timestamp(1543923115, 1),
                        "electionDate" : ISODate("2018-12-04T11:31:55Z"),
                        "configVersion" : 3,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "192.168.17.223:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 8427,
                        "optime" : {
                                "ts" : Timestamp(1543932576, 1),
                                "t" : NumberLong(8)
                        },
                        "optimeDurable" : {
                                "ts" : Timestamp(1543932576, 1),
                                "t" : NumberLong(8)
                        },
                        "optimeDate" : ISODate("2018-12-04T14:09:36Z"),
                        "optimeDurableDate" : ISODate("2018-12-04T14:09:36Z"),
                        "lastHeartbeat" : ISODate("2018-12-04T14:09:38.167Z"),
                        "lastHeartbeatRecv" : ISODate("2018-12-04T14:09:38.736Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "192.168.17.52:27017",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "192.168.17.49:27017",
                        "health" : 1,
                        "state" : 7,
                        "stateStr" : "ARBITER",
                        "uptime" : 10518,
                        "lastHeartbeat" : ISODate("2018-12-04T14:09:38.167Z"),
                        "lastHeartbeatRecv" : ISODate("2018-12-04T14:09:36.770Z"),
                        "pingMs" : NumberLong(0),
                        "configVersion" : 3
                }
        ],
        "ok" : 1,
        "operationTime" : Timestamp(1543932576, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1543932576, 1),
                "signature" : {
                        "hash" : BinData(0,"Ydlo0SyUlFlnZUfimAmGvrowuRs="),
                        "keyId" : NumberLong("6630712219715764225")
                }
        }
}

Extra information: The firewall has been turned off on all hosts. The hostname and IP address has been added to the hosts file on all servers.

0
ru

Es gibt keine Antworten.

0