icon

MongoDB (Replica Set)

The high-availability MongoDB replica set deployment template.

template cover
Deployed98 times
Publisherpan93412
Created2024-08-22
Services
service icon
Tags
Database

MongoDB is an open source NoSQL database management program. NoSQL (Not only SQL) is used as an alternative to traditional relational databases. NoSQL databases are quite useful for working with large sets of distributed data. MongoDB is a tool that can manage document-oriented information, store or retrieve information.

MongoDB is used for high-volume data storage, helping organizations store large amounts of data while still performing rapidly. Organizations also use MongoDB for its ad-hoc queries, indexing, load balancing, aggregation, server-side JavaScript execution and other features.

Deployment

After the deployment, follow the steps to complete your ReplicaSet:

First, edit the "replSetName" in "/etc/mongo/mongod.conf" to your real replica set name. For more information, check this documentation.

Then, regenerate the key in the "/etc/mongo-keyfile" in the Config Editor to your pasword. For more information, check this documentation.

You can generate a safe key with the following command:

openssl rand -base64 756

Finally, Run rs.initialize() in the "Terminal":

mongosh -u "${MONGO_USERNAME}" -p "${MONGO_PASSWORD}"

and then run the following command to initialize the replica set:

rs.initiate({
    _id: "rs0",
    members: [
        { _id: 0, host: "<public-ip-1>:<port-1>" },
        { _id: 1, host: "<public-ip-2>:<port-2>" },
        { _id: 2, host: "<public-ip-3>:<port-3>" },
    ]
})

Note that the rs0 should be changed to the replSetName you set if you have changed it in mongod.conf.