webinar slides: mysql on docker: understanding the basics
Post on 21-Jan-2018
204 Views
Preview:
TRANSCRIPT
Copyright 2017 Severalnines AB
I'm Jean-Jérôme from the Severalnines Team and I'm your host for today's webinar!
Feel free to ask any questions in the Questions section of this application or via the Chat box.
You can also contact me directly via the chat box or via email: info@severalnines.com during or after the webinar.
Your host & some logistics
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
About Severalnines and ClusterControl
Copyright 2017 Severalnines AB
What We Do
Copyright 2017 Severalnines AB
ClusterControl Automation & Management
Management● Multi-Cluster / Multi-DC
● Automate Repair &
Recovery
● Database Upgrades
● Backups
● Configuration Management
● Database Cloning
● One-Click Scaling
Deployment● Deploy a Cluster in Minutes
● On-Premises or in the Cloud (AWS)
Monitoring● Systems View with 1sec Resolution
● DB / OS stats & Performance Advisors
● Configurable Dashboards
● Query Analyzer
● Real-time / historical
Copyright 2017 Severalnines AB
Supported Databases
Copyright 2012 Severalnines ABCopyright 2012 Severalnines AB
Our Customers
Sep 2017
MySQL on Docker: Understanding the Basics
Ashraf Sharif, Support EngineerPresenter
ashraf@severalnines.com
Agenda
Copyright 2012 Severalnines AB
● Introduction● Image● Container● Volume● Network● Orchestration● ClusterControl on Docker● Q&A
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Introduction
What is Docker?
Copyright 2012 Severalnines AB
● Lightweight application container platform.● Each container has its own:
○ Filesystem○ Process space○ Network stack
● Use pre-built image.● Advantages:
○ Rapid deployment○ Greater density per host○ Isolation
Docker Architecture
Docker Components
Copyright 2012 Severalnines AB
Docker Components
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Image
Docker Image - Introduction
Copyright 2012 Severalnines AB
● A template for Docker container.● Create an image:
○ Commit the container's changes○ Build from Dockerfile
● Share the image:○ Save as tarball.○ Push to registry:
■ Public - Docker Hub, Docker Store■ Private, hosted - Quay, ECR, GCR, Bintray,
Artifactory■ Private, self-hosted - Your own registry
# Save image to tarball$ docker save -o mysql.tar abc
# Start your own Docker registry service$ docker run -d -p 5000:5000 --name registry registry:2
# Push image to Docker Hub$ docker push myimage/mysql:5.7
Docker Image - Commit a Container
Copyright 2012 Severalnines AB
Host
# Save image to tarball$ docker run -d --name=abc ubuntu:16.04
# Commit the changes (in another window)$ docker commit abc myimage/mysql:5.7
# Push image to Docker Hub$ docker exec -it abc /bin/bashroot@abc:/# apt-get updateroot@abc:/# DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server root@abc:/# vi /etc/mysql/my.cnf
# Ubuntu 16.04 host$ apt-get update$ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server$ vi /etc/mysql/my.cnf
# Run MySQL server as a process$ mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid
Docker
# Run MySQL server as a container$ docker run -d myimage/mysql:5.7 mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid
Docker Image - Using Dockerfile
Copyright 2012 Severalnines AB
Host
# Build as image$ docker build -t myimage/mysql:5.7 .
# vi DockerfileFROM ubuntu:16.04RUN apt-get updateRUN DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-serverCOPY my.cnf /etc/mysql/my.cnfEXPOSE 3306
# Ubuntu 16.04 host$ apt-get update$ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server$ vi /etc/mysql/my.cnf
# Run MySQL server as a process$ mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid
Docker
# Run MySQL server as a container$ docker run -d myimage/mysql:5.7 mysqld --socket=/var/lib/mysql/mysqld.sock --pid-file=/var/lib/mysql/mysqld.pid
# Create MySQL config file$ vi my.cnf
Docker Image - Build an Image
Copyright 2012 Severalnines AB
# Get image size$ docker imagesREPOSITORY TAG SIZEmyimage/mysql 5.7 529MB
# Show created layers$ docker history myimage/mysql:5.7CREATED BY SIZE/bin/sh -c #(nop) COPY file:e8163ef656b6da... 101B/bin/sh -c DEBIAN_FRONTEND=noninteractive ... 370MB/bin/sh -c apt-get update 39.1MB/bin/sh -c #(nop) CMD ["/bin/bash"] 0B/bin/sh -c mkdir -p /run/systemd && echo '... 7B/bin/sh -c sed -i 's/^#\s*\(deb.*universe\... 2.76kB/bin/sh -c rm -rf /var/lib/apt/lists/* 0B/bin/sh -c set -xe && echo '#!/bin/sh' >... 745B/bin/sh -c #(nop) ADD file:39d3593ea220e68... 120MB
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
724179e94999
f6016aab25f1
d51f459239fb
Image: myimage/mysql:5.7
ubuntu:16.04
ad74af05f5a2
Dockerfile
Docker Image - Best Practice for MySQL
Copyright 2012 Severalnines AB
# Get image size$ docker imagesREPOSITORY TAG SIZEmysql 5.6 299MBmysql 5.7 412MB
# tail entrypoint.sh......exec mysqld "$@"
● Extend an existing image available in the registry, instead of building a new one from scratch.
● The smaller the image size, the faster the deployment. (Hint: alpine).
● If using an entrypoint script, ensure mysqld command runs with "exec", indicating it's the primary process that holds PID 1 inside container.
● General guidelines: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
# vi DockerfileFROM mysql:5.7
# vi DockerfileFROM ubuntu:16.04RUN apt-get install {all MySQL stuff}
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Container
Docker Container - Run a Single Container
Copyright 2012 Severalnines AB
# Run a MySQL container$ docker run -d \--name my-test \--env MYSQL_ROOT_PASSWORD=mypassword \mysql
# Get the container layer size$ docker ps -sCONTAINER ID IMAGE NAMES SIZEd51f459239fb mysql my-test 4B (virtual 412MB)
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
Image layers (RO)
412 MB
Container layers (RW)4 B
Docker Container - Run another Container
Copyright 2012 Severalnines AB
# Run a MySQL container$ docker run -d \--name my-test2 \--env MYSQL_ROOT_PASSWORD=mypassword \mysql
# Get the container layer size$ docker ps -sCONTAINER ID IMAGE NAMES SIZEd51f459239fb mysql my-test 4B (virtual 412MB)e9de9ed50ced mysql my-test2 4B (virtual 412MB)
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
Image layers (RO)
412 MB
Container layers (RW)
4 B + 4 B
e9de9ed50ced
my-test2
Docker Container - Container Layer Changes
Copyright 2012 Severalnines AB
# Operation 2 - Create a schema and table$ docker exec -it my-test \mysql -uroot -pmypassword -e \'CREATE SCHEMA testdb; CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, data TEXT);'
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
d51f459239fb
0639788facc8
35369f9634e1
937bbdd4305a
my-test
c33a2b88395d
Copy-on-Write (CoW)
416f2a97355f
Supported CoW file system & devices: AUFS, Btrfs, Device Mapper, OverlayFS/Overlay2, ZFS, VFS
# Operation 1 - Update /etc/mysql/my.cnf$ docker exec -it my-test vi /etc/mysql/my.cnf
1
2New Branch
Docker Container - Application vs Data
Copyright 2012 Severalnines AB
Application Data
Stateless Stateful
Ephemeral Persistent
Independant Dependant
Frontend Backend
Web, API Database, File Storage
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Volume
Docker Volume - Type
Copyright 2012 Severalnines AB
# Mount a named volume into container-v mysql1-data:/var/lib/mysql
# Mount tmpfs into container--tmpfs /tmp
● Bind mount:○ A file or directory on the host machine is
mounted into a container.○ You manage the directory’s contents.
● Named volume:○ A new directory is created within Docker’s
storage directory.○ Docker manages the directory’s contents.○ Extensible via volume plugin.
● tmpfs:○ Stored on host machine’s memory (or swap).○ Linux only.
# Bind mount a directory into container-v /data/mysql1/data:/var/lib/mysql
# Bind mount a file into container-v /data/mysql1/my.cnf:/etc/mysql/my.cnf
Docker Volume - Persistent Volumes
Copyright 2012 Severalnines AB
# Run with persistent named volume, using -v or --volume$ docker run -d \--name mysql-local \--env MYSQL_ROOT_PASSWORD=mypassword \--volume local-datadir:/var/lib/mysql \mysql:5.7
Image: docker.io/mysql:5.7
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-local
416f2a92355f
/var/lib/mysql
local-datadir
# Run with persistent named volume, using --mount$ docker run -d \--name mysql-local \--env MYSQL_ROOT_PASSWORD=mypassword \--mount source=local-datadir,target=/var/lib/mysql \mysql:5.7
Docker Volume - Changes on Volume
Copyright 2012 Severalnines AB
# Run a container with port 3308$ docker run -d \--name mysql-local \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \-v local-datadir:/var/lib/mysql \mysql
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-local
416f2a92355f
/var/lib/mysql
local-datadir
# Run with persistent named volume, using --mount$ mysql -uroot -p -h127.0.0.1 -P3308 < dump.sql
dump.sql
3308
Docker Volume - Remote Volume
Copyright 2012 Severalnines AB
# Run a container with NFS bind mount$ docker run -d \--name mysql-nfs \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \-v /nfs/mysql-nfs:/var/lib/mysql \mysql
Image: docker.io/mysql
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-nfs
416f2a92355f
/var/lib/mysql
192.168.1.100/storage/docker
# Mount NFS with extra options for MySQL$ mount 192.168.1.100:/storage/docker /nfs -o noatime,nodiratime,hard,intr
3308
/nfs/mysql-nfs
Further Reading - Using NFS with MySQL:https://dev.mysql.com/doc/refman/5.7/en/disk-issues.html#disk-issues-nfs
Docker Volume - MySQL Persistency
Copyright 2012 Severalnines AB
Description Variable Name Default Value (5.7)
MySQL data directory datadir /var/lib/mysql
MySQL plugin directory plugin_dir {basedir}/lib/plugin
MySQL configuration directory config_dir /etc/my.cnf.d
MySQL binary log log_bin {datadir}/{hostname}-bin
Slow query log slow_query_log_file {datadir}/{hostname}-slow.log
Error log log_error {datadir}/{hostname}.err
General log general_log_file {datadir}/{hostname}.log
Docker Volume - Non-Persistent Volume
Copyright 2012 Severalnines AB
# Run a container with NFS bind mount and tmpfs volumes$ docker run -d \--name mysql-nfs-tmp \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \-v /nfs/mysql-nfs:/var/lib/mysql \--tmpfs /tmp:rw,size=1g,mode=177 \mysql
Image: docker.io/mysql:latest
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-nfs-tmp
416f2a92355f
/var/lib/mysql
192.168.1.100/storage/docker
3308
/nfs/mysql-nfs
/tmp
Docker Volume - Drivers
Copyright 2012 Severalnines AB
● Default is local.● You can use other different volume driver (or plugin).
○ Install the plugin.○ Use --volume-driver option.
● Volume drivers allow you to extend Docker's volume capabilities:
○ Snapshot○ Backup○ Encryption
# Install Rexray EBS docker plugin$ docker plugin install rexray/ebs EBS_ACCESSKEY=XXXX EBS_SECRETKEY=YYYY
# Verify if the plugin is loaded$ docker info -f '{{json .Plugins.Volume}}' | jq[ "local", "rexray"]
# Run a container with volume plugin$ docker run -d \--name=mysql-ebs \--volume-driver=rexray/ebs \-v ebs-datadir:/var/lib/mysql \mysql:5.7
# List volumes$ docker volume lsDRIVER VOLUME NAMElocal local-datadir1local local-datadir2rexray ebs-datadir
Docker Volume - Drivers and Storage Platforms
Copyright 2012 Severalnines AB
Further Reading - Volume Plugins List: https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins
Contiv
Fuxi Netshare
REX-ray
Horcrux
Convoy
OpenStorage
Amazon S3Azure FS
Google PD
Amazon EBS DigitalOcean BS
Flocker
EMC
FUSE
vSphere
iSCSI
CIFS NetApp OpenStack Cinder Minio CephFS
BeeGFS
NFS
SMB
Infinit
Docker Volume - Simple Benchmark
Copyright 2012 Severalnines AB
Local vs NFS vs NFS-tweaked vs EBS-standard
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Network
Docker Network - Types
Copyright 2012 Severalnines AB
● Single-host:○ Host○ None○ Bridge
■ Default bridge (docker0)■ User-defined bridge
● Multi-host:○ Default overlay○ User-defined overlay
● Extensible via Docker network plugins.
# List all networks$ docker network lsNAME DRIVER SCOPEbridge bridge localdb_multi overlay swarmdb_single bridge localdocker_gwbridge bridge localhost host localingress overlay swarmnone null local
Docker Network - Host Network
Copyright 2012 Severalnines AB
# Run a container on host network$ docker run -d \--name mysql-host \--net host \-e MYSQL_ROOT_PASSWORD=mypassword \mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Display active TCP connections$ netstat -tulpn | grep mysqltcp6 0 0 :::3306 :::* LISTEN 24601/mysqld
● Container’s network interfaces will be identical with the machine host.
● Only one host network per machine host. ● Container linking, --link mysql-test:mysql is not
supported.● Port mapping, --publish 3307:3306 is not
supported.
Docker Network - Default Bridge Network
Copyright 2012 Severalnines AB
# Run a container on docker0 bridge network$ docker run -d \--name mysql-bridge \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Display active TCP connections$ netstat -tulpn | grep 3308tcp6 0 0 :::3308 :::* LISTEN 24601/docker-proxy
● Packet forwarding by iptables to the bridge network.● --publish is supported. Run multiple containers with
same image through different ports.● --link is supported. Link with other containers to
expose environment variables.● docker-proxy redirects connection to the correct
container through NAT.
docker0(virtual Ethernet bridge)
vethxxx vethyyy
Docker Network - User-Defined Bridge Network
Copyright 2012 Severalnines AB
# Run a container on user bridge network$ docker run -d \--name mysql1 \--net db_single \-p 3308:3306 \--ip 192.168.10.10 \--hostname mysql1 \-e MYSQL_ROOT_PASSWORD=mypassword \mysql:5.7
Container 1
eth0
eth0
Container 2
eth0
Docker
Host
# Create a new bridge network$ docker network create subnet=192.168.10.0/24 db_single
Similar to the default docker0 bridge, plus:● --hostname is supported for sticky hostname.● --ip is supported for sticky IP address.● --link is not supported. Use embedded DNS to
resolve container's name in the same network.
db_single(virtual Ethernet bridge)
vethxxx vethyyy
DNS
Docker Network - Plugins
Copyright 2012 Severalnines AB
● Similar to volume, Docker network can be extended through plugins:
○ Multi-host networking (must use outside of Swarm)
○ Name resolver and service discovery.○ Encryption.
● Popular network plugins:○ Contiv○ Calico○ Weave○ Flannel
Further Reading - Multi-host Networking with Calico:https://severalnines.com/blog/mysql-docker-multi-host-networking-mysql-containers-part-2-calico
Docker Network - Default Overlay Network
Copyright 2012 Severalnines AB
# Run a service on default overlay network$ docker service create \--name mysql-service \--replicas 1 \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \-v nfs-datadir:/var/lib/mysql \mysql:5.7
Container 1
eth0
eth0 eth1
Docker
Host
# Initialize Docker Swarm$ docker swarm init
● Docker Swarm must be enabled.● Each task (container) has:
○ eth0 - Interface to external network via docker_gwbridge.
○ eth1 - Interface to overlay network via VXLAN.
docker_gwbridge
vethxxx vethyyy
br0
External
Container 2
eth0 eth1
Docker
docker_gwbridge
vethxxx vethyyy
br0
eth0Host
VXLANudp/4789
Docker Network - User-Defined Overlay Network
Copyright 2012 Severalnines AB
# Run a service on default overlay network$ docker service create \--name mysql-service \--replicas 1 \--net db_multi \-p 3308:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \-v nfs-datadir:/var/lib/mysql \mysql:5.7
Container 1
eth0
eth0 eth1
Docker
Host
# Create an overlay network$ docker network create -d overlay db_multi
Similar with the default overlay, plus:● Embedded DNS resolver:
○ {service_name} → Service VIP○ tasks.{service_name} → Container's IP
docker_gwbridge
vethxxx vethyyy
br0
External
Container 2
eth0 eth1
Docker
docker_gwbridge
vethxxx vethyyy
br0
eth0Host
VXLANudp/4789
DNS
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
Docker Orchestration
Docker Orchestration - Container Orchestration
Copyright 2012 Severalnines AB
● Simplify container's management at scale.● Concept:
○ Multiple containers as one entity.○ Structural YAML formatting.
● Official Docker comes with:○ Docker Compose:
■ single-host, small scale, separate package.○ Docker Swarm:
■ multi-host, big scale, out-of-the-box.■ support compose formatting through
docker stack.
Docker Orchestration - Docker Compose
Copyright 2012 Severalnines AB
Docker CLI
version: '2'services: mysql-prod: image: mysql:5.7.16 command: - --innodb_buffer_pool_size=2G - --max_connections=50 ports: - "3307:3306" environment: MYSQL_ROOT_PASSWORD: r00tP4ssw0rD MYSQL_USER: myshop MYSQL_PASSWORD: MyS3creTP4s5 MYSQL_DATABASE: myshop hostname: mysql-prod networks: db-prod: ipv4_address: 192.168.10.101 volumes: - mysql-datadir:/var/lib/mysql - mysql-tmp:/tmp ulimits: nofile: soft: 16824 hard: 16824 mem_limit: 4g memswap_limit: 4gvolumes: mysql-datadir: mysql-tmp:networks: db-prod: driver: bridge ipam: driver: default config: - subnet: 192.168.10.0/24
# Production MySQL container - full command$ docker network create --subnet=192.168.10.0/24 db-prod$ docker run -d \--name mysql-prod \--net db-production \--publish 3307:3306 \--ip 192.168.10.101 \--hostname mysql-prod \--memory 4g \--memory-swap 4g \--ulimit nofile=16824:16824 \--volume mysql-datadir:/var/lib/mysql \--volume mysql-tmp:/tmp \--env MYSQL_ROOT_PASSWORD=r00tP4ssw0rD \--env MYSQL_USER=myshop \--env MYSQL_PASSWORD=MyS3creTP4s5 \--env MYSQL_DATABASE=myshop \mysql:5.7.16 \--innodb_buffer_pool_size=2G \--max_connections=50
Docker Orchestration - Run with Docker Compose
Copyright 2012 Severalnines AB
# Bring up the production MySQL container in background$ docker-compose up -dCreating network "compose_db-prod" with driver "bridge"Creating compose_mysql-prod_1
Image: docker.io/mysql:5.7.18
de70fa77eb2b
f6016aab25f1
0639788facc8
35369f9634e1
937bbdd4305a
ad74af05f5a2
0639788facc8
35369f9634e1
937bbdd4305a
mysql-prod
416f2a92355f
/var/lib/mysql
mysql-datadir
/tmp
mysql-tmp
3307
# Stop the container$ docker-compose stop
# Destroy everything$ docker-compose down
# Start the container$ docker-compose start
Scaling is supported via docker-compose scale, however conflicting options must be omitted:hostname, ports, ipv4_address, volume
Docker Orchestration - Docker Swarm
Copyright 2012 Severalnines AB
● Multi-host deployment, through overlay network.● Concepts:
○ Node■ Manager - Dispatches tasks■ Worker - Executes tasks by manager
○ Service■ Replicated - Number of replicas■ Global - One task per available node
○ Task■ Container
○ Mesh routing■ All Swarm nodes route to the running tasks■ Ingress load balancing (round-robin only)
○ Scheduler■ Resources availability■ Label and constraints
Docker Orchestration - Simple Auto Failover using Swarm
Copyright 2012 Severalnines AB
# Run a replica of MySQL service$ docker service create \--name mysql-service \--replicas 1 \--net db_multi \-p 3307:3306 \-e MYSQL_ROOT_PASSWORD=mypassword \--mount source=ebs-datadir,destination=/var/lib/mysql,volume-driver=rexray \--mountsource=ebs-conf,destination=/etc/my.cnf.d,volume-driver=rexray \mysql:5.7
mysql-service
Docker
Host 1
ebs-datadir
mysql-service
Docker
Host 2
3307
ebs-conf
Docker Orchestration - Galera Cluster on Swarm
Copyright 2012 Severalnines AB
# Bootstrap-only container$ docker service create \--name pxc-bs \--replicas 1 \--net db-multi-hosts \-e MYSQL_ROOT_PASSWORD=mypassword123 \-e CLUSTER_NAME=my_galera \-e CLUSTER_JOIN= \percona/percona-xtradb-cluster
DockerHost 1
tasks.pxc1
# 3-node Galera$ for i in {1..3}; do docker service create \--name pxc${i} \--replicas 1 \--net db-multi-hosts \-p 330${i}:3306 \-e MYSQL_ROOT_PASSWORD=mypassword123 \-e CLUSTER_NAME=my_galera \-e CLUSTER_JOIN=tasks.pxc-bs,tasks.pxc1,tasks.pxc2,tasks.pxc3 \--mount source=pxc{i},target=/var/lib/mysql \percona/percona-xtradb-cluster; \sleep 1m; \done
tasks.pxc-b
s
# Remove bootstrap-only container$ docker service rm pxc-bs
DockerHost 2
tasks.pxc2
DockerHost 3
tasks.pxc3
HAproxy
330133023303
330133023303
330133023303
3306
Docker Orchestration - Other Orchestration Tools
Copyright 2012 Severalnines AB
Docker Orchestration - Best Practice for MySQL
Copyright 2012 Severalnines AB
● Add label to node and use placement constraints:○ Avoid overcommit resources.○ Manageability and predictability.
● Use Service's name and virtual IP address to distinguish container's role.
● Understand the scheduling strategy:○ Spread○ Binpack○ Random○ Custom
● Rolling update:○ Only perform update one container at a time.○ Add delay before move to the next container.
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
ClusterControl on Docker
ClusterControl on Docker - Image
Copyright 2012 Severalnines AB
● Image is available at Docker Hub. Dockerfile at Github.● Automation software for database clusters.● Status: Non-production.● The image consists of:
○ ClusterControl v1.4.2○ Percona Server for MySQL○ Apache + SSL○ SSH key
● Key changes:○ Some ClusterControl defaults are changed to
support Docker.○ Automatic deployment (Galera only)
# Create a user-defined bridge for DB network$ docker network create --subnet=192.168.10.0/24 db-cluster
# Run a ClusterControl container$ docker run -d --name clustercontrol \--network db-cluster \--ip 192.168.10.10 \-h clustercontrol \-p 5000:80 \-p 5001:443 \-v /storage/clustercontrol/cmon.d:/etc/cmon.d \-v /storage/clustercontrol/datadir:/var/lib/mysql \-v /storage/clustercontrol/.ssh:/root/.ssh \-v /storage/clustercontrol/backups:/root/backups \-e CMON_PASSWORD mysecr3t \-e MYSQL_ROOT_PASSWORD mys3cret \severalnines/clustercontrol
# Restart cmon service inside container$ docker exec -it clustercontrol supervisorctl restart cmon
ClusterControl on Docker - Run as Container
Copyright 2012 Severalnines AB
● Recommended volumes for data persistence:○ /etc/cmon.d○ /var/lib/mysql○ /root/.ssh○ /root/backups
● ClusterControl UI is exposed at 80 and 443 by default.● Service control via supervisord: sshd, mysqld, httpd,
cmon, cmon-ssh, cmon-events, cc-auto-deployment● Run it as:
○ --net=host, if you want this container to manage host or container outside of Docker network.
○ --net={net_name}, if you want CC container to manage containers in the same Docker network.
# Run a ClusterControl container$ docker run -d --name=clustercontrol \-p 5000:80 \-p 5001:443 \-h clustercontrol \-v /storage/clustercontrol/.ssh:/root/.ssh \-v /storage/clustercontrol/datadir:/var/lib/mysql \-v /storage/clustercontrol/cmon.d:/etc/cmon.d \-v /storage/clustercontrol/backups:/backups \severalnines/clustercontrol
# Run a 3 node Galera cluster, with auto deployment$ for i in {1..3}; do docker run -d \ --name galera${i} \ -p 666{$i}:3306 \ --link clustercontrol:clustercontrol \ -e CLUSTER_TYPE=galera \ -e CLUSTER_NAME=mygalera \ -e INITIAL_CLUSTER_SIZE=3 \ severalnines/centos-sshdone
ClusterControl on Docker - Auto DB Cluster Deployment
Copyright 2012 Severalnines AB
● Use "severalnines/centos-ssh" image - configures passwordless SSH automatically from CC to DB containers and register the container with CC.
● Only Galera is supported (more to come).● Background script, cc-auto-deployment:
○ Monitors new containers registration.○ Triggers deployment job if AUTO_DEPLOYMENT=1
(default).○ Uses ClusterControl CLI, called 's9s' to interact
with cmon backend.● Deployment flow:
○ You create the container.○ cc-auto-deployment picks up the registered
containers and creates a deployment job.○ ClusterControl deploys the cluster.
ClusterControl on Docker - Manual DB Cluster Deployment
● Use "severalnines/centos-ssh" image with AUTO_DEPLOYMENT=0.
● Allows user to have better control on the deployment process initiates by ClusterControl.
● All supported database cluster can be deployed using this method.
● Deployment flow:a. You create the containers.b. You create the database deployment job
through ClusterControl UI.c. ClusterControl deploys the cluster.
Copyright 2012 Severalnines AB
Further Reading - Example at Github:https://github.com/severalnines/docker/tree/master/examples/docker
ClusterControl on Docker - Add Existing DB Containers
Copyright 2012 Severalnines AB
● Must be in the same Docker network with the DB containers.
● SSH server and client must be installed and started on the DB containers:
○ Setup passwordless SSH from ClusterControl container to the DB containers.
○ It's going to improve though.
Further Reading - Import Existing DB Containers into ClusterControl:https://severalnines.com/blog/clustercontrol-docker
Copyright 2017 Severalnines AB
Copyright 2017 Severalnines AB
What's Next?
Copyright 2017 Severalnines AB
● Follow our MySQL on Docker blog series at severalnines.com/blog
● Attend the 2nd MySQL on Docker webinar, MySQL Container Management:○ Coming Soon in November 2017
● Deploy DB containers using ClusterControl Docker image.
What's Next
top related