literakl / mezinamiridici

Traffic forum
htttps://www.mezinamiridici.cz
MIT License
4 stars 4 forks source link

Local MongoDB #134

Closed literakl closed 3 years ago

literakl commented 3 years ago

MongoDB Atlas is a far from Hetzner cloud which is not optimal. It is a shared instance with no guarantees.

Plan:

Info:

literakl commented 3 years ago

https://docs.mongodb.com/manual/tutorial/deploy-geographically-distributed-replica-set/ Across Two Data Centers: Two members to Site A and one member to Site B. If one of the members of the replica set is an arbiter [#arbiter-alternative], distribute the arbiter to Site A with a data-bearing member.

All machines run recent Debian.

literakl commented 3 years ago

Setup must be hardened and security configured as recommended by Mongo vendor. Both mongo nodes can be accessed only from machine A where the backend is running. No public internet access.

literakl commented 3 years ago

Other interesting documents:

https://jelastic.medium.com/mongodb-replica-set-auto-%D1%81lustering-for-high-availability-and-performance-d7e8983882fa (Specifics of the MongoDB Auto-Clustering, readPreference:’primaryPreferred’) https://www.mongodb.com/blog/post/optimizing-fast-responsive-reads-cross-region-replication-mongodb-atlas (2018 doc)

https://docs.mongodb.com/manual/core/read-preference/#mongodb-readmode-nearest https://docs.mongodb.com/manual/core/read-preference/#mongodb-readmode-primaryPreferred

https://docs.mongodb.com/manual/core/replica-set-hidden-member/#std-label-replica-set-hidden-members

LabN36 commented 3 years ago

MongoDB PSA Architecture is configured using docker swarm. so far it's working fine. Mongo nodes will automatically restart on crash as well as system boot(tested)

Note:

  1. performance related benchmark is not done for this.
literakl commented 3 years ago

Set up

literakl commented 3 years ago

systemctl status/stop/start mongod

literakl commented 3 years ago

H/A does not work. I have stopped mongo on primary and backend stopped working. I assume trouble is in a connection string.

MONGODB_URI=mongodb://user:pwd@10.0.0.3:27017/bud?replicaSet=bud-replica&authSource=admin

Should be: mongodb://db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl

See https://docs.mongodb.com/manual/reference/connection-string/#tls-options

literakl commented 3 years ago

You have not provided a documentation on how Mongo is installed and configured. I am doing a reverse engineering now. Mongo arbiter config on www is the same as on db-primary. MONGO_URI on backend points to the backend where mongod is not running. Can you fix it?

literakl commented 3 years ago

MONGODB_URI=mongodb://user:pwd@10.0.0.4:27017,10.0.0.6:27017,10.0.0.2:27017/bud?replicaSet=bud-replica&authSource=admin

2021-08-22 21:29:23.621 [ERROR] [getBlog.js:24]: Request failed MongoServerSelectionError: connection timed out at Timeout._onTimeout (/var/www/beta.mezinamiridici.cz/backend/node_modules/mongodb/lib/core/sdam/topology.js:439:30) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7) { reason: TopologyDescription { type: 'ReplicaSetNoPrimary', setName: 'bud-replica', maxSetVersion: 1, maxElectionId: 7fffffff0000000000000004, servers: Map { '10.0.0.6:27017' => [ServerDescription], '10.0.0.2:27017' => [ServerDescription], '10.0.0.3:27017' => [ServerDescription] }, stale: false, compatible: true, compatibilityError: null, logicalSessionTimeoutMinutes: 30, heartbeatFrequencyMS: 10000, localThresholdMS: 15, commonWireVersion: 9 } }

I need to review mongo configuration, there is an IP address mismatch

literakl commented 3 years ago

Completely removed and installed from scratch. Turning off the primary works fine too.

    "members" : [
            {
                    "_id" : 0,
                    "name" : "10.0.0.4:27017",
                    "health" : 0,
                    "state" : 8,
                    "stateStr" : "(not reachable/healthy)",