Database Replica Set Administration
Contents
Introduction
This is the guide for the first time configuration of a MongoDB Replica Set following installation.
Prerequisites
Installation of MongoDB on a primary and two secondaries. During installation the replica database options must have been selected for each server. See Installing the Software for more information.
MongoDB Shell or Studio 3T installed on the primary database system or a system that has network access to the primary database server.
Given the reduced resilience and potential performance issues associated with the PSA architecture when in a failure state, it is strongly recommended that database resilience is implemented with a minimum of 3 full database servers.
Create the Replica Set
When the database servers are installed in Replica Set mode they are configured for replication but without any information about the other member servers. This needs to be provided using the MongoDB replica set Initiate command. The command can be used to configure all member details in a single step. Use the command to apply the required settings for your architecture.
Primary and Two Secondaries
The example below configures a three server architecture. You need to adjust the IP addresses and ports in the member list to match your setup.
rs.initiate({_id:'ClearWay', members:[
{_id:0,host:'10.127.1.62:27010'},
{_id:1,host:'10.127.1.63:27010'},
{_id:2,host:'10.127.1.64:27010'}
]})The initial _id field is the replica set name. This defaults to either ClearWay or AdvanceGuard depending on the product you are using.
The members list contains an entry for each server. Each entry must include a numeric id, IP address and port. Ensure you enter your own server details.
You can use host names in place of IP addresses but only if the servers are part of a network that has full DNS support. If you are unsure about the DNS setup then use IP addresses.
Using MongoDB Shell
On the primary database, navigate to the folder where the mongosh.exe saved and open a cmd (or Powershell):
To connect to the database enter the command mongosh --host <remote-ip-or-hostname> --port 27010 (leave --host out if its on the same VM):
Run the command rs.conf() - this should show only one IP address within members:
Once you are connected ensure that the replica set has been initialized by using the rs. initiate() command and press Enter:
You can check the status using the rs. status() command:
rs.status()
Reconfigure a Replica Set
Once initialised a replica set cannot be initialised again. To change the configuration you must use the replica set reconfig command. The syntax for the command is the same as the initialise command.
To review the existing config you can use the replica set conf command:
rs.conf()The returned config can be modified and used in the reconfig command, however be aware that the conf command returns a complete configuration and contains more properties then you will need to change. However, you can still reconfigure the replica set using a simple member list as illustrated below:
rs.reconfig({_id:'ClearWay', members:[
{_id:0,host:'10.127.1.6427010'},
{_id:1,host:'10.127.1.65:27010'},
{_id:2,host:'10.127.1.68:27010'}
]})This command can be used for:
Swapping IPs and host names
Changing port numbers
Adding and removing members
Notes
You can only add or remove one member at a time when using the reconfig command.
If you attempt to apply a configuration that will change the write concern then it will fail. The global write concern settings will need to be adjusted before applying the configuration.