Migrating MongoDB from RHEL 7.9 to 8
After upgrading MongoDB, migrate MongoDB from RHEL 7.9 to RHEL 8.
Before you begin
Make sure to configure the primary and secondary as a replica set in RHEL 7.9 and that the version is 5.0.18.
About this task
To migrate MongoDB from RHEL 7.9 to RHEL 8:
Steps
-
Install the MongoDB replica set on RHEL 8 instances.
-
Create RHEL 8 new instances.
-
To create the MongoDB directory structure, create the following directories on each MongoDB node:
mongo,data,logs, andkeymkdir -p /opt/pingidentity/mongo/data /opt/pingidentity/mongo/logs \ /opt/pingidentity/mongo/key
-
Download MongoDB 5.0.18 on each node and extract it:
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
mongo-keyfileandmongodb.pemfiles from the primarymongoand copy the files to the newmongoRHEL 8 instance key folder:/opt/pingidentity/mongo/key. -
Optional: Copy the
abs_init.jsandabs_rs.jsfiles from RHEL 7.9mongoto RHEL 8 primarymongo. -
Change the key file permissions.
/opt/pingidentity/mongo# chmod 600 key/mongodb-keyfile
-
Start
mongowith TLS mode enabled using the same mode as the existing RHEL 7.9mongomembers.mongod --auth --dbpath ./data/ --logpath ./logs/mongo.log --port 27017 --replSet absrs01 --fork --keyFile ./key/mongodb-keyfile -bind_ip 0.0.0.0 --tlsMode requireTLS --tlsCertificateKeyFile ./key/mongodb.pem
-
-
Add the newly created RHEL 8
mongoinstances to the existing RHEL 7.9mongoreplica set.-
Add the newly created
mongoinstances as a new replica set member to the existing RHEL 7.9mongosetup using the following command in the RHEL 7.9 primarymongoshell:rs.add( { host: “new_mongo_IP_1:27017" } )rs.add( { host: “new_mongo_IP_2:27017" } ) -
Check the replica set members status by running the status command in primary
mongo:rs.status()
Result:
The initial status of the newly added replica members is
STARTUP2. Once the initial sync completes, the newly added member’s state changes toSECONDARY. -
Set one of the newly created members as primary by executing the shell commands from the existing RHEL 7.9 primary
mongo.-
Copy the replica set configuration to a variable:
cfg = rs.conf()
-
Change each member’s priority value based on which member you want as a
PRIMARYand give highest priority to the node you want to set as a primary node.cfg.members[0].priority = 1 cfg.members[1].priority = 1 cfg.members[2].priority = 1 cfg.members[3].priority = 100 cfg.members[4].priority = 100 cfg.members[5].priority = 100
In the commands above,
members[0],members[1], andmembers[2]are RHEL 7.9mongoinstances, andmembers[3],members[4], andmembers[5]are newly added RHEL 8mongoinstances. -
Assign the new
configto the replica set:rs.reconfig(cfg)
-
Check the current status using the
rs.status()command. Make sure one of the newly added RHEL 8mongoinstance isPRIMARY, and the rest are allSECONDARY.
-
-
-
Remove the RHEL 7.9
mongomembers from the replica set.-
Run the following command from the current RHEL 8 primary
mongo:rs.remove("RHEL79_mongo_IP_1:27017") rs.remove("RHEL79_mongo_IP_2:27017") -
Check the current status using the
rs.status()command.Result:
It should show only the RHEL 8
mongomembers (one among them should bePRIMARY).-
Change ABS and API Publish configurations to point to the new replica set (RHEL 8).
-
Shut down the RHEL 7.9
mongoinstances.
-
Next steps
Complete the steps in Migrating Elasticsearch from RHEL 7.9 to 8.