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
, andkey
mkdir -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-keyfile
andmongodb.pem
files from the primarymongo
and copy the files to the newmongo
RHEL 8 instance key folder:/opt/pingidentity/mongo/key
. -
Optional: Copy the
abs_init.js
andabs_rs.js
files from RHEL 7.9mongo
to RHEL 8 primarymongo
. -
Change the key file permissions.
/opt/pingidentity/mongo# chmod 600 key/mongodb-keyfile
-
Start
mongo
with TLS mode enabled using the same mode as the existing RHEL 7.9mongo
members.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
mongo
instances to the existing RHEL 7.9mongo
replica set.-
Add the newly created
mongo
instances as a new replica set member to the existing RHEL 7.9mongo
setup using the following command in the RHEL 7.9 primarymongo
shell: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
PRIMARY
and 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.9mongo
instances, andmembers[3]
,members[4]
, andmembers[5]
are newly added RHEL 8mongo
instances. -
Assign the new
config
to the replica set:rs.reconfig(cfg)
-
Check the current status using the
rs.status()
command. Make sure one of the newly added RHEL 8mongo
instance isPRIMARY
, and the rest are allSECONDARY
.
-
-
-
Remove the RHEL 7.9
mongo
members 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
mongo
members (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
mongo
instances.
-
Next steps
Complete the steps in Migrating Elasticsearch from RHEL 7.9 to 8.