Running Percona XtraDB Cluster on Raspberry PI 3

Percona XtraDB Cluster on Raspberry PI 3In a previous post, I showed you how to compile Percona Mysql 5.7 on Raspberry PI 3. Now, I’ll show you how to compile and run the latest version of Percona XtraDB Cluster 5.7.26.

We will need at least 3 RaspberryPi 3 boards, and I recommend you use an external SSD drive to compile and use as MySQL’s “datadir” to avoid the stalls associated with the microSD card, which will cause PXC to run slow.

In this post, we are going to run many OS commands and configure PXC. I recommend having minimal knowledge about PXC and Linux commands.

How to install CentOS

Download the centos image from this link http://mirror.ufro.cl/centos-altarch/7.6.1810/isos/armhfp/CentOS-Userland-7-armv7hl-RaspberryPI-Minimal-1810-sda.raw.xz

I’m using this open source software https://www.balena.io/etcher/ to flash/burn the microSD card because it is very simple and works fine. I recommend using a 16GB card or larger.

If the previous process finished ok, take out the microSD card and put it into the raspberry and boot it. Wait until the boot process finishes and log in with this user and password

By default, the root partition is very small and you need to expand it. Run the next command, this process is fast.

Finally, to finish the installation process it is necessary to install many packages to compile PXC and percona-xtrabackup,

Repeat all the previous steps over all those 3 dbnodes because some libs are needed to start mysql and to work with percona-xtrabackup.

How to compile PXC + Galera + Xtrabackup

I am using an external SSD disk because it’s faster than the microSD which I mounted on /mnt directory, so we will use this partition to download, compile, and create the datadir.

For the latest PXC version, download and decompress it using the following commands:

RaspberryPi3’s are not x86_64 architecture; it uses an ARMv7 which forces us to compile PXC from scratch. For me, this process took 6-ish hours. I recommend running the next commands in a screen session.

Create a new OS user to be used by the mysql process.

Now to continue it is necessary to create the datadir directory. I recommend to use the SSD disk attached and set the mysql permissions to the directory:

Configure my.cnf with the minimal params to start mysql.

So far we’ve only compiled PXC. Before we can start the mysql process, we also need to compile the Galera library, as, without this library, mysql will start as a standalone db-node and will not have any “cluster” capabilities.

To build libgalera_smm.so you need to install scons.

Download using the next command:

Now we will proceed to compile libgalera. The source code for this library exists in the Percona-XtraDB-Cluster-57 directory download:

If the compile process finishes ok, it will create a new file like this:

I recommend copying libgalera_smm.so to the installed PXC directory to avoid deleting, in that case, remove the source directory.

Also, this is useful because after installing and compiling all the packages we can create a compressed file and copy to the rest of the db-nodes to avoid having to compile these packages again.

The last step is to download and compile percona-xtrabackup. I used the latest version:

If all the previous steps were successful, we will add those binary directories in the PATH variable:

Save and exit and run the “export” command manually to set it in the active session:

Well, so far we have PXC, Galera-lib, and percona-xtrabackup compiled for the ARMv7 architecture, which is all that is needed to work with PXC, so now we can start playing.

We will call the first host where we compiled “pxc1”. We will proceed to set the hostname:

It is necessary to connect again to ssh to refresh the hostname and you will see something like this:

Now we are ready to open the ports needed by PXC;  xtrabackup, galera, and mysql.

Repeat the above procedures to set the hostname and open ports in the other db nodes.

Finally, to start the first node you’ll need to initialize the system databases and then launch the mysql process with the –wsrep-new-cluster option. This will bootstrap the cluster so that it starts with 1 node. Run the following from the command-line:

Check the mysql error log to see any errors:

Create the new mysql user, and this will be used for xtrabackup to sync another db node on IST or SST process.

Lastly, I recommend checking if the galera library was loaded successfully:

You will see something like this:

As you can see this is the first node and the cluster size is 1.

How to copy the previous compiled source code to the rest of the db nodes

You don’t need to compile again over all the rest of the db nodes, just compress PXC and Xtrabackup directories and copy to the rest of the db nodes, nothing else.

In the first step, we compiled and installed on the next directories:

We’re going to proceed to compress both directories and copy to the other servers (pxc2 and pxc3)

Let’s copy to each db node:

Now connect to each db node and start decompressing, configure my.cnf, other stuff, and start mysql.

From here we are going to repeat several steps that we did previously.

Connect to IP_PXC2.

Add the next directories in the PATH variable:

Save and exit and run the “export” command manually to set it in the active session:

Create a new OS user to be used by mysql process:

Now to continue it’s necessary to create the datadir directory. I recommend using the SSD disk attached and set the mysql permissions to the directory.

Configure my.cnf with the minimal params to start mysql.

Now we need to start the second db node. This time you don’t need to add “–wsrep-new-cluster” param (from the second and next nodes it’s not needed), just start mysql and run the next command:

Check the mysql error log to see any error:

Check if the galera library was loaded successfully:

You will see something like this:

Excellent, we have the second node up, now is it’s part of the cluster and the cluster size is 2.

Repeat the previous steps to configure IP_PXC3 and nexts.

Summary

We are ready to start playing and doing a lot of tests. I recommend running sysbench to test how many transactions this environment supports, kill some nodes to test SST and IST, and I recommend using pt-online-schema-change and check this blog “How to Perform Compatible Schema Changes in Percona XtraDB Cluster” to learn how this tool works in PXC.

I hope you enjoyed this guide, and if you want to compile other PXC 5.7.X versions, please go ahead, the steps will be very similar.

Share this post

Comment (1)

  • Marcel Reply

    Hi, thanks for that guide but I spotted some inconsistencies. First you create the 2 tar archives on first node while mysql is running. The tar archive includes the datadir directory with innodb files etc. Later on you extract the tar archives on node2 and then run “mkdir /mnt/pxc5726/data/” but since data was already in the tar archive there is already the data dir.

    September 27, 2019 at 4:03 am

Leave a Reply