Xtradb集群部署完成后,3台机器都能同时读写,此时需要在前端搭建haproxy来进行负载均衡。
官网haproxy配置参考地址:
https://www.percona.com/doc/perc ... s/virt_sandbox.html
Haproxy服务器配置
拿一台机器用作haproxy,此处是192.168.6.219。
安装haproxy
yum install haproxy -y
配置文件:
[iyunv@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
xtradb服务器上xinetd配置在所有xtradb服务器上,都要配置xinetd打开9200端口来进行监控。
yum instal xinetd
配置mysqlchk监控
[iyunv@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 # <user><pass> <available_when_donor=0|1> <log_file><available_when_readonly=0|1> <defaults_extra_file>" # 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的效果。
|