当前位置:网站首页>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 .
边栏推荐
- 【CNN】|How much position information do convolutional neural networks encode?
- Checkbox beautify button selected style
- 大厂外包or自研公司?测试人找工作怎么选?
- Writing shell scripts using vscode
- JS top icon menu click to switch background color JS special effect
- OPENSSL ASN.1, DER, PEM, X509
- Shopping and retail backstage management system of chain supermarket based on SSM framework
- Implementation of publish and subscribe mode ----- hand tearing JS series
- Promise use
- thinkphp3.2.3反序列化利用链分析
猜你喜欢

Thinkphp3.2.3 deserialization using chain analysis

What has TCL done right to break through the technological strength of Chinese brand innovation?

618 coming! Can oppo reno6, which is sold through all channels with high price and low configuration, win?

SQL query users logged in for three consecutive days

Promise use

Kirin V10 installation of tongweb7.0

Understand single chip microcomputer drive 8080lcd
![[elt.zip] openharmony paper Club - multi tier storage hierarchical data compression](/img/28/ec83b2ebb1f0772acdec443525c26d.png)
[elt.zip] openharmony paper Club - multi tier storage hierarchical data compression

如何提高回归测试效率

Tweenmax colorful ball bouncing animation
随机推荐
实现发布订阅模式-----手撕js系列
Web upload file Preview
Canvas rotation drawing H5 animation JS effect
openssl enc 加解密
用Fragment实现图片简易浏览
Why is vfly, a high-end brand of Yadi that does not live up to its name, not high-end?
手工测试转不了自动化测试,缺的是什么?
Sentence s, paragraph P in VIM text object
Implementation of publish and subscribe mode ----- hand tearing JS series
Tweenmax colorful ball bouncing animation
OpenGL第七章 基础光照
What kind of people are happy?
[elt.zip] openharmony paper Club - Data high-throughput lossless compression scheme
Canvas+svg line particle animation web page background
Quartz: an old and robust open source task scheduling framework, which is smooth enough to use
Unity's data persistence -- Jason
OpenGL Chapter 11 multiple light sources
[elt.zip] openharmony paper Club - fast random access string compression
【ELT.ZIP】OpenHarmony啃论文俱乐部——电子设备软件更新压缩
RT thread test