Docker file/image to deploy Percona XtraDB Cluster 5.6 for dev/tests.

Quickstart

$ git clone https://github.com/alyu/docker.git
$ cd docker/percona-xtradb-5.6/centos
$ ./build.sh
$ ./start-servers.sh 3
$ ./bootstrap-cluster.sh
$ ssh root@172.17.0.2 (root123)
$ mysql -uroot -proot123 -e "show status like '%wsrep%'"

Percona XtraDB Cluster 5.6 Dockerfile

# Percona XtraDB Cluster 5.6
#
# VERSION 1.0
# DOCKER-VERSION 0.81
#
# tag: latest
FROM centos:latest
MAINTAINER Alex Yu <alex@alexyu.se>

RUN yum -y update
RUN echo 'root:root123' | chpasswd
RUN yum -y install openssh-server openssh-clients which
# unsafe
#RUN sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
RUN mkdir -p /root/.ssh; chmod 700 /root/.ssh
ADD id_rsa.pub /root/.ssh/authorized_keys
RUN chown root.root /root/.ssh/*; chmod 600 /root/.ssh/*

# supervisord for sshd
RUN yum -y install python-setuptools
RUN easy_install supervisor
ADD supervisord.conf /etc/
RUN chown root.root /etc/supervisord.conf

# epel
RUN wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
RUN wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN rpm -Uvh epel* remi-*

# PXC XtraDB 5.6
RUN rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
RUN yum -y remove mysql-*
# need epel for qpress
RUN yum -y install Percona-XtraDB-Cluster-56 qpress
RUN rm -rf /var/lib/mysql/* /var/run/mysqld/* /etc/my.cnf
ADD my.cnf /etc/my.cnf
RUN chown mysql.mysql /etc/my.cnf

# sysbench need libaio and libmysqlclient
RUN yum -y install libaio
RUN wget http://www.lefred.be/files/sysbench-0.5-3.el6_.x86_64.rpm
RUN rpm -Uvh sysb*
RUN rm -f *.rpm

EXPOSE 22 80 443 3306 4444 4567 4568

ADD init.sh /opt/init.sh
RUN chown root.root /opt/init.sh
CMD ["/bin/bash", "/opt/init.sh"]

This docker file creates an image with the most recent Percona XtraDB Cluster 5.6 package installed.
Each launched image starts a single bootstrapped Galera node. A launched image will check
if the MySQL server's data dir needs to be initated or can be re-used.

Run the bootstrap-cluster.sh script to bootstrap a cluster.
The script sets a proper wsrep-cluster-address for all instances named 'galera-N'
and then performs a rolling node restart of the DB nodes to join the cluster.

Build a docker image

The default root user and MySQL server root password is 'root123'.
Ports exposed: 22 80 443 4444 4567 4568

Before creating the image, tune the my.cnf file to your liking.

centos:latest

$ git clone https://github.com/alyu/docker.git && cd docker/percona-xtradb-5.6/centos
$ ./build.sh

ubuntu:latest

$ git clone https://github.com/alyu/docker.git && cd docker/percona-xtradb-5.6/ubuntu
$ ./build.sh

$ docker images

alyu/ubuntu         pxc56               d440fdc4dffc        4 days ago          566.3 MB
alyu/centos         pxc56               01eb2d9512be        4 days ago          1.059 GB

Start 3 db instances

Launch 3 images named 'galera-1', 'galera-2', and 'galera-3' and map the host's
/mnt/data/{centos-pxc56|ubuntu-pxc56}/mysql to the instance's /var/lib/mysql direcory.

$ ./start-servers.sh 3

$ docker ps

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                                                             NAMES
7349a81d2294        alyu/centos:pxc56   /bin/bash /opt/init.   4 seconds ago       Up 2 seconds        22/tcp, 3306/tcp, 443/tcp, 4444/tcp, 4567/tcp, 4568/tcp, 80/tcp   galera-3
862280f54f62        alyu/centos:pxc56   /bin/bash /opt/init.   4 seconds ago       Up 3 seconds        22/tcp, 3306/tcp, 443/tcp, 4444/tcp, 4567/tcp, 4568/tcp, 80/tcp   galera-2
bcb8ea7da6c3        alyu/centos:pxc56   /bin/bash /opt/init.   4 seconds ago       Up 3 seconds        22/tcp, 3306/tcp, 443/tcp, 4444/tcp, 4567/tcp, 4568/tcp, 80/tcp   galera-1

Bootstrap the Galera cluster

Sets a proper wsrep-cluster-address in each node's my.cnf file and performs a rolling restart
of the nodes so that they join the cluster.

$ ./bootstrap-cluster.sh

Login to the first node and check the cluster status

$ ssh root@172.17.0.2 (pass: root123)
$ mysql -uroot -proot123 -e "show status like '%wsrep%'"

Tags: 

Add new comment

Plain text

  • No HTML tags allowed.
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.