实战配置Haproxy动静分离
- 2016-12-14 16:35:00
- 村里来的扫地僧 原创
- 7507
动静分离示例:
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 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 30000 listen stats mode http bind 0.0.0.0:1080 stats enable stats hide-version stats uri /haproxyadmin?stats stats realm Haproxy Statistics stats auth admin:admin stats admin if TRUE frontend http-in bind *:80 mode http log global option httpclose option logasap option dontlognull capture request header Host len 20 capture request header Referer len 60 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .jpeg .gif .png .css .js use_backend static_servers if url_static default_backend dynamic_servers健康状态检测:
frontend healthcheck bind :1099 mode http option httpclose option forwardfor default_backend servers backend servers balance roundrobin server websrv1 192.168.32.200:80 check maxconn 2000 server websrv2 192.168.32.201:80 check maxconn 2000 backend static_servers balance roundrobin server imgsrv1 172.16.200.7:80 check maxconn 6000 server imgsrv2 172.16.200.8:80 check maxconn 6000 backend dynamic_servers balance source server websrv1 192.168.32.20:80 check maxconn 1000 cookie websrv1 server websrv2 192.168.32.21:80 check maxconn 1000 cookie websrv2 server websrv3 192.168.32.22:80 check maxconn 1000 cookie websrv3实战负载Mysql实例:
frontend Mysql bind :3306 mode tcp log global default_backend mysqlserver backend mysqlservers balance leastconn server dbserv1 192.168.32.200:3306 check port 3306 intval 2 rise 1 fall 2 maxconn 300 server dbserv2 192.168.32.201:3306 check port 3306 intval 2 rise 1 fall 2 maxconn 300
发表评论