Configure a replica set for MongoDB
Rocket.Chat uses the MongoDB replica set to improve performance via Meteor Oplog tailing.
Note please check release notes to ensure you are using a compatible version of Mongo
To configure the replica set add this section into mongod.conf:
1
replication:
2
replSetName: "rs01"
Copied!
for example by running this command:
1
echo -e "replication:\n replSetName: \"rs01\"" | sudo tee -a /etc/mongod.conf
Copied!

Restart MongoDB and initiate the replica set

Restart MongoDB service:
1
sudo systemctl restart mongod
Copied!
Start the MongoDB shell and initiate the replica set:
1
mongo
2
> rs.initiate()
Copied!
The output of the command should look like this:
1
{
2
"info2" : "no configuration specified. Using a default configuration for the set",
3
"me" : "127.0.0.1:27017",
4
"ok" : 1,
5
"operationTime" : Timestamp(1538772048, 1),
6
"$clusterTime" : {
7
"clusterTime" : Timestamp(1538772048, 1),
8
"signature" : {
9
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
10
"keyId" : NumberLong(0)
11
}
12
}
13
}
14
rs01:SECONDARY>
Copied!
Note 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:
1
rs01:PRIMARY> exit
2
bye
Copied!
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:
[conn1] created this configuration for initiation : { _id: "rs0", version: 1, members: [ { _id: 0, host: "test:27017" } ] }
rs.initiate() may be defaulting to the host name e.g. 'test'
You can force a different hostname as follows:
1
rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: 'localhost:27017' } ]})
Copied!
You should get a response similar to:
1
> rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: 'localhost:27017' } ]})
2
{ "ok" : 1 }
3
rs0:OTHER>
Copied!

Reconfigure and restart Rocket.Chat service

After you configured replica set, you MUST add the MONGO_OPLOG_URL environment variable to the service definition and restart Rocket.Chat server.
In CentOS open file /usr/lib/systemd/system/rocketchat.service
In Ubuntu or Debian open file /lib/systemd/system/rocketchat.service
and add this to the Environment line:
1
MONGO_OPLOG_URL=mongodb://localhost:27017/local?replSet=rs01
Copied!
Reload systemd state and restart Rocket.Chat:
1
sudo systemctl daemon-reload && sudo systemctl restart rocketchat
Copied!
Last modified 1yr ago