﻿---
path: faq/repl-set-mongo/update/centos-8.mdx
title: Upgrading a MongoDB replica set to 7.x on CentOS 8
slug: centos-8
pagination_next: null
pagination_prev: faq/repl-set-mongo/update/intro
description: >-
  Step-by-step upgrade of a MongoDB replica set on CentOS 8 from version 4.2
  to 7.0.x through the intermediate versions 4.4, 5.0.x, and 6.0.x.
keywords:
  - Passwork
  - MongoDB
  - Replica Set
  - CentOS 8
  - upgrade
  - rolling update
  - featureCompatibilityVersion
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

## Preparation

- [Create a backup of the MongoDB databases](/databases/mongodb/backup-creation-and-restoration-examples)
- 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:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
mongod --version
```

  </TabItem>
</Tabs>


:::danger
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**.
:::

:::warning
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

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

Create the repository file for MongoDB 4.4:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
nano /etc/yum.repos.d/mongodb-4.4.repo
```

  </TabItem>
</Tabs>


Insert the contents:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
```

  </TabItem>
</Tabs>


### Upgrading the MongoDB nodes

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

Stop the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl stop mongod.service
```

  </TabItem>
</Tabs>


Upgrade MongoDB to version 4.4:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
dnf upgrade mongodb-org-tools mongodb-org-shell mongodb-org-server mongodb-org-database-tools-extra mongodb-org-database mongodb-org -y
```

  </TabItem>
</Tabs>

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

Start the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl start mongod.service
```

  </TabItem>
</Tabs>


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

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


### Changing the compatibility parameter

:::warning
`featureCompatibilityVersion` must be changed **after all MongoDB instances have been upgraded**.
:::

Connect to the MongoDB shell (replica set):

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


Update the `featureCompatibilityVersion` parameter:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


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

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

Create the repository file for MongoDB 5.0.x:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
nano /etc/yum.repos.d/mongodb-5.0.repo
```

  </TabItem>
</Tabs>


Add the contents:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-5.0.asc
```

  </TabItem>
</Tabs>


### Upgrading the MongoDB nodes

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

Stop the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl stop mongod.service
```

  </TabItem>
</Tabs>


Upgrade MongoDB to version 5.0.x:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
dnf upgrade mongodb-org-tools mongodb-org-shell mongodb-org-server mongodb-org-database-tools-extra mongodb-org-database mongodb-org -y
```

  </TabItem>
</Tabs>

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

Start the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl start mongod.service
```

  </TabItem>
</Tabs>


Check the state of the replica set:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


### Changing the compatibility parameter

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

Connect to the MongoDB shell:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


Update `featureCompatibilityVersion`:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


Open the Passwork web interface and check that it works.

## Upgrading the MongoDB replica set to version 6.0.x

### Adding the MongoDB repository

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

Create the repository file for MongoDB 6.0.x:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
nano /etc/yum.repos.d/mongodb-6.0.repo
```

  </TabItem>
</Tabs>


Add the contents:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-6.0.asc
```

  </TabItem>
</Tabs>


### Upgrading the MongoDB nodes

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

Stop the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl stop mongod.service
```

  </TabItem>
</Tabs>


Upgrade MongoDB to version 6.0.x:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
dnf upgrade mongodb-org-tools mongodb-org-shell mongodb-org-server mongodb-org-database-tools-extra mongodb-org-database mongodb-org -y
```

  </TabItem>
</Tabs>

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

Start the MongoDB service:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

```shell
systemctl start mongod.service
```

  </TabItem>
</Tabs>


Check the state of the replica set:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


### Changing the compatibility parameter

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

Connect to the MongoDB shell:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


Update `featureCompatibilityVersion`:

<Tabs className="tabs-container">
  <TabItem className="tab-item-container" value="shell" label="shell">

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

  </TabItem>
</Tabs>


Open the Passwork web interface and check that it works.
