发布网友 发布时间:2022-04-24 20:54
共3个回答
懂视网 时间:2022-04-30 12:31
集群部署完成后,3台机器都能同时读写,此时需要在前端搭建haproxy来进行负载均衡。官网haproxy配置参考地址:
https://www.percona.com/doc/percona-xtradb-cluster/5.6/howtos/virt_sandbox.html
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
在所有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
# <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的效果。
本文出自 “楊雲” 博客,转载请与作者联系!
Xtradb+Haproxy高可用数据库集群(二)haproxy负载均衡篇
标签:percona xtradb cluster sysbench haproxy
热心网友 时间:2022-04-30 09:39
haproxy就是用来实现高可用的,不是说haproxy是高可用的。ha就是利用集群的手段,实现故障转移,负载均衡的目的。也就是实现,服务器出现故障后可以平滑地将服务转移到别的服务器,以及在大并发的情况下,将压力分散到不同的服务器上。热心网友 时间:2022-04-30 10:57
游戏