※ 이전에 생성한 MariaDB 2개 (참조 여기 Click!!)
위 2개 DB컨테이너(13307, 13308)과 아래의 HAProxy 20000 port로 연ㅗ
$ docker run -it --name haproxy -p 20000:20000 centos /bin/bash
# yum -y install haproxy
# vi /etc/haproxy/haproxy.cfg
※ 아래와 같이 설정파일을 변경한다.
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode tcp
log global
option tcplog
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 mysql_cluster 0.0.0.0:20000
mode tcp
balance roundrobin
#option mysql-check user haproxy
server node1 192.168.99.100:13307 weight 2 check
server node2 192.168.99.100:13308 weight 1 check
# haproxy -f /etc/haproxy/haproxy.cfg -db -V
URL : 192.168.99.100:20000
user/pwd : myuser/9999
Database : mydb