Adding a member to an existing MongoDB replica set
You can add a new node to an existing MongoDB replica set.
Before you begin
You must have:
- 
An active replica set. 
- 
A new MongoDB system accessible by the replica set. 
- 
ClusterAdmin privileges. 
About this task
| 
 | 
To add a node to an existing replica set:
Steps
- 
Create the MongoDB directory structure on the new MongoDB node: # mkdir -p /opt/pingidentity/mongo/data/opt/pingidentity/mongo/logs \ /opt/pingidentity/mongo/key 
- 
Download MongoDB 4.2 on the node and extract it to /opt/pingidentity/mongo:# cd /opt/pingidentity/ /opt/pingidentity# wget \ https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.0.tgz \ -O mongodb.tgz && tar xzf mongodb.tgz -C /opt/pingidentity/mongo/ --strip-components=1 
- 
Update the shell path variable and reload the shell: /opt/pingidentity# echo PATH=$PATH:/opt/pingidentity/mongo/bin >> ~/.bashrc; /opt/pingidentity# source ~/.bashrc 
- 
Copy the contents of the /opt/pingidentity/mongo/keydirectory from the primary node to the new node into/opt/pingidentity/mongo/key.
- 
Start the MongoDB database on the new node: /opt/pingidentity# cd mongo /opt/pingidentity/mongo# mongod --auth --dbpath ./data/ --logpath ./logs/mongo.log --port 27017 --replSet absrs01 --fork --keyFile ./key/mongodb-keyfile -bind_ip 0.0.0.0 
- 
Connect to the mongoshell of the primary node and run the following command:absrs01:PRIMARY> rs.add({"host": "<IP address of new node>:27017", "priority": 2})Result:The state of the new node changes to STARTUP2. This indicates that the synchronization between the replica set and the new node has started.
- 
Verify that the new node is added as a secondary node to the replica set using the following command: absrs01:PRIMARY> rs.status() 
Next steps
For more information, see https://docs.mongodb.com/manual/tutorial/expand-replica-set/.