当前位置:网站首页>Haproxy + keepalived for high availability load balancing of MySQL
Haproxy + keepalived for high availability load balancing of MySQL
2022-06-13 09:18:00 【Brother Xing plays with the clouds】
HAProxy+Keepalived Realization MySQL High availability load balancing
Current environment description
A:10.10.99.180(MySQLMaster)----|
|________VIP(10.10.99.103) B:10.10.99.108(MySQLSlave)------| C:10.10.105.11(MySQLSlave) D:10.10.105.23(HAProxy+Keepalived)
E:10.10.105.24(HAProxy+Keepalived) VIP:10.10.105.30
The following operations are in 10.10.105.23 and 10.10.105.24 On the whole
1、 Adjust kernel parameters , Add non local IP Binding support
#vi/etc/sysctl.conf net.ipv4.ip_nonlocal_bind=1 #sysctl–p
2、 install haproxy and keepalived yum-yinstallhaproxykeepalived
3、 To configure keepalived.conf file
#vi/etc/haproxy/haproxy.cfg
!ConfigurationFileforkeepalived
global_defs{
notification_email{
}
smtp_server127.0.0.1
smtp_connect_timeout30
router_idLVS_DEVEL
}
vrrp_instanceVI_1{
stateMASTER#10.10.105.24 Set to BACKUP
interfaceeth0
virtual_router_id51
realserver10.10.105.23#10.10.105.24 Change your own ip
priority90#10.10.105.24 Set to 80
advert_int1
authentication{
auth_typePASS
auth_pass111111
}
virtual_ipaddress{
10.10.105.30
}
4、 To configure haproxy
#vi/etc/haproxy/haproxy.cfg
#thisconfigneedshaproxy-1.1.28orhaproxy-1.2.1
global
#log127.0.0.1local0
log127.0.0.1local1notice
maxconn5000
uid99
gid99
daemon
pidfile/var/run/haproxy.pid
defaults
logglobal
modehttp
#optionhttplog
optiondontlognull
retries3
optionredispatch
maxconn2000
contimeout5000
clitimeout50000
srvtimeout50000
listenMYSQL10.10.105.30:3306
modetcp
maxconn2000
balanceroundrobin
servermysql-10.10.99.10810.10.99.108:3306checkinter5000fall1rise2
servermysql-10.10.105.1110.10.105.11:3306checkinter5000fall1rise2
srvtimeout20000
listenstats_auth10.10.105.23:80
#listenstats_auth10.10.105.24:80#backupconfig
statsenable
statsuri/korea
statsauthadmin:12345
statsadminifTRUE
5、 To start, respectively, haproxy and keepalived
[[email protected]~]#/etc/init.d/haproxyrestart&&/etc/init.d/keepalivedrestart
Stoppinghaproxy:[OK]
Startinghaproxy:[OK]
Stoppingkeepalived:[OK]
Startingkeepalived:[OK]
For more details, please read on to the next page : http://www.linuxidc.com/Linux/2013-10/92062p2.htm
Recommended reading :
Haproxy+Keepalived build Weblogic High availability load balancing colony http://www.linuxidc.com/Linux/2013-09/89732.htm
Keepalived+HAProxy Configure highly available load balancing http://www.linuxidc.com/Linux/2012-03/56748.htm
CentOS 6.3 Next Haproxy+Keepalived+Apache Configure notes http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived Realization WEB to cluster around on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Haproxy+Keepalived Build high availability load balancing http://www.linuxidc.com/Linux/2012-03/55880.htm
6、 see vip Whether to get up or not
[[email protected]~]#ipaddr
1:lo:<LOOPBACK,UP,LOWER_UP>mtu16436qdiscnoqueuestateUNKNOWN
link/loopback00:00:00:00:00:00brd00:00:00:00:00:00
inet127.0.0.1/8scopehostlo
inet6::1/128scopehost
valid_lftforeverpreferred_lftforever
2:eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
link/ether52:54:00:6c:d5:95brdff:ff:ff:ff:ff:ff
inet10.10.105.23/24brd10.10.105.255scopeglobaleth0
inet10.10.105.30/32scopeglobaleth0
inet6fe80::5054:ff:fe6c:d595/64scopelink
valid_lftforeverpreferred_lftforever
7、 Because we know crontab The grain fineness of is only 1 minute , It cannot be refined to seconds , So we write haproxy Loop detection script , And put it into the background to run
cd/home/ops/scripts
nohupshcheckhapid.sh&
vicheckhapid.sh
#!/bin/bash
whiletrue
do
HA=`ps-ef|grephaproxy|grep-vgrep|wc-l`
if[$HA-eq0];
then
/etc/init.d/haproxystart
echo"">/dev/null
sleep2
if[$HA-eq0];
then
/etc/init.d/keepalivedstop
fi
fi
sleep2
done
8、 High availability test
stay 10.10.105.23 On the implementation ipaddr|grepeth0
[[email protected]~]#ipaddr|grepeth0
eth0:<BROADCAST,MULTICAST,UP,LOWER_UP>mtu1500qdiscpfifo_faststateUPqlen1000
inet10.10.105.23/24brd10.10.105.255scopeglobaleth0
inet10.10.105.30/32scopeglobaleth0
close haproxy Open another terminal to continue ipaddr|grepeth0, observation
It can be found that when it cannot be started quickly haproxy After the process , The loop script will kill keepalived process , Realization vip Migration
10.10.105.30 Move quickly to 10.10.105.24 On this standby machine !
9、MySQL test
Program after read / write separation , be-all select Statements can be accessed directly by 10.10.105.303306 To do the work , Back end mysql The server Concurrent read operations can be implemented
[[email protected]]#mysqlslap-h10.10.105.30--concurrency=100--iterations=1--create-schema='ultrax'--query='select*frompre_home_share;'--number-of-queries=10--debug-info-ubbs-piz3n3s0ft
Benchmark
Averagenumberofsecondstorunallqueries:1.028seconds
Minimumnumberofsecondstorunallqueries:1.028seconds
Maximumnumberofsecondstorunallqueries:1.028seconds
Numberofclientsrunningqueries:100
Averagenumberofqueriesperclient:0
Usertime0.02,Systemtime0.08
Maximumresidentsetsize6996,Integralresidentsetsize0
Non-physicalpagefaults1584,Physicalpagefaults0,Swaps0
Blocksin0out0,Messagesin0out0,Signals0
Voluntarycontextswitches1280,Involuntarycontextswitches91
10、 effect
You can visit http://10.10.105.23/korea
user name admin
password 12345
HAProxy+Keepalived Realization MySQL High availability load balancing
Current environment description
A:10.10.99.180(MySQLMaster)----|
|________VIP(10.10.99.103) B:10.10.99.108(MySQLSlave)------| C:10.10.105.11(MySQLSlave) D:10.10.105.23(HAProxy+Keepalived)
E:10.10.105.24(HAProxy+Keepalived) VIP:10.10.105.30
The following operations are in 10.10.105.23 and 10.10.105.24 On the whole
1、 Adjust kernel parameters , Add non local IP Binding support
#vi/etc/sysctl.conf net.ipv4.ip_nonlocal_bind=1 #sysctl–p
2、 install haproxy and keepalived yum-yinstallhaproxykeepalived
3、 To configure keepalived.conf file
#vi/etc/haproxy/haproxy.cfg
!ConfigurationFileforkeepalived
global_defs{
notification_email{
}
smtp_server127.0.0.1
smtp_connect_timeout30
router_idLVS_DEVEL
}
vrrp_instanceVI_1{
stateMASTER#10.10.105.24 Set to BACKUP
interfaceeth0
virtual_router_id51
realserver10.10.105.23#10.10.105.24 Change your own ip
priority90#10.10.105.24 Set to 80
advert_int1
authentication{
auth_typePASS
auth_pass111111
}
virtual_ipaddress{
10.10.105.30
}
4、 To configure haproxy
#vi/etc/haproxy/haproxy.cfg
#thisconfigneedshaproxy-1.1.28orhaproxy-1.2.1
global
#log127.0.0.1local0
log127.0.0.1local1notice
maxconn5000
uid99
gid99
daemon
pidfile/var/run/haproxy.pid
defaults
logglobal
modehttp
#optionhttplog
optiondontlognull
retries3
optionredispatch
maxconn2000
contimeout5000
clitimeout50000
srvtimeout50000
listenMYSQL10.10.105.30:3306
modetcp
maxconn2000
balanceroundrobin
servermysql-10.10.99.10810.10.99.108:3306checkinter5000fall1rise2
servermysql-10.10.105.1110.10.105.11:3306checkinter5000fall1rise2
srvtimeout20000
listenstats_auth10.10.105.23:80
#listenstats_auth10.10.105.24:80#backupconfig
statsenable
statsuri/korea
statsauthadmin:12345
statsadminifTRUE
5、 To start, respectively, haproxy and keepalived
[[email protected]~]#/etc/init.d/haproxyrestart&&/etc/init.d/keepalivedrestart
Stoppinghaproxy:[OK]
Startinghaproxy:[OK]
Stoppingkeepalived:[OK]
Startingkeepalived:[OK]
边栏推荐
- Agile development practice summary-4
- 批量讀取文件夾下的全部語音文件
- 20211108 A转置乘A是正定矩阵吗?A转置乘A是正定矩阵的充分必要条件是什么?
- Three indexes reflecting system reliability in performance test: MTTF, MTTR and MTBF
- C/S模型与P2P模型
- LeetCode 583. 两个字符串的删除操作
- HAProxy + Keepalived实现MySQL的高可用负载均衡
- C language: deep understanding of character functions and string functions (1)
- LeetCode 6096. 咒语和药水的成功对数(二分查找)
- JUC atomic accumulator
猜你喜欢

Routing - static routing

Overview of common layers of image recognition neural network (under update)

final 原理

Mttr/mttf/mtbf diagram

Neo4j - CQL use

20220524 如何把CoppeliaSim安装到D盘

IP address introduction

Message Oriented Middleware

JUC 原子累加器 源码之 LongAdder

C language: deep understanding of character functions and string functions (2)
随机推荐
C language: Simulated Implementation of library function strcpy
Spectre record
【最全面详细解释】背包问题详解
20211104 why are the traces of similar matrices the same
LeetCode 202. 快乐数
Exporting MySQL data table documents using Navicat
20211018 一些特殊矩阵
20211108 能观能控,可稳可测
20220606 关于矩阵的Young不等式
20211028 Stabilizability
JUC Unsafe
20211005 Hermite矩阵及几个性质
Use typescript to complete simple snake eating function
JUC atomic accumulator
20211108 observable, controllable, stable and measurable
Final principle
20211108 is transpose multiply a a a positive definite matrix? What are the necessary and sufficient conditions for a to be a positive definite matrix?
Yolov5 face learning notes
时间戳转localDate
Dpdk timer learning notes