准备工作
搭建mycat集群至少需要两个以上的mycat实例,如果在同一个集群上部署的话需要不同的端口
设置jmx端口
vi wrapper.conf
wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1985
设置服务端口以及管理端口
vim server.xml
<property name="serverPort">8067</property>
<property name="managerPort">9067</property>
搭建haproxy
#拉取镜像
docker pull haproxy:1.9.3
创建目录,用于存放配置文件
mkdir /home/haproxy
创建容器
docker create --name haproxy --net host -v /home/haproxy:/usr/local/etc/haproxy haproxy:1.9.3
编写配置文件:
vi /home/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
maxconn 4000
daemon
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 admin_stats
bind 0.0.0.0:4001
mode http
stats uri /dbs
stats realm Global\ statistics
stats auth root:123456
listen proxy-mysql
bind 0.0.0.0:4002
mode tcp
balance roundrobin
option tcplog
#代理mycat服务
server mycat_1 192.168.64.128:8066 check port 8066 maxconn 2000
server mycat_2 192.168.64.128:8067 check port 8067 maxconn 2000
启动容器
docker restart haproxy && docker logs -f haproxy