PingIntelligence

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

  1. Install the MongoDB replica set on RHEL 8 instances.

    1. Create RHEL 8 new instances.

    2. To create the MongoDB directory structure, create the following directories on each MongoDB node: mongo, data, logs, and key

      mkdir -p /opt/pingidentity/mongo/data /opt/pingidentity/mongo/logs \ /opt/pingidentity/mongo/key
    3. 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
    4. Update the shell path variable and reload the shell:

      /opt/pingidentity# echo PATH=$PATH:/opt/pingidentity/mongo/bin >> ~/.bashrc
      /opt/pingidentity# source ~/.bashrc
    5. Copy the mongo-keyfile and mongodb.pem files from the primary mongo and copy the files to the new mongo RHEL 8 instance key folder: /opt/pingidentity/mongo/key.

    6. Optional: Copy the abs_init.js and abs_rs.js files from RHEL 7.9 mongo to RHEL 8 primary mongo.

    7. Change the key file permissions.

      /opt/pingidentity/mongo# chmod 600 key/mongodb-keyfile
    8. Start mongo with TLS mode enabled using the same mode as the existing RHEL 7.9 mongo 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
  2. Add the newly created RHEL 8 mongo instances to the existing RHEL 7.9 mongo replica set.

    1. Add the newly created mongo instances as a new replica set member to the existing RHEL 7.9 mongo setup using the following command in the RHEL 7.9 primary mongo shell:

      rs.add( { host: “new_mongo_IP_1:27017" } )
      rs.add( { host: “new_mongo_IP_2:27017" } )
    2. 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 to SECONDARY.

    3. Set one of the newly created members as primary by executing the shell commands from the existing RHEL 7.9 primary mongo.

      1. Copy the replica set configuration to a variable:

        cfg = rs.conf()
      2. 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], and members[2] are RHEL 7.9 mongo instances, and members[3], members[4], and members[5] are newly added RHEL 8 mongo instances.

      3. Assign the new config to the replica set:

        rs.reconfig(cfg)
      4. Check the current status using the rs.status() command. Make sure one of the newly added RHEL 8 mongo instance is PRIMARY, and the rest are all SECONDARY.

  3. Remove the RHEL 7.9 mongo members from the replica set.

    1. 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")
    2. Check the current status using the rs.status() command.

      Result:

    It should show only the RHEL 8 mongo members (one among them should be PRIMARY).

    1. Change ABS and API Publish configurations to point to the new replica set (RHEL 8).

    2. Shut down the RHEL 7.9 mongo instances.

Next steps