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, secondary, and arbiter (PSA) system or 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.
Robo3T 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. The arbiter should be avoided if possible.
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 Initialise 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, Secondary and Arbiter (PSA)
The example below configures a PSA 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', arbiterOnly:true}
]})
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.
Set the arbiterOnly attribute to true on the last server.
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. Note that the only difference is the use of the arbiterOnly option.
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.
Execute Commands using Robo3T
Start Robo3T.
Select Create, and enter the connection information of the primary database. By default, the database is configured to use port 27010.
Click Save and then Connect.
Once connected Right Click on the name you provided in the connection setup.
Select Open Shell:
In the shell window, enter or paste in the replica set initialise command with your configuration options as explained above and press Play:
Once the replica set has been initialised you can check the status using the replica set 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:
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:
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.
Related Information
-
Installing the Software (Witness 4.0)
-
Database Authentication (Witness 4.0)
-
Database Replica Set Administration (Witness 4.0)