Configure a Replica Set for MongoDB
Last updated
Last updated
Rocket.Chat uses the to improve performance via Meteor Oplog tailing. Replica sets are used to provide high data availability by maintaining multiple copies of the data across different servers.
To configure the replica set, add this section to the mongod.conf
file:
For example, run the following command to update the replication settings in the MongoDB configuration file:
Follow these steps to initiate the MongoDB replica set:
Restart MongoDB service:
Start the MongoDB shell and initiate the replica set:
The output of the command should look like this:
Note that the ok
value should be 1
. Any other value, i.e. 93, means something is wrong.
Hit enter, you should see your prompt turn into rs01:PRIMARY>
, this indicates the replica set is being used. Type exit
to get back to your regular shell:
Troubleshooting
Depending on your network settings, including /etc/hosts
and DNS, if you have configured Rocket.Chat to use localhost:27017
, you may see an error similar to this:
rs.initiate()
may be defaulting to the host name e.g., test
.
You can force a different hostname as follows:
You should get a response similar to the following:
After you configured the replica set, you must add the MONGO_OPLOG_URL
environment variable to the service definition and restart Rocket.Chat server.
In CentOS, open the file /usr/lib/systemd/system/rocketchat.service
In Ubuntu or Debian, open the file /lib/systemd/system/rocketchat.service
Add the following to the environment line:
Reload the system state and restart Rocket.Chat: