> For the complete documentation index, see [llms.txt](https://docs.percona.com/percona-xtradb-cluster/8.4/llms.txt).

# Configure a cluster on Red Hat-based distributions

This tutorial describes how to install and configure three Percona XtraDB Cluster nodes on Red Hat Enterprise Linux (RHEL) 8 servers, using the packages from Percona repositories.

- Node 1

  - Host name: `percona1`
  - IP address: `192.168.70.71`

- Node 2

  - Host name: `percona2`
  - IP address: `192.168.70.72`

- Node 3

  - Host name: `percona3`
  - IP address: `192.168.70.73`

## Prerequisites

The procedure described in this tutorial requires the following:

- All three nodes have Red Hat Enterprise Linux 8 installed.
- The firewall on all nodes is configured to allow connecting to ports 3306, 4444, 4567 and 4568.
- SELinux on all nodes is disabled.

Percona XtraDB Cluster 8.4 creates the internal MySQL account [`mysql.pxc.internal.session`](https://docs.percona.com/percona-xtradb-cluster/8.4/glossary.md#mysqlpxcinternalsession), which the SST process uses to run the SQL needed for node synchronization.

During [SST](https://docs.percona.com/percona-xtradb-cluster/8.4/glossary.md#sst), that account creates the user `mysql.pxc.sst.user` on the donor node and assigns it the role [`mysql.pxc.sst.role`](https://docs.percona.com/percona-xtradb-cluster/8.4/glossary.md#mysqlpxcsstrole).

## Step 1. Install

Install Percona XtraDB Cluster on all three nodes as described in [Install on Red Hat Enterprise Linux](https://docs.percona.com/percona-xtradb-cluster/8.4/yum.md#install-from-percona-software-repository).

## Step 2. Configure the first node

Individual nodes should be configured to be able to bootstrap the cluster. For more information about bootstrapping the cluster, see [Bootstrapping the First Node](https://docs.percona.com/percona-xtradb-cluster/8.4/bootstrap.md#bootstrap-the-first-node).

1. Make sure that the configuration file `/etc/my.cnf` on the first node (`percona1`) contains the following:

   ```text
   [mysqld]
   datadir=/var/lib/mysql
   user=mysql
   # Path to Galera library
   wsrep_provider=/usr/lib64/galera4/libgalera_smm.so
   # Cluster connection URL contains the IPs of node#1, node#2 and node#3
   wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
   # Using the MyISAM storage engine is not recommended.
   default_storage_engine=InnoDB
   # This InnoDB autoincrement locking mode is a requirement for Galera
   innodb_autoinc_lock_mode=2
   # Node 1 address
   wsrep_node_address=192.168.70.71
   # SST method
   wsrep_sst_method=xtrabackup-v2
   # Cluster name
   wsrep_cluster_name=my_rhel_cluster
   ```

1. Start the first node, `[root@percona1 ~] #`, with the following command:

   ```shell
   systemctl start mysql@bootstrap.service
   ```

   The previous command will start the cluster with initial [`wsrep_cluster_address`](https://docs.percona.com/percona-xtradb-cluster/8.4/wsrep-system-index.md#wsrep_cluster_address) variable set to `gcomm://`. If the node or MySQL are restarted later, there will be no need to change the configuration file.

1. After the first node has been started, cluster status can be checked with the following command:

   ```sql
   show status like 'wsrep%';
   ```

   This output shows that the cluster has been successfully bootstrapped.

   Expected output

   ```text
   +----------------------------+--------------------------------------+
   | Variable_name              | Value                                |
   +----------------------------+--------------------------------------+
   | wsrep_local_state_uuid     | c2883338-834d-11e2-0800-03c9c68e41ec |
   ...
   | wsrep_local_state          | 4                                    |
   | wsrep_local_state_comment  | Synced                               |
   ...
   | wsrep_cluster_size         | 1                                    |
   | wsrep_cluster_status       | Primary                              |
   | wsrep_connected            | ON                                   |
   ...
   | wsrep_ready                | ON                                   |
   +----------------------------+--------------------------------------+
   75 rows in set (0.00 sec)
   ```

   Copy the automatically generated temporary password for the superuser account:

   ```shell
   sudo grep 'temporary password' /var/log/mysqld.log
   ```

   Expected output

   ```text
   [Note] A temporary password is generated for root@localhost: xYz123AbC
   ```

   Use this password to log in as root:

   ```shell
   mysql -u root -p
   ```

   Change the password for the superuser account and log out. For example:

   ```shell
   ALTER USER 'root'@'localhost' IDENTIFIED BY 'r00tP@$$';
   ```

   Expected output

   ```text
   Query OK, 0 rows affected (0.00 sec)
   ```

   Exit the MySQL client:

   ```sql
   EXIT
   ```

   Expected output

   ```text
   Bye
   ```

## Step 3. Configure the second node

1. Make sure that the configuration file `/etc/my.cnf` on the second node (`percona2`) contains the following:

   ```text
   [mysqld]
   datadir=/var/lib/mysql
   user=mysql
   # Path to Galera library
   wsrep_provider=/usr/lib64/galera4/libgalera_smm.so
   # Cluster connection URL contains IPs of node#1, node#2 and node#3
   wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
   # Using the MyISAM storage engine is not recommended
   default_storage_engine=InnoDB
   # This InnoDB auto_increment locking mode is a requirement for Galera
   innodb_autoinc_lock_mode=2
   # Node 2 address
   wsrep_node_address=192.168.70.72
   # Cluster name
   wsrep_cluster_name=my_rhel_cluster
   # SST method
   wsrep_sst_method=xtrabackup-v2
   ```

1. Start the second node, `[root@percona2 ~] #`, with the following command:

   ```shell
   systemctl start mysql
   ```

1. After the server has been started, it should receive SST automatically. Cluster status can be checked on both nodes. The following is an example of status from the second node (`percona2`):

   ```sql
   show status like 'wsrep%';
   ```

   The output shows that the new node has been successfully added to the cluster.

   Expected output

   ```text
   +----------------------------+--------------------------------------+
   | Variable_name              | Value                                |
   +----------------------------+--------------------------------------+
   | wsrep_local_state_uuid     | c2883338-834d-11e2-0800-03c9c68e41ec |
   ...
   | wsrep_local_state          | 4                                    |
   | wsrep_local_state_comment  | Synced                               |
   ...
   | wsrep_cluster_size         | 2                                    |
   | wsrep_cluster_status       | Primary                              |
   | wsrep_connected            | ON                                   |
   ...
   | wsrep_ready                | ON                                   |
   +----------------------------+--------------------------------------+
   40 rows in set (0.01 sec)
   ```

## Step 4. Configure the third node

1. Make sure that the MySQL configuration file `/etc/my.cnf` on the third node (`percona3`) contains the following:

   ```text
   [mysqld]
   datadir=/var/lib/mysql
   user=mysql
   # Path to Galera library
   wsrep_provider=/usr/lib64/galera4/libgalera_smm.so
   # Cluster connection URL contains IPs of node#1, node#2 and node#3
   wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
   # Using the MyISAM storage engine is not recommended
   default_storage_engine=InnoDB
   # This InnoDB auto_increment locking mode is a requirement for Galera
   innodb_autoinc_lock_mode=2
   # Node #3 address
   wsrep_node_address=192.168.70.73
   # Cluster name
   wsrep_cluster_name=my_rhel_cluster
   # SST method
   wsrep_sst_method=xtrabackup-v2
   ```

1. Start the third node, `[root@percona3 ~] #`, with the following command:

   ```shell
   systemctl start mysql
   ```

1. After the server has been started, it should receive SST automatically. Cluster status can be checked on all three nodes. The following is an example of status from the third node (`percona3`):

   ```sql
   show status like 'wsrep%';
   ```

   The output confirms that the third node has joined the cluster.

   Expected output

   ```text
   +----------------------------+--------------------------------------+
   | Variable_name              | Value                                |
   +----------------------------+--------------------------------------+
   | wsrep_local_state_uuid     | c2883338-834d-11e2-0800-03c9c68e41ec |
   ...
   | wsrep_local_state          | 4                                    |
   | wsrep_local_state_comment  | Synced                               |
   ...
   | wsrep_cluster_size         | 3                                    |
   | wsrep_cluster_status       | Primary                              |
   | wsrep_connected            | ON                                   |
   ...
   | wsrep_ready                | ON                                   |
   +----------------------------+--------------------------------------+
   40 rows in set (0.01 sec)
   ```

## Test replication

To test replication, lets create a new database on second node, create a table for that database on the third node, and add some records to the table on the first node.

1. Create a new database on the second node, `mysql@percona2>`:

   ```sql
   CREATE DATABASE percona;
   ```

   Expected output

   ```text
   Query OK, 1 row affected (0.01 sec)
   ```

1. Switch to a newly created database, `mysql@percona3>`:

   ```sql
   USE percona;
   ```

   The following output confirms that a database has been changed:

   Expected output

   ```text
   Database changed
   ```

1. Create a table on the third node, `mysql@percona3>`:

   ```sql
   CREATE TABLE example (node_id INT PRIMARY KEY, node_name VARCHAR(30));
   ```

   The following output confirms that a table has been created:

   Expected output

   ```text
   Query OK, 0 rows affected (0.05 sec)
   ```

1. Insert records on the first node, `mysql@percona1>`:

   ```sql
   INSERT INTO percona.example VALUES (1, 'percona1');
   ```

   The following output confirms that the records have been inserted:

   Expected output

   ```text
   Query OK, 1 row affected (0.02 sec)
   ```

1. Retrieve all the rows from that table on the second node, `mysql@percona2>`:

   ```sql
   SELECT * FROM percona.example;
   ```

   The following output confirms that all the rows have been retrieved:

   Expected output

   ```text
   +---------+-----------+
   | node_id | node_name |
   +---------+-----------+
   |       1 | percona1  |
   +---------+-----------+
   1 row in set (0.00 sec)
   ```

   This simple procedure should ensure that all nodes in the cluster are synchronized and working as intended.
