当前位置:网站首页>Docker configuring MySQL Cluster
Docker configuring MySQL Cluster
2022-07-26 09:48:00 【Color the sky】
original text :https://www.cnblogs.com/zhenghongxin/p/9228101.html
install docker
yum install -y dockerstart-up docker
# start-up docker
systemctl start docker
# stop it docker
systemctl stop docker
# restart docker
systemctl restart docker
# see docker Has it been started?
docker ps
explain docker It's already started
install pxc colony
1、 obtain pxc Mirror image
# obtain pxc Mirror image
docker pull percona/percona-xtradb-cluster
# rename
docker tag percona/percona-xtradb-cluster pxc
# Check out the image list
docker images
----------------------------------------------------------------------------------------------
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/percona/percona-xtradb-cluster latest 7ad1b9c338b6 5 weeks ago 413 MB
pxc latest 7ad1b9c338b6 5 weeks ago 413 MB
2、 Create network segment net1( Be careful not to contact the host ip Same paragraph , If there is a conflict, it will lead to the failure of external links docker Installed on mysql)
# Create network segment net1
docker network create --subnet=172.18.0.0/16 net1
# see net1 Network segment
docker inspect net1
# Delete net1 Network segment
docker network rm net13、 establish 5 Data volume (pxc Unable to directly access the data of the host , adopt docker Volume to store )
# Creating a data volume
docker volume create v1
docker volume create v2
docker volume create v3
docker volume create v4
docker volume create v5
# View data volume
docker inspect v1
4、 establish 5 individual pxc node
# Create the 1 individual MySQL node
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -v v1:/var/lib/mysql -v backup:/data --privileged --name=node1 --net=net1 --ip 172.18.0.2 pxc
--------------------------------------------------------------------------------
-d: Means running in the background
-v: mapping Docker Rolled into containers mysql Data directory
MYSQL_ROOT_PASSWORD: Indicates the created database password
CLUSTER_NAME: Indicates the name of the created cluster
XTRABACKUP_PASSWORD: Indicates the cluster communication password
--privileged: Indicates that the highest permission is assigned
--net: Specify network segment
--ip: Appoint IP
wait for 2 Minutes later , Create a second node , Wait until the first node is instantiated , To open the second node instance , Otherwise, there may be an instant stop
# Create the 2 individual MySQL node
docker run -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -e CLUSTER_JOIN=node1 -v v2:/var/lib/mysql -v backup:/data --privileged --name=node2 --net=net1 --ip 172.18.0.3 pxc
# Create the 3 individual MySQL node
docker run -d -p 3308:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -e CLUSTER_JOIN=node1 -v v3:/var/lib/mysql --privileged --name=node3 --net=net1 --ip 172.18.0.4 pxc
# Create the 4 individual MySQL node
docker run -d -p 3309:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -e CLUSTER_JOIN=node1 -v v4:/var/lib/mysql --privileged --name=node4 --net=net1 --ip 172.18.0.5 pxc
# Create the 5 individual MySQL node
docker run -d -p 3310:3306 -e MYSQL_ROOT_PASSWORD=abc123456 -e CLUSTER_NAME=PXC -e XTRABACKUP_PASSWORD=abc123456 -e CLUSTER_JOIN=node1 -v v5:/var/lib/mysql -v backup:/data --privileged --name=node5 --net=net1 --ip 172.18.0.6 pxc
5、 Look at the container mysql The node list
notice 5 All nodes have been started successfully , Enter any node to create a database , Observe others mysql Is it synchronized
thus pxc The simple cluster has been built .
Be careful : Use after the host computer restarts docker start node1 Failed to start any node , It is caused by the synchronization mechanism before the cluster , Start any node , This node will go to other nodes to synchronize data , Other nodes are still down , So the node failed to start , This is also pxc Strong consistency of clusters , The solution is , Delete all nodes docker rm node1 node2 node3 node4 node 5 And in the data volume grastate.dat file , then , Re execute the command of cluster creation , Because the data is in the data volume , Rest assured , When the cluster restarts, the data is still there .( If a node fails to start , You can delete this node , Then re execute the create command , The data will be synchronized )
# Delete all nodes
docker rm node1 node2 node3 node4 node5
# In the output data volume grastate.dat file
rm -rf /var/lib/docker/volumes/v1/_data/grastate.dat
rm -rf /var/lib/docker/volumes/v2/_data/grastate.dat
rm -rf /var/lib/docker/volumes/v3/_data/grastate.dat
rm -rf /var/lib/docker/volumes/v4/_data/grastate.dat
rm -rf /var/lib/docker/volumes/v5/_data/grastate.datinstall Haproxy High availability and load balancing
1、 obtain haproxy Mirror image
docker pull haproxy2、 To write Haproxy The configuration file
vim /home/soft/haproxy/haproxy.cfg
global
# working directory
chroot /usr/local/etc/haproxy
# Log files , Use rsyslog In service local5 Log devices (/var/log/local5), Grade info
log 127.0.0.1 local5 info
# The daemons run
daemon
defaults
log global
mode http
# Log format
option httplog
# The heartbeat detection record of load balancing is not recorded in the log
option dontlognull
# Connection timeout ( millisecond )
timeout connect 5000
# Client timeout ( millisecond )
timeout client 50000
# Server timeout ( millisecond )
timeout server 50000
# Monitoring interface
listen admin_stats
# Monitoring access to the interface IP And port
bind 0.0.0.0:8888
# access protocol
mode http
#URI Relative address
stats uri /dbs
# Statistical report format
stats realm Global\ statistics
# Login account information
stats auth admin:abc123456
# Database load balancing
listen proxy-mysql
# Access to the IP And port
bind 0.0.0.0:3306
# Network protocol
mode tcp
# Load balancing algorithm ( Polling algorithm )
# Polling algorithm :roundrobin
# Weight algorithm :static-rr
# Least connection algorithm :leastconn
# Request source IP Algorithm :source
balance roundrobin
# Log format
option tcplog
# stay MySQL Create an unauthorized haproxy user , The password is empty. .Haproxy Use this account for MySQL Database heartbeat detection
option mysql-check user haproxy
server MySQL_1 172.18.0.2:3306 check weight 1 maxconn 2000
server MySQL_2 172.18.0.3:3306 check weight 1 maxconn 2000
server MySQL_3 172.18.0.4:3306 check weight 1 maxconn 2000
server MySQL_4 172.18.0.5:3306 check weight 1 maxconn 2000
server MySQL_5 172.18.0.6:3306 check weight 1 maxconn 2000
# Use keepalive Detect dead chain
option tcpkastay MySQL Create an unauthorized haproxy user , The password is empty. .Haproxy Use this account for MySQL Database heartbeat detection
Create the 1 individual Haproxy Load balancing server
docker run -it -d -p 4001:8888 -p 4002:3306 -v /home/soft/haproxy:/usr/local/etc/haproxy --name h1 --privileged --net=net1 --ip 172.18.0.7 haproxyGet into h1 Containers , start-up Haproxy
docker exec -it h1 bash
haproxy -f /usr/local/etc/haproxy/haproxy.cfgCheck to see if startup succeeded :
visit http://ip:4001/dbs

