当前位置:网站首页>Docker uses PXC to build a MySQL Cluster (mysql:5.7.24)
Docker uses PXC to build a MySQL Cluster (mysql:5.7.24)
2022-06-11 03:49:00 【linmengmeng_ one thousand three hundred and fourteen】

About MySQL colony , There are two common modes :Replication Cluster architecture ( Master slave copy ) and PXC Cluster architecture
- PXC All nodes in the cluster scheme are readable and writable ,Replication Slave node cannot write , Because master-slave synchronization is one-way , from slave Node to master Point synchronization .
- PXC The synchronization mechanism is synchronous , This is also the fundamental reason why it can ensure strong data consistency ,Replication Synchronous mechanism is asynchronous , If it stops syncing from the node , You can still insert data into the primary node , Correct return , Cause inconsistency between master and slave data .
- PXC It's about sacrificing performance to ensure data consistency ,Replication It's better than PXC Of . So they are not the same .PXC It's for storing important information , for example : Order 、 User information, etc .Replication For general information storage , Able to tolerate data loss , for example : The shopping cart , User behavior log, etc .


Record the construction here PXC The process of clustering , The selected image is percona/percona-xtradb-cluster:5.7.24,
For the original document, see :About Percona XtraDB Cluster
Docker The cluster environment is :docker-79、docker-80、docker-81 Three machines , among docker-81 For the current cluster Leader node .
1. Pull the mirror image :
docker pull percona/percona-xtradb-cluster:5.7.24
Here you can choose according to your own needs MySQL edition , Directly modify the following version number . Different versions MySQL, Normal should be able to pull down .
2. establish docker Swarm Internal network
docker network create -d overlay --attachable pxc_network

It must be added here –attachable Otherwise, it will run later pxc When the container , Will report a mistake :XXX not manually attachable.
docker: Error response from daemon: Could not attach to network pxc-network: rpc error: code = PermissionDenied desc = network pxc-network not manually attachable.
If it is on a single server, it needs to be based on the network card of the host , Create a subnet segment :docker network create --subnet=172.18.0.0/24 net1 When used in the back , Appoint 172.18.0.0 To 172.18.0.24 Within the scope of IP As each pxc Node IP
Here are three servers , Just create a overlay Type of network
3. Creating a data volume volume
Create data volumes once on each machine volume_81 And backup data volumes backup:
docker volume create volume_81
docker volume create backup
Then you can take a look at the newly created data volume , Location on the host :docker inspect Data volume name 
among :/var/lib/docker/volumes/volume_81/_data That is to say volume_81 Volume location . In fact, it is possible not to create it manually , At run time , If the data volume doesn't exist ,docker Will automatically help us create .
stay docker-81 On the machine , start-up pxc_81 node :
docker run --privileged=true \
--restart=always \
--name node_81 \
-d -p 3306:3306 \
-v volume_81:/var/lib/mysql \
-v backup:/data \
-e MYSQL_ROOT_PASSWORD=abc123456\
-e CLUSTER_NAME=PXC_CLUSTER \
-e XTRABACKUP_PASSWORD=abc123456\
--net=pxc_network \
percona/percona-xtradb-cluster:5.7.24

After the node is running normally , You can use Navicat Database linking tool access try :

In addition, you can see on the host MySQL Container files :
Be sure to use Navicat After successful connection , Then install from the node , Otherwise, even if the slave node is running normally , It may not be connected .
Then run the container on the other two servers .docker-80 machine
docker run --privileged=true \
--restart=always \
--name node_80 \
-d -p 3306:3306 \
-v volume_80:/var/lib/mysql \
-v backup:/data \
-e MYSQL_ROOT_PASSWORD=huauN2021 \
-e CLUSTER_NAME=PXC_CLUSTER \
-e CLUSTER_JOIN=node_81 \
-e XTRABACKUP_PASSWORD=huauN2021 \
--net=pxc_network \
percona/percona-xtradb-cluster:5.7.24
docker-79 machine
docker run --privileged=true \
--restart=always \
--name node_79 \
-d -p 3306:3306 \
-v volume_79:/var/lib/mysql \
-v backup:/data \
-e MYSQL_ROOT_PASSWORD=huauN2021 \
-e CLUSTER_NAME=PXC_CLUSTER \
-e CLUSTER_JOIN=node_81 \
-e XTRABACKUP_PASSWORD=huauN2021 \
--net=pxc_network \
percona/percona-xtradb-cluster:5.7.24
Then you can try to create a new database on any node , Other nodes will automatically synchronize the database or data .
Then you can take a look at the network Usage situation :
docker network inspect pxc_network

You can see three nodes IP.
Although we were the first to create node81 node , And it looks like it's the master node , Other nodes join the cluster according to its name , Here you can try to stop docker-81 On the machine MySQL Containers , And then verify ,docker-79 and docker-80 above MySQL You can still keep in sync .
New database :spring_boot_plus
You can see the automatic synchronization , Then import... On a certain computer SQL Script :
After importing successfully , You can see that the other two libraries also synchronize the data information imported above .
边栏推荐
- Lua removing elements from a loop in a list
- Arm development board scheme and manufacturer analysis
- RequestContextHolder
- Interface performance optimization ideas
- VIM quickly select a method / function
- JS the most commonly used sorting - hand tearing JS series
- 如何提高回归测试效率
- Go failing - expected ‘package‘, found ‘EOF‘
- [interpretable] | axiomatic attribute for deep networks
- Canvas rotation drawing H5 animation JS effect
猜你喜欢

OpenGL Chapter 10 illuminant

Why is vfly, a high-end brand of Yadi that does not live up to its name, not high-end?

UML series articles (28) architecture modeling - collaboration

Azure kubernates service update | improve development experience and efficiency

pmm监控oracle

SQL query users logged in for three consecutive days

J. Balanced Tree

Lvgl Chinese font production

Comparison of four delivery modes of Message Oriented Middleware

基于SSM框架的学生老师考试管理系统
随机推荐
实现发布订阅模式-----手撕js系列
Record the problem of Galaxy Kirin V10 server version once: an error is reported when installing KVM
OpenGL Chapter 8 material
RT thread test
Thinkphp3.2.3 deserialization using chain analysis
从功能测试进阶自动化测试,熬夜7天整理出这一份3000字超全学习指南【附网盘资源】
Shopping and retail backstage management system of chain supermarket based on SSM framework
1_ Attribute management function
Detailed explanation of scenario method for common test case design methods
Implementation of publish and subscribe mode ----- hand tearing JS series
Two solutions for reliable message consistency
The tide play power is really firepower! The first big screen cinema for young people? Cool open TV Max 86 "sudden attack
PostgreSQL statement
js最常用的排序---手撕js系列
pmm监控oracle
SSL library selection
Management system of College Students' associations based on SSM
unforgettable moments
Canvas rotation drawing H5 animation JS effect
[elt.zip] openharmony paper Club - fast random access string compression