haproxy对mysql集群进行负载均衡:
参考网址:/jave1ove/p/5980053.html
注:
mysql为集群模式,我使用的为mysql cluster(ndb引擎)
安装haproxy略
vi /etc/haproxy/hapory.cfg
global
log 127.0.0.1 local2 info
chroot/var/lib/haproxypidfile/var/run/haproxy.pidmaxconn4000user haproxygroup haproxydaemonstats socket /var/lib/haproxy/stats
defaults
mode http
log global
option tcplog (此处需改为tcplog)
option dontlognull
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 5m
timeout server 5m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen mysql
bind 0.0.0.0:3306
mode tcp
balance roundrobin (roundrobin为轮询)
server 10.0.0.2 10.0.0.2:3306
server 10.0.0.3 10.0.0.3:3306
listen stats
bind 0.0.0.0:8888
mode http
option httplog
maxconn 10
stats refresh 30s
stats uri /stats
:wq
service haproxy restart
即使用proxy服务器的3306端口(3306被占用的话,使用其它端口也可以,如3307)来访问集群的3306端口,访问时ip写haproxy的ip