边栏推荐
- asp. Net using redis cache
- IIS website configuration
- MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具
- 服务发现原理分析与源码解读
- Mo team learning summary (II)
- Why does new public chain Aptos meet market expectations?
- Mo team learning notes (I)
- Learning notes: what are the common array APIs that change the original array or do not change the original array?
- Azkaban【基础知识 01】核心概念+特点+Web界面+架构+Job类型(一篇即可入门Azkaban工作流调度系统)
- Logical architecture of MySQL
猜你喜欢

2021年山东省中职组“网络空间安全”B模块windows渗透(解析)

开发转测试:从0开始的6年自动化之路...

【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛

一种分布式深度学习编程新范式:Global Tensor

Does volatile rely on the MESI protocol to solve the visibility problem? (top)

Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice

2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)

The problem of accessing certsrv after configuring ADCs

Interview shock 68: why does TCP need three handshakes?

Node 内存溢出及V8垃圾回收机制
随机推荐
IE7 set overflow attribute failure solution
Modern medicine in the era of "Internet +"
Fiddler download and installation
Registration module use case writing
CSV data file settings of JMeter configuration components
B站这个视频我是跪着看完的
Explain automatic packing and unpacking?
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
网站设计需要的基本知识
EOJ 2020 January race E-number transformation
spolicy请求案例
反射机制的原理是什么?
阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践
QT随手笔记(六)——更新界面、截图、文件对话框
POJ 1012 Joseph
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
The diagram of user login verification process is well written!
Cloud native (36) | introduction and installation of harbor in kubernetes
[fluorescent character effect]
开发转测试:从0开始的6年自动化之路...