mysql MHA扩展haproxy搭建从库只读负载均衡
【环境介绍】
系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57
MHA架构中从库之间的负责均衡可选择mysql_route&keepalived+lvs&haproxy+keepalived&proxy中间件来实现,这里简单使用haproxy来实现
备库:192.168.142.112 192.168.142.113 这里设置192.168.142.113为haproxy配置主机
【搭建步骤:软件部署】
系统软件安装:
在一个从库或者在另一台主机上安装即可:直接使用系统自带的haproxy安装,yum install haproxy
Query OK, 0 rows affected (0.13 sec)
Query OK, 0 rows affected (0.01 sec)
Query OK, 0 rows affected (0.21 sec)
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
log 127.0.0.1 local0 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
log global
retries 3
option dontlognull
option redispatch
maxconn 2000
timeout connect 3000
timeout server 5000
timeout client 5000
# round robin balancing between the various backends
#---------------------------------------------------------------------
listen mysql-mha
bind 192.168.142.113:4040
mode tcp
option mysql-check user haproxy_check
balance roundrobin
server mysql_mha2 192.168.142.112:3306 weight 1 check
server mysql_mha3 192.168.142.113:3306 weight 1 check
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
listen stats *:8888
mode http
option httpclose
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
stats auth myadmin:myadmin
# Create an additional socket in haproxy's chroot in order to allow logging via
# /dev/log to chroot'ed HAProxy processes
$AddUnixListenSocket /var/lib/haproxy/dev/log
$ModLoad imudp
$UDPServerRun 514
local3.* /var/log/haproxy.log
# Send HAProxy messages to a dedicated logfile
if $programname startswith 'haproxy' then /var/log/haproxy.log
&~
Redirecting to /bin/systemctl status haproxy.service
haproxy.service - HAProxy Load Balancer
Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled)
Active: active (running) since 一 2018-06-11 15:53:09 CST; 35s ago
Main PID: 10512 (haproxy-systemd)
CGroup: /system.slice/haproxy.service
├─10512 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
├─10513 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
└─10514 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
6月 11 15:53:09 mysqldb2 systemd[1]: Started HAProxy Load Balancer.
Jun 11 15:53:09 localhost haproxy[10513]: Proxy stats started.
root 10512 1 0 15:53 ? 00:00:00 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy 10513 10512 0 15:53 ? 00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
haproxy 10514 10513 0 15:53 ? 00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
root 10609 62609 0 15:53 pts/0 00:00:00 tail -f /var/log/haproxy.log
root 10809 62956 0 15:54 pts/5 00:00:00 grep --color=auto haproxy
tcp 0 0 192.168.142.113:4040 0.0.0.0:* LISTEN 10513/haproxy
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 10513/haproxy
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqldb1 |
+------------+
mysql -ubackup -pbackup -h192.168.142.113 -P4040 -e "select @@hostname";
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqldb2 |
+------------+
mysql -ubackup -pbackup -h192.168.142.113 -P4040 -e "select @@hostname";
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqldb1 |
+------------+
mysql -ubackup -pbackup -h192.168.142.113 -P4040 -e "select @@hostname";
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqldb2 |
+------------+
【haproxy高可用用扩展】
当需要对VIP进行高可用配置时可以使用keepalived配置
yum install keepalived
keepalived配置文件,注意挂载VIP不要被占用:
global_defs {
#notification_email {
# xxx@qq.com
#}
#smtp_server smtp.163.com
smtp_connect_timeout 30
router_id LVS_HAPROXY
}
script "killall -0 haproxy" #服务探测,返回0说明服务是正常的
interval 1 #每隔1秒探测一次
weight 2
}
state MASTER #mha1为主,mha2为备
interface eno16777736
virtual_router_id 113 #实例1的VRID为113
garp_master_delay 1
priority 100 #主的优先级为100,从的优先级为99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
192.168.142.115/24 dev eno16777736 #VIP
}
track_interface {
eth0
}
chk_haproxy
}
Jun 11 18:35:45 localhost Keepalived_healthcheckers[30312]: Opening file '/etc/keepalived/keepalived.conf'.
Jun 11 18:35:45 localhost Keepalived_healthcheckers[30312]: Configuration is using : 7595 Bytes
Jun 11 18:35:45 localhost Keepalived_healthcheckers[30312]: Using LinkWatch kernel netlink reflector...
Jun 11 18:35:46 localhost Keepalived_vrrp[30313]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 11 18:35:47 localhost Keepalived_vrrp[30313]: VRRP_Instance(VI_1) Entering MASTER STATE
Jun 11 18:35:47 localhost Keepalived_vrrp[30313]: VRRP_Instance(VI_1) setting protocol VIPs.
Jun 11 18:35:47 localhost Keepalived_vrrp[30313]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eno16777736 for 192.168.142.115
Jun 11 18:35:47 localhost avahi-daemon[484]: Registering new address record for 192.168.142.115 on eno16777736.IPv4.
Jun 11 18:35:47 localhost Keepalived_healthcheckers[30312]: Netlink reflector reports IP 192.168.142.115 added
Jun 11 18:35:48 localhost Keepalived_vrrp[30313]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eno16777736 for 192.168.142.115
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c9:13:a2 brd ff:ff:ff:ff:ff:ff
inet 192.168.142.113/24 brd 192.168.142.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet 192.168.142.115/24 scope global secondary eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fec9:13a2/64 scope lin
mysql MHA扩展haproxy搭建从库只读负载均衡的更多相关文章
- Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
配置环境说明: KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G 系统盘20G cpu 4核 Haproxy keepalived 2台 192.168.1.10 192 ...
- haproxy+keepalived实现高可用负载均衡
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...
- haproxy+keepalived实现高可用负载均衡(转)
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. ...
- RabbitMQ3.6.3集群搭建+HAProxy1.6做负载均衡
目录 [TOC] 1.基本概念 1.1.RabbitMQ集群概述 通过 Erlang 的分布式特性(通过 magic cookie 认证节点)进行 RabbitMQ 集群,各 RabbitMQ 服 ...
- RabbitMQ3.6.3集群搭建+HAProxy1.6做负载均衡
目录 目录 1.基本概念 1.1.RabbitMQ集群概述 1.2.软件负载均衡器HAProxy 2.RabbitMQ的配置步骤 2.1.安装 Erlang.RabbitMQ 2.2.修改 /etc/ ...
- 用apache和tomcat搭建集群,实现负载均衡
型的企业应用每天都需要承受巨大的访问量,在着巨大访问量的背后有数台服务器支撑着,如果一台服务器崩溃了,那么其他服务器可以使企业应用继续运行,用户对服务器的运作是透明化的,如何实现这种透明化呢?由如下问 ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(三)
参考网址:https://blog.csdn.net/zhanghan18333611647/article/details/50811980 [前言] 在<架构之路:nginx与IIS服务器搭 ...
- 通过LVS+Keepalived搭建高可用的负载均衡集群系统
1. 安装LVS软件 (1)安装前准备操作系统:统一采用Centos6.5版本,地址规划如下: 服务器名 IP地址 网关 虚拟设备名 虚拟ip Director Server 192.168 ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(二)
[前言] 在<架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)>中小编简单的讲解了Nginx的原理!俗话说:光说不练假把式.接下来,小编就和大家一起来做个小Demo来体会一下N ...
随机推荐
- sql Server 2008 数据库自动备份维护计划
数据库中右键-‘管理’-新建维护计划 创建执行计划,设置备份时间 点击保存 完成 执行后报 ‘’错误5:拒绝访问 ’,时需到文件目录‘属性’→‘安全’设置用户的 ‘写入’ 权限
- 作业2:分布式版本控制系统Git的安装与使用
1.下载安装配置用户名和邮箱. 2. 创建工作目录并通过git init命令把这个目录变成Git可以管理的仓库. 3. 在工作目录下准备文本文件,建议下载Notepad++代替记事本. 4. 组合用g ...
- Linux ISCSI服务配置
Linux ISCSI服务配置,客户端进行访问 环境配置: server端 172.25.0.11 client端 172.25.0.10 配置ISCSI服务端 1.安装软件包 yum install ...
- HTML5网页点击分享到whatsapp
一.在网页头部加入分享标题和url,代码如下: <meta name="whatsapp:url" class="share_url" content=& ...
- 菜鸟学IT之python网页爬取初体验
作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2881 1. 简单说明爬虫原理 爬虫简单来说就是通过程序模拟浏览器放松请求站 ...
- [代码]解析nodejs的require,吃豆人的故事
最近在项目中需要对nodejs的require关键字做解析,并且替换require里的路径.一开始我希望nodejs既然作为脚本语言,内核提供一个官方的parser库应该是一个稳定可靠又灵活的渠道,然 ...
- JAVA之列表
增: import java.util.ArrayList; import java.util.List; public class T{ public static void main(Stri ...
- grep -v 反向查找
grep 是查找含有指定文本行 grep -v 是方向查找,比如 grep -v grep 就是查找 不含有 grep 内容的行,简单来说,就是过滤输入的 grep 命令 Demo: ps -aux ...
- Python——pyqt5——各框架编程
一.日期时间(dateTimeEdit/dateEdit) setDateTime:设置日期(含时间) QDateTime.currentDateTime():当前日期(含时间) setDate:设置 ...
- iOS NSInteger 的输出 %d %ld %zd %ld (long)
NSInteger 输出类型 %zd