Cluster and Replication Setup
Deployment Scheme
danger
For passwords and secret combinations, the character set abcdefghijklmnopqrstuvwxyzABCDEF is used. Be sure to generate a more complex password consisting of at least 32 characters.
MongoDB Replica Set Configuration
According to the deployment scheme, the replica consists of nodes on hosts db1, db2, and db3.
info
Read more about the replication mechanism in the official documentation: https://www.mongodb.com/docs/manual/replication/
- Add a new parameter with the replica name to the configuration file [db1, db2, db3]:
replication:
replSetName: rs0
Example full configuration file for db1:
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
wiredTiger:
engineConfig:
directoryForIndexes: true
replication:
replSetName: rs0
systemLog:
destination: file
logAppend: true
logRotate: reopen
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: "127.0.0.1,db1"
- After restarting MongoDB, connect to the database via MongoDB Shell and initialize the replica [db1]:
tip
Make sure that the instance you are connecting to has the Primary status.
> rs.initiate({
_id: "rs0",
version: 1,
members: [
{
_id: 0,
host: "db1:27017"
},
{
_id: 1,
host: "db2:27017"
},
{
_id: 2,
host: "db3:27017"
}
]
});
- Check the replication status [db1]:
rs0: PRIMARY > rs.status();
- Update the connection parameters in main.json configuration [app1, app2]:
{
"MONGO_AUTH_DB": "admin",
"CONTROLDB_NAME": "control",
"CONTROLDB_USER": "altcraft",
"CONTROLDB_PASS": "abcdefghijklmnopqrstuvwxyzABCDEF",
"CONTROLDB_REPL_SET_NAME": "rs0",
"CONTROLDB": [
{
"IP": "db1",
"PORT": 27017
},
{
"IP": "db2",
"PORT": 27017
},
{
"IP": "db3",
"PORT": 27017
}
],
"FILEDB_ENABLE": true,
"FILEDB_NAME": "filedb",
"FILEDB_USER": "altcraft",
"FILEDB_PASS": "abcdefghijklmnopqrstuvwxyzABCDEF",
"FILEDB_REPL_SET_NAME": "rs0",
"FILEDB": [
{
"IP": "db1",
"PORT": 27017
},
{
"IP": "db2",
"PORT": 27017
},
{
"IP": "db3",
"PORT": 27017
}
]
}