docker-compose部署haproxy

docker-compose配置文件如下
目录结构

[root@ZHTCYPT-SJJD-04 ~]# cd /data/haproxy/
[root@ZHTCYPT-SJJD-04 haproxy]# ll
total 8
drwxr-xr-x. 2 root root 4096 Apr 29 09:17 config
-rw-r--r--. 1 root root  304 Apr 28 17:57 haproxy.yml

haproxy.yml内容如下:

haproxy:
    image: haproxy:latest
    volumes:
        - ./config:/usr/local/etc/haproxy # haproxy的配置文件路径
    ports:
        - "1080:1080"  # 端口转换
        - "5000:5000"
        - "5001:5001"
    expose:
        - 1080   # haproxy对外暴露的端口
        - 5000
        - 5001

haproxy.cfg配置信息如下,位于config目录下

global
  log 127.0.0.1 local0 info  # 设置日志文件输出定向
  daemon
  maxconn 20000
 
defaults
  log                     global
  option tcplog
  option dontlognull
  retries 5
  option redispatch
  mode tcp
  timeout queue 1m
  timeout connect 10s
  timeout client 1m  #客户端空闲超时时间
  timeout server 1m  #服务端空闲超时时间
  timeout check 5s
  maxconn 10000
 
#listen http_front #haproxy的客户页面
#  bind 0.0.0.0:1080
#  stats uri /haproxy?stats

listen stats
    mode http
    log global
    bind 0.0.0.0:1080
    stats enable
    stats refresh 30s
    stats uri /haproxy-stats
    stats hide-version

listen  master
        bind *:5000
        mode tcp
        option tcplog
        balance leastconn
        http-check expect status 200
        default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
        server masterdb01 10.11.238.27:5432 cookie postgresql0_node1 maxconn 1000 check inter 5000 rise 2 fall 2
listen  replicas
        bind *:5001
        mode tcp
        option tcplog
        balance leastconn
        http-check expect status 200
        default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
        server slavedb01 10.11.238.49:5432 cookie postgresql0_node1 maxconn 1000 check inter 5000 rise 2 fall 2
        server slavedb02 10.11.238.50:5432 cookie postgresql0_node2 maxconn 1000 check inter 5000 rise 2 fall 2
        server slavedb03 10.11.238.51:5432 cookie postgresql0_node3 maxconn 1000 check inter 5000 rise 2 fall 2

启动方式:

docker-compose -f haproxy.yml up -d --build ##构建并启动
docker-compose -f haproxy.yml restart 重启
docker-compose -f haproxy.yml stop 停止
docker-compose -f haproxy.yml down 删除(移除容器)
docker-compose -f haproxy.yml logs 查询容器运行日志

猜你喜欢

转载自www.cnblogs.com/caidingyu/p/12800112.html