1. Create a MySQL Cluster
Download PXC image
Docker Pull Percona/percona-xtradb-cluster
Create an internal network: For security reasons, you need to create a docker internal network for your PXC cluster instances
Create command: Docker network Create Net1
Create a specified network segment: Docker network Create--SUBNET=172.18.0.0/24 Net1
View Network properties: Docker network Inspect NET1
Delete Networks: Docker network RM net1
Create a Docker volume (a workaround for the PXC node mapping data directory in the container)
Docker Volume Create--name v1
Create a PXC container (you can create a PXC container only if you want to pass in the run parameter like a PXC mirror)
Node1 node:
Docker run-d-P 3,306:3,306 \
-V v1:/var/lib/mysql \
-e mysql_root_password= database password \
-E cluster_name=pxc \
-e xtrabackup_password= passwords synchronized between database nodes \
--privileged--name=node1--net=net1--ip=172.18.0.0/24 PXC
Node2 to NODE5 node
Docker run-d-P 3,306:3,306 \
-V v1:/var/lib/mysql \
-e mysql_root_password= database password \
-E cluster_name=pxc \
-e xtrabackup_password= passwords synchronized between database nodes \
-E cluster_join=node1 \
--privileged--name=node#--net=net1--ip=172.18.0.0/24 PXC
2. Database Load Balancing:
Download Haproxy image
Docker Pull Haproxy
Docker Images viewing mirrors
Create a Haproxy configuration file
Created on Host: Touch/home/soft/haproxy.cfg
The configuration file can be consulted: https://zhangge.net/5125.html
Docker build cluster MySQL