Percona XtraDB Cluster
Percona XtraDB Cluster
Examples:
| Node | Host | IP |
|---|---|---|
| Node 1 | node1.localhost | 192.168.184.161 |
| Node 2 | node2.localhost | 192.168.184.162 |
| Node 3 | node3.localhost | 192.168.184.163 |
Prerequisites
Make sure that the following ports are not blocked by firewall or used by other software. Percona XtraDB
Cluster requires them for communication.
• 3306
• 4444
• 4567
• 4568
The SELinux security module can constrain access to data for Percona XtraDB Cluster. The best solution is to
change the mode from enforcing to permissive by running the following command:
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
Installing from Percona Repository
-
Configure Percona repositories
sudo yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm
sudo percona-release setup <PRODUCT> -
Install the Percona XtraDB Cluster packages
sudo yum install Percona-XtraDB-Cluster-57
-
Start the Percona XtraDB Cluster server
sudo systemctl start mysql
-
Copy the automatically generated temporary password for the superuser account
sudo grep 'temporary password' /var/log/mysqld.log
-
Use this password to log in as root
mysql -uroot -p
-
Change the password for the superuser account and log out. For example
ALTER USER 'root'@'localhost' IDENTIFIED BY 'welcome';
-
Stop the mysql service
sudo systemctl stop mysql
CONFIGURING NODES FOR WRITE-SET REPLICATION
If you are running Red Hat or CentOS, modify the following configuration variables to /etc/percona-xtradb-cluster.conf.d/wsrep.cnf on the first node:
[mysqld] |
Use the same configuration for the second and third nodes, except the wsrep_node_name and wsrep_node_address variables:
-
For the second node:
wsrep_node_name=pxc2
wsrep_node_address=192.168.184.162 -
For the third node:
wsrep_node_name=pxc3
wsrep_node_address=192.168.184.163
Modify the following configuration variables to /etc/percona-xtradb-cluster.conf.d/mysqld.cnf on the all nodes.
[client] |
BOOTSTRAPPING THE FIRST NODE
Start the first node with the following command on RedHat or CentOS:
[root@node1 ~]# systemctl start mysql@bootstrap.service |
To make sure that the cluster has been initialized, run the following:
mysql@node1> show status like 'wsrep%'; |
Create a user for SST and provide the necessary privileges for that user account:
mysql@node1> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd'; |
Starting the Second Node
Start the second node by using either of the following commands:
[root@node2 ~]# systemctl start mysql |
After the server starts, it should receive SST automatically.
To check the status of the second node, run the following:
mysql@node2> show status like 'wsrep%'; |
Starting the Third Node
Start the second node by using either of the following commands:
[root@node3 ~]# systemctl start mysql |
After the server starts, it should receive SST automatically.
To check the status of the second node, run the following:
mysql@node3> show status like 'wsrep%'; |
VERIFYING REPLICATION
Use the following procedure to verify replication by creating a new database on the second node, creating a table for that database on the third node, and adding some records to the table on the first node.
-
Create a new database on the second node:
mysql@node2> CREATE DATABASE percona;
Query OK, 1 row affected (0.01 sec) -
Create a table on the third node:
mysql@node3> USE percona;
Database changed
mysql@node3> CREATE TABLE example (node_id INT PRIMARY KEY, node_name VARCHAR(30));
Query OK, 0 rows affected (0.05 sec) -
Insert records on the first node:
mysql@node1> INSERT INTO percona.example VALUES (1, 'percona1');
Query OK, 1 row affected (0.02 sec) -
Retrieve rows from that table on the second node:
mysql@pxc2> SELECT * FROM percona.example;
+---------+-----------+
| node_id | node_name |
+---------+-----------+
| 1 | percona1 |
+---------+-----------+
1 row in set (0.00 sec)