haproxy配置mysql集群_Xtradb+Haproxy高可用数据库集群(二)haproxy负载均衡篇

Xtradb集群部署完成后,3台机器都能同时读写,此时需要在前端搭建haproxy来进行负载均衡。

官网haproxy配置参考地址:

Haproxy服务器配置

拿一台机器用作haproxy,此处是192.168.6.219。

安装haproxy

yum install haproxy -y

配置文件:

[root@yang-219 ~]# cat /etc/haproxy/haproxy.cfg

global

log 127.0.0.1 local0

log 127.0.0.1 local1 notice

maxconn 4096

chroot /usr/share/haproxy

user haproxy

group haproxy

daemon

defaults

log global

mode http

option tcplog

option dontlognull

retries 3

option redispatch

maxconn 2000

contimeout 5000

clitimeout 50000

srvtimeout 50000

frontend pxc-front

bind *:3307

mode tcp

default_backend pxc-back

frontend stats-front

bind *:8080

mode http

default_backend stats-back

frontend pxc-onenode-front

bind *:3308

mode tcp

default_backend pxc-onenode-back

backend pxc-back

mode tcp

balance leastconn

option httpchk

server c1 192.168.70.71:3306 check port 9200 inter 12000 rise 3fall 3

server c2 192.168.70.72:3306 check port 9200 inter 12000 rise 3fall 3

server c3 192.168.70.73:3306 check port 9200 inter 12000 rise 3fall 3

backend stats-back

mode http

balance roundrobin

stats uri /haproxy/stats

stats auth pxcstats:secret

backend pxc-onenode-back

mode tcp

balance leastconn

option httpchk

server c1 192.168.70.71:3306 check port 9200 inter 12000 rise 3fall 3

server c2 192.168.70.72:3306 check port 9200 inter 12000 rise 3fall 3

server c3 192.168.70.73:3306 check port 9200 inter 12000 rise 3fall 3

启动haproxy

/etc/init.d/haproxy start

web访问

上面配置的8080端口及/haproxy/stats

访问url:192.168.6.219:8080/haproxy/stats

用户名密码是上面配置的pxcstats:secret

e1034599ef071823a15bb0cb5f2e70bf.png

xtradb服务器上xinetd配置

在所有xtradb服务器上,都要配置xinetd打开9200端口来进行监控。

yum instal  xinetd

配置mysqlchk监控

[root@percona2 mysql]# cat /etc/xinetd.d/mysqlchk

# default: on

# description: mysqlchk

service mysqlchk

{

# this is a config for xinetd, place it in /etc/xinetd.d/

disable = no

flags           = REUSE

socket_type     = stream

type            = UNLISTED

port            = 9200

wait            = no

user            = nobody

server          = /usr/bin/clustercheck

log_on_failure  += USERID

only_from       = 0.0.0.0/0

#

# Passingarguments to clustercheck

# "

# Recommended:server_args   = user pass 1/var/log/log-file 0 /etc/my.cnf.local"

# Compatibility:server_args = user pass 1 /var/log/log-file 1 /etc/my.cnf.local"

# 55-to-56upgrade: server_args = user pass 1 /var/log/log-file 0 /etc/my.cnf.extra"

#

# recommended toput the IPs that need

# to connectexclusively (security purposes)

per_source      = UNLIMITED

}

默认安装xtradb server后会安装此配置.

重启xinetd服务

/etc/init.d/xinetd restart

haproxy每一段时间检测xtradb服务器上的9200端口,当clustercheck命令执行的结果不是200时,haproxy的检测将会把该机器从负载均衡中摘除,从而达到自动failover的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值