当前位置:网站首页>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 docker
start-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 net1
3、 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.dat
install Haproxy High availability and load balancing
1、 obtain haproxy Mirror image
docker pull haproxy
2、 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 tcpka
stay 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 haproxy
Get into h1 Containers , start-up Haproxy
docker exec -it h1 bash
haproxy -f /usr/local/etc/haproxy/haproxy.cfg
Check to see if startup succeeded :
visit http://ip:4001/dbs
边栏推荐
- Global variables in DLL
- ie7设置overflow属性失效解决方法
- 2020-12-29
- Search module use case writing
- AR model in MATLAB for short-term traffic flow prediction
- Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
- Node 内存溢出及V8垃圾回收机制
- asp. Net using redis cache
- Fuzzy PID control of motor speed
- copyTo
猜你喜欢
【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛
SSG框架Gatsby访问数据库,并显示到页面上
解决ProxyError: Conda cannot proceed due to an error in your proxy configuration.
Solve proxyerror: CONDA cannot proceed due to an error in your proxy configuration
Logical architecture of MySQL
QT handy notes (III) use qtcharts to draw a line chart in VS
服务发现原理分析与源码解读
R语言ggplot2可视化: 将图例标题(legend title)对齐到ggplot2中图例框的中间(默认左对齐、align legend title to middle of legend)
Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
随机推荐
matlab中的AR模型短时预测交通流
【Mysql数据库】mysql基本操作集锦-看得会的基础(增删改查)
E. Two Small Strings
JS one line code to obtain the maximum and minimum values of the array
面试突击68:为什么 TCP 需要 3 次握手?
JS 连等赋值操作
Network flow learning notes
在Blazor 中自定义权限验证
(1) Hand eye calibration of face scanner and manipulator (eye on hand)
Fuzzy PID control of motor speed
MySQL的逻辑架构
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
Apple dominates, Samsung revives, and domestic mobile phones fail in the high-end market
IIS website configuration
A new paradigm of distributed deep learning programming: Global tensor
[MySQL] understand the important architecture of MySQL (I)
Process32first returns false, error x message 24
服务发现原理分析与源码解读
QT handy notes (III) use qtcharts to draw a line chart in VS
R语言ggpubr包ggsummarystats函数可视化分组箱图(自定义分组颜色)并在X轴标签下方添加分组对应的统计值(样本数N、中位数median、四分位数的间距iqr、统计值的色彩和分组图色匹配