1、配置mysql负载均衡
用户请求3366端口,调度到172.16.1.7:3306、172.16.1.8:3306
1.1、配置MySQL
yum install -y mariadb mariadb-server
systemctl start mariadb
mysql -uroot -e "grant all privileges on *.* to 'all'@'%' identified by 'xx';"
1.2、配置Haproxy
cat /etc/haproxy/conf.d/mysql.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 50
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen haproxy-stats
bind *:9999
stats enable
stats hide-version
stats uri /haproxy?stats
stats realm "Haproxy Statistics"
stats auth admin:admin
stats admin if TRUE
frontend main
bind *:3366
mode tcp
log global
use_backend mysql_servers
backend mysql_servers
mode tcp
balance roundrobin
server node1 172.16.1.7:3306 check port 3306
server node2 172.16.1.8:3306 check port 3306
1.3、客户端测试
client客户端测试
yum install -y mariadb
mysql -h10.0.0.200 -uall -p123456 -P3366