Saltar al contenido principal

Upgrading a MongoDB replica set to 7.x on Ubuntu 22.04

Preparation

  • Create a backup of the MongoDB databases
  • Make a copy of the /etc/mongod.conf configuration file.
  • If Passwork is installed on a virtual server, we recommend taking snapshots of the operating systems before performing the upgrade.
  • Make sure the server has access to the MongoDB repositories.

The example uses three servers configured for data replication:

  1. example-mongo-01 (PRIMARY)
  2. example-mongo-02 (SECONDARY)
  3. example-mongo-03 (SECONDARY)

Checking the current version

Check the MongoDB version in use:

mongod --version
peligro

If the MongoDB version is 4.2, you first need to upgrade to 4.4, because migration to MongoDB 5.0 is only available from version 4.4.

aviso

If the current MongoDB version is already 4.4, go straight to the Upgrading the MongoDB replica set to version 5.0.x section.

Upgrading the MongoDB replica set to version 4.4

Adding the MongoDB repository

peligro

The steps in this section must be performed on all servers of the replica set.

Download the key and add the repository to the local OS store:

curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

Update the list of available packages:

apt update

Upgrading the MongoDB nodes

peligro

The upgrade must be performed one instance at a time across the replica set.

Stop the MongoDB service:

systemctl stop mongod.service

Upgrade MongoDB to version 4.4:

apt upgrade mongodb-org -y
peligro

Do not update the MongoDB configuration file /etc/mongod.conf — keep the current version (N when prompted to replace it).

If an error occurs during the process, run:

apt --fix-broken install

Start the MongoDB service:

systemctl start mongod.service

Connect to the replica set and check the state of the nodes:

mongo --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017
rs.status()

Changing the compatibility parameter

aviso

featureCompatibilityVersion must be changed after all MongoDB instances have been upgraded.

Connect to the MongoDB shell (replica set):

mongo --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017

Update the featureCompatibilityVersion parameter:

db.adminCommand({ setFeatureCompatibilityVersion: "4.4" })

Open the Passwork web interface and make sure everything works correctly.

Upgrading the MongoDB replica set to version 5.0.x

Adding the MongoDB repository

peligro

The steps in this section must be performed on all servers of the replica set.

Download the key and add the repository:

curl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-5.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-5.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Update the package list:

apt update

Upgrading the MongoDB nodes

peligro

The steps are performed one at a time on each node of the replica set.

Stop the MongoDB service:

systemctl stop mongod.service

Upgrade MongoDB to version 5.0.x:

apt upgrade mongodb-org -y
peligro

Do not update the MongoDB configuration file /etc/mongod.conf — keep the current version (N when prompted to replace it).

Start the MongoDB service:

systemctl start mongod.service

Check the state of the replica set:

mongo --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017
rs.status()

Changing the compatibility parameter

aviso

Perform this after all nodes have been upgraded to version 5.0.x.

Connect to the MongoDB shell:

mongo --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017

Update featureCompatibilityVersion:

db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })

Open the Passwork web interface and check that it works.

Upgrading the MongoDB replica set to version 6.0.x

Adding the MongoDB repository

peligro

The steps in this section are performed on all servers of the replica set.

Download the key and add the repository:

curl -fsSL https://www.mongodb.org/static/pgp/server-6.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Update the package list:

apt update

Upgrading the MongoDB nodes

peligro

Perform the upgrade one node at a time across the replica set.

Stop the MongoDB service:

systemctl stop mongod.service

Upgrade MongoDB to version 6.0.x:

apt upgrade mongodb-org -y
peligro

Do not update the MongoDB configuration file /etc/mongod.conf — keep the current version (N when prompted to replace it).

Start the MongoDB service:

systemctl start mongod.service

Check the state of the replica set:

mongosh --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017
rs.status()

Changing the compatibility parameter

aviso

Perform this after all nodes have been upgraded to version 6.0.x.

Connect to the MongoDB shell:

mongosh --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017

Update featureCompatibilityVersion:

db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })

Open the Passwork web interface and check that it works.

Upgrading the MongoDB replica set to version 7.0.x

Adding the MongoDB repository

peligro

The steps are performed on all servers of the replica set.

Download the key and add the repository:

curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Update the package list:

apt update

Upgrading the MongoDB nodes

peligro

The upgrade is performed sequentially on each node of the replica set.

Stop the MongoDB service:

systemctl stop mongod.service

Upgrade MongoDB to version 7.0.x:

apt upgrade mongodb-org -y
peligro

Do not update the MongoDB configuration file /etc/mongod.conf — keep the current version (N when prompted to replace it).

Start the MongoDB service:

systemctl start mongod.service

Check the state of the replica set:

mongosh --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017
rs.status()

Changing the compatibility parameter

aviso

Only change featureCompatibilityVersion after all nodes have been upgraded to 7.0.x.

Connect to the MongoDB shell:

mongosh --host rs0/example-mongo-01:27017,example-mongo-02:27017,example-mongo-03:27017

Update featureCompatibilityVersion:

db.adminCommand({ setFeatureCompatibilityVersion: "7.0" })

Open the Passwork web interface and make sure Passwork works correctly with the upgraded MongoDB version.