haproxy负载均衡mysql

1、安装
ubuntu 1804上安装:
sudo apt install haproxy
查看版本号1.8.8:
haproxy -v

2、配置
配置文件:/etc/haproxy/haproxy.cfg
日志:/var/log/haproxy.log

在haproxy.cfg中添加以下代码
# Load Balancing for Galera Cluster
listen galera 
bind *:8011
     balance source
     mode tcp
     option tcpka
     #option mysql-check user haproxy
     server node1 192.168.1.251:3306 check weight 1
     server node2 192.168.1.252:3306 check weight 1
     server node3 192.168.1.253:3306 check weight 1
server node4 192.168.1.254:3306 check weight 1

3、启动 
sudo systemctl status haproxy
sudo systemctl start haproxy

sudo systemctl restart haproxy

原文地址:https://www.cnblogs.com/xiaomacs/p/11697120.html