July 22, 2014

Installing Percona XtraDB Cluster 5.6 with the Docker open-source engine

In my previous post, I blogged about using Percona Server with Docker and have shown you how fast and easy it was to create a virtual environment with just a few commands.

This time I will be showing you how to setup a three-node Percona XtraDB Cluster (PXC) 5.6 on the Docker open-source engine. Just to review Docker… “is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.”

In this case we will make use of a Dockerfile, think of this more like the Vagrantfile, it is a build script with a set of commands automating the creation of a new docker container.

For this case, we will use the following Dockerfile contents and use Ubuntu 12.04 instead of CentOS 6.5 as guest OS:

Create a my.cnf file and add the following:

Build an image from the Dockerfile we just created.

The ‘docker build’ command will create a new image from the Dockerfile build script. This will take a few minutes to complete. You can check if the new image was successfully built:

Now we will launch three containers with Percona XtraDB Cluster using the new docker image we have just created.

Check if the new containers were created:

Get relevant information from the container using ‘docker inspect’ command which by default will show a JSON-format output on the terminal. Since we only need to get the IP address for each container just run the following commands:

Take note of the IP address because we will need them later.

Do the same for dockerpxc2 and dockerpxc3 nodes. To attach to a container you need to run ‘docker attach {node_name}’ (eg # docker attach dockerpxc1). To exit without stopping the containers you need to hit CTRL+p/CTRL+q, otherwise an explicit ‘exit’ command on the prompt will drop you out of the container and stop the container as well, as much as possible we try to avoid this. Also make sure to edit wsrep_node_name and wsrep_node_address accordingly.

Bootstrapping the Cluster

Next step is to start the first node in the cluster, or bootstrapping.

After bootstrapping the first node, we can then prepare the first node for SST. That means we need to create the SST auth user, and in this case it is wsrep_ss_auth=pxcuser:pxcpass.

After adding the SST auth user on the first node the next step would be to start dockerpxc2 and dockerpxc3:

After starting all nodes, check the status of the entire cluster:

All three nodes are in the cluster!

Install net-tools to verify the default port for Galera.

Summary

I’ve shown you the following:

* Create a Dockerfile and my.cnf file
* Build a docker container using the created Dockerfile
* Made a few changes on some wsrep_ options on my.cnf
* Bootstrap the first node
* Start the other nodes of the cluster
* Check cluster status and confirmed all nodes are in the cluster

There are other ways to setup Docker with Percona XtraDB Cluster 5.6 such as using vagrant + docker which further automates the whole process or by using shell scripts, this article however shows you the basics of how to accomplish the same task.

On my next post, I will show how to setup Percona ClusterControl on another Docker container and adding this three-node PXC 5.6 cluster to it.

Read related posts here:

* Using MySQL Sandbox with Percona Server
* Testing Percona XtraDB Cluster with Vagrant
* Percona XtraDB Cluster: Setting up a simple cluster

About Jericho Rivera

Jericho Rivera currently works for Percona as Support Engineer. His interests include linux systems and MySQL database administration.

Comments

  1. Jericho,

    Nice! Though I wonder if it is possible to automate it to be more user friendly. As a user getting test cluster what I would do is to get back the cluster nodes IP (without messing with setting them in config) or might be even IP of HaProxy which is staying in front of the cluster.

  2. Jericho Rivera says:

    Peter,

    I think Pipework [Software-defined networking for Linux Containers] would be the solution here, although I’ve read that there are other “hackish” ways to accomplish the job. Currently, Docker is in heavy development and I would assume that eventually it would be possible to explicitly set each node’s IP much like how vagrant does it with “private network”.

  3. You might want to use ADD in your dockerfile to add the percona.list and my.cnf files.

  4. Jericho Rivera says:

    Daniel,

    Thanks for pointing that out.

    Yes indeed, we can include the ADD option in the dockerfile like below:

    ADD ./percona.list /etc/apt/sources.list.d/percona.list
    ADD ./my.cnf /etc/my.cnf

    Assuming the file contents are correct, it would make the process of provisioning the node clusters much simpler.

  5. erkules says:

    Isn’t it a very bad style to rely on the IP-address of the container?!
    Most likley the IP is going to change after i.e. a restart. Propagating the usage of docker should not use any IP at all.
    Also configuration is done *not* accessing the container :/

  6. Jericho Rivera says:

    @erkules,

    Its about showing the basics of setting up Percona XtraDB Cluster 5.6 on Docker, regarding whether this is the safest way to do container networking is beyond the scope of this blog IMHO. Readers may refer to Docker’s documentation for further reference here: https://docs.docker.com/articles/networking/#communication-between-containers (which is an advanced topic) and https://docs.docker.com/userguide/dockerlinks/.

    In hindsight, readers should be aware that this is only good for testing purposes and not fit (maybe not yet) for production use. I’ve also encountered some limitations with docker and on those rare occasions I tend to use Virtualbox. As I’ve also said before, docker is still heavily developed and there could still be changes on how the setup can be done.

Speak Your Mind

*