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:
|
1 |
FROM ubuntu:precise<br>MAINTAINER Percona.com <info@percona.com><br><br># Upgrade<br>RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y<br><br>ENV DEBIAN_FRONTEND noninteractive<br>RUN echo "deb http://repo.percona.com/apt precise main" >> /etc/apt/sources.list.d/percona.list<br>RUN echo "deb-src http://repo.percona.com/apt precise main" >> /etc/apt/sources.list.d/percona.list<br>RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A<br><br>RUN apt-get update<br>RUN apt-get install -y percona-xtradb-cluster-56 qpress xtrabackup<br><br>RUN apt-get install -y python-software-properties vim wget curl netcat<br> |
Create a my.cnf file and add the following:
|
1 |
[MYSQLD]<br>user = mysql<br>default_storage_engine = InnoDB<br>basedir = /usr<br>datadir = /var/lib/mysql<br>socket = /var/run/mysqld/mysqld.sock<br>port = 3306<br>innodb_autoinc_lock_mode = 2<br>log_queries_not_using_indexes = 1<br>max_allowed_packet = 128M<br>binlog_format = ROW<br>wsrep_provider = /usr/lib/libgalera_smm.so<br>wsrep_node_address ={node_IP}<br>wsrep_cluster_name="mydockerpxc"<br>wsrep_cluster_address = gcomm://{node1_ip},{node2_ip},{node3_ip}<br>wsrep_node_name = {node_name}<br>wsrep_slave_threads = 4<br>wsrep_sst_method = xtrabackup-v2<br>wsrep_sst_auth = pxcuser:pxcpass<br><br>[sst]<br>streamfmt = xbstream<br><br>[xtrabackup]<br>compress<br>compact<br>parallel = 2<br>compress_threads = 2<br>rebuild_threads = 2<br> |
Build an image from the Dockerfile we just created.
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker build -rm -t ubuntu_1204/percona:galera56 .<br> |
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:
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker images | grep ubuntu<br>ubuntu_1204/percona galera56 c2adc932aaec 9 minutes ago 669.4 MB<br>ubuntu 13.10 5e019ab7bf6d 13 days ago 180 MB<br>ubuntu saucy 5e019ab7bf6d 13 days ago 180 MB<br>ubuntu 12.04 74fe38d11401 13 days ago 209.6 MB<br>ubuntu precise 74fe38d11401 13 days ago 209.6 MB<br> |
Now we will launch three containers with Percona XtraDB Cluster using the new docker image we have just created.
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # for n in {1..3}; do docker run --name dockerpxc$n -i -t -d ubuntu_1204/percona:galera56 bash; done<br> |
Check if the new containers were created:
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker ps<br>CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES<br>dd5bafb99108 ubuntu_1204/percona:galera56 bash 5 minutes ago Up 5 minutes dockerpxc3<br>01664cfcbeb7 ubuntu_1204/percona:galera56 bash 5 minutes ago Up 5 minutes dockerpxc2<br>2e44d8baee99 ubuntu_1204/percona:galera56 bash 5 minutes ago Up 5 minutes dockerpxc1<br> |
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:
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker inspect dockerpxc1 | grep IPAddress<br> "IPAddress": "172.17.0.2",<br>root@Perconallc-Support /home/jericho.rivera/docker-test # docker inspect dockerpxc2 | grep IPAddress<br> "IPAddress": "172.17.0.3",<br>root@Perconallc-Support /home/jericho.rivera/docker-test # docker inspect dockerpxc3 | grep IPAddress<br> "IPAddress": "172.17.0.4",<br> |
Take note of the IP address because we will need them later.
|
1 |
wsrep_cluster_address=gcomm://172.17.0.2,172.17.0.3,172.17.0.4<br> |
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.
Next step is to start the first node in the cluster, or bootstrapping.
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker attach dockerpxc1<br><br>root@2e44d8baee99:# /etc/init.d/mysql bootstrap-pxc<br> |
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:
|
1 |
root@Perconallc-Support /home/jericho.rivera/docker-test # docker attach dockerpxc2<br><br>root@01664cfcbeb7:/# /etc/init.d/mysql start<br> |
After starting all nodes, check the status of the entire cluster:
|
1 |
root@2e44d8baee99:/# mysql -e "show global status like 'wsrep%';"<br>+------------------------------+--------------------------------------+<br>| Variable_name | Value |<br>+------------------------------+--------------------------------------+<br>| wsrep_local_state_uuid | 7ae2a03e-d71e-11e3-9e00-2f7c2c79edda |<br>| wsrep_protocol_version | 5 |<br>| wsrep_last_committed | 1 |<br>| wsrep_replicated | 1 |<br>| wsrep_replicated_bytes | 270 |<br>| wsrep_repl_keys | 1 |<br>| wsrep_repl_keys_bytes | 31 |<br>| wsrep_repl_data_bytes | 175 |<br>| wsrep_repl_other_bytes | 0 |<br>| wsrep_received | 18 |<br>| wsrep_received_bytes | 2230 |<br>| wsrep_local_commits | 0 |<br>| wsrep_local_cert_failures | 0 |<br>| wsrep_local_replays | 0 |<br>| wsrep_local_send_queue | 0 |<br>| wsrep_local_send_queue_avg | 0.333333 |<br>| wsrep_local_recv_queue | 0 |<br>| wsrep_local_recv_queue_avg | 0.000000 |<br>| wsrep_local_cached_downto | 1 |<br>| wsrep_flow_control_paused_ns | 0 |<br>| wsrep_flow_control_paused | 0.000000 |<br>| wsrep_flow_control_sent | 0 |<br>| wsrep_flow_control_recv | 0 |<br>| wsrep_cert_deps_distance | 1.000000 |<br>| wsrep_apply_oooe | 0.000000 |<br>| wsrep_apply_oool | 0.000000 |<br>| wsrep_apply_window | 1.000000 |<br>| wsrep_commit_oooe | 0.000000 |<br>| wsrep_commit_oool | 0.000000 |<br>| wsrep_commit_window | 1.000000 |<br>| wsrep_local_state | 4 |<br>| wsrep_local_state_comment | Synced |<br>| wsrep_cert_index_size | 1 |<br>| wsrep_causal_reads | 0 |<br>| wsrep_cert_interval | 0.000000 |<br>| wsrep_incoming_addresses | ,, |<br>| wsrep_cluster_conf_id | 11 |<br>| wsrep_cluster_size | 3 |<br>| wsrep_cluster_state_uuid | 7ae2a03e-d71e-11e3-9e00-2f7c2c79edda |<br>| wsrep_cluster_status | Primary |<br>| wsrep_connected | ON |<br>| wsrep_local_bf_aborts | 0 |<br>| wsrep_local_index | 2 |<br>| wsrep_provider_name | Galera |<br>| wsrep_provider_vendor | Codership Oy <[email protected]> |<br>| wsrep_provider_version | 3.5(r178) |<br>| wsrep_ready | ON |<br>+------------------------------+--------------------------------------+<br> |
All three nodes are in the cluster!
Install net-tools to verify the default port for Galera.
|
1 |
root@dd5bafb99108:/# netstat -ant<br>Active Internet connections (servers and established)<br>Proto Recv-Q Send-Q Local Address Foreign Address State<br>tcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN<br>tcp 0 0 172.17.0.4:33875 91.189.88.153:80 TIME_WAIT<br>tcp 0 0 172.17.0.4:56956 172.17.0.2:4567 ESTABLISHED<br>tcp 0 0 172.17.0.4:57475 172.17.0.3:4567 ESTABLISHED<br>tcp6 0 0 :::3306 :::* LISTEN<br> |
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
Resources
RELATED POSTS