天天看点

docker 启动haproxy

准备工作:

#下载镜像
docker pull haproxy 
#创建工作目录
mkdir /home/haproxy
chmod 777 /home/haproxy
#创建配置文件haproxy.cfg
global   
    #log         127.0.0.1 local2
    #chroot      /var/lib/haproxy
    #pidfile     /var/run/haproxy.pid
    maxconn     4000
    #user        haproxy
   #group       haproxy
    daemon
    #stats socket /var/lib/haproxy/stats
    stats socket /usr/local/etc/haproxy/stats
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 stats
    mode http
    bind 0.0.0.0:1080
    stats enable
    stats uri /haproxyadmin
frontend www
  bind *:8888
  mode http
  log global
  default_backend app
backend app
  balance roundrobin
  server app1 192.168.42.73:80 cookie 1 check inter 5000 rise 3 fall 3 weight 1
  server app2 192.168.42.73:81 cookie 1 check inter 5000 rise 3 fall 3 weight 10
           

启动:

docker run -d --name haproxy -p 88:8888 -p 1080:1080 --privileged -v /home/haproxy:/usr/local/etc/haproxy haproxy
           
docker 启动haproxy

继续阅读