Introduction
This tutorial will show how to install the Percona XtraDB Cluster on three Ubuntu 16.04 LTS servers, using the packages from the official Percona repositories. After this tutorial you should be able to install, configure and secure a high available MySQL cluster.
Prerequisites
To follow this tutorial you need 3 machines running Ubuntu 16.04. All machines need to be reachable over SSH and they need to be in the same network.
| |
Configuring the repositories
To install Percona XtraDB you will have to add the appropriate repositories to your servers. Run the following commands on the three nodes.
| |
Configure Apparmor & SElinux
In order to successfully start Percona XtraDB, it is advised to disable SElinux. When SElinux is enabled the communication between nodes does not work and the nodes won’t be able to join the cluster successfully. By default SElinux is not enabled in Ubuntu, if you have installed it previously there are some options for disabling it. To test if SElinux is enabled on your system run the following command.
| |
If SElinux is enabled you can completely remove it from your system by uninstalling it
| |
Or you can disable it by editing the config file for SElinux.
| |
Percona doesn’t provide any AppArmor profile for PXC, but it seems that on this server (Ubuntu TLS), a previous version of MySQL was installed and then removed but the AppArmor profile was still present. So if you use apparmor (or if you don’t know) and you want to check is there is a profile for mysql, you can run the following command :
| |
If a mysql profile is available you can disable it like this.
| |
If SElinux is enabled you can completely remove it from your system by uninstalling it
Remember to check all your nodes, it prevents a lot of issues later on.
Configure your firewall
Percona XtraDB uses some ports asside from the standard 3306. You need to open these ports on your firewall for the cluster to function well.
MySQL: 3306
Cluster Communication: 4567
SST: 4568
The main cluster communication happens over port 4567. You can change this by specifying this option.
| |
Configure the bootstrap node
Go to your first node and open /etc/mysql/my.cnf and copy the following configuration at the end of the file and change the IP’s on line 2 and 6 to your configuration.
| |
The first node is ready to be started. Execute the following command to bootsrap the cluster.
| |
Now we have to check if the first node has started successfully.
| |
As you can see the first node started successfully and it is ready to accept other nodes to join the cluster. Now we have to configure a user to make use of State Snapshot Transfer. Change the username and password to the values you chose for wsrep_sst_auth in /etc/mysql/my.conf.
| |
State Snapshot Transfer (SST) is a full data copy from one node (donor) to the joining node (joiner). It’s used when a new node joins the cluster. In order to be synchronized with the cluster, the new node has to receive data from a node that is already part of the cluster.
Configure the two other nodes
Edit /etc/mysql/my.cnf on the two other nodes. Remember to change the IP of the host on line 6.
| |
Then start MySQL on the nodes.
| |
If everything went right, you can check the cluster status to check if all nodes are connected and the cluster is in a good state.
| |
Conclusion
Setting up a Percona XtraDB cluster is relatively easy. There are however some things that could go wrong. 90% of the time it has something to do with SElinux. A whole other beast is when your cluster dies, there are a lot of scenario’s that could break the cluster. I will get more in depth in a later article.
TIP: In case of any errors look for the file /var/lib/mysql/mysqlxx.err this file has saved me in a lot of situations when troubleshooting MySQL.