#创建目录,用于存放配置文件
mkdir -p /haoke/haproxy
#进入目录
cd /haoke/haproxy/
#拉取镜像
docker pull haproxy:1.9.3
#创建容器
docker create --name haproxy --net host -v /haoke/haproxy:/usr/local/etc/haproxy haproxy:1.9.3
#创建文件
vim /haoke/haproxy/haproxy.cfg
#输入如下内容[配置文件一定要写对,否则启动不起来,我在这上面浪费不少时间]
global
log 127.0.0.1 local2
maxconn 4000
daemon
defaults
log global
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
listen admin_status
stats realm Global\ statistics
bind 0.0.0.0:4001
stats uri /dbs ##haproxy自带的管理页面通过http://ip:port/admin访问
stats auth admin:admin123 ##管理页面的用户名和密码
mode http
option httplog
listen proxy-mysql
bind 0.0.0.0:4002 ##转发到 mycat 的 8066 端口,即 mycat 的服务端口
mode tcp
option tcplog
balance roundrobin
server mycat_1 192.168.88.101:8066 check port 8066 maxconn 2000
server mycat_2 192.168.88.101:8067 check port 8067 maxconn 2000
#启动容器
docker restart haproxy && docker logs -f haproxy
通过http://192.168.88.101:4001/dbs
端口查看集群情况,如果都是绿色表示部署成功
用navicate登录HAProxy,用户名和密码是你在mycat中设置的,默认端口是4002
到此,你就搭建出了高可用的mysql主从架构,恭喜你