装 HAProxy 配置负载均衡
HAProxy 可以完成较复杂的负载均衡工作,同时还可对服务器健康检测,有 down 机的自动停止分发,当服务器正常后,又自动均衡到刚死过的服务器。
下载:haProxy 1.3.15
具体下载目录在 /2012年资料/3月/15日/Linux下HAProxy的均衡配置/
安装:
cd /home wget tar -zxvf haproxy-1.3.15.7.tar.gz cd haproxy-1.3.15.7 mkdir –p /usr/local/haproxy/logs/ make TARGET=linux26 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy cd /usr/local/haproxy vi haproxy.cfg
创建/修改配置haproxy.cfg:
global log 127.0.0.1 local0 #log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096 chroot /usr/local/haproxy uid 99 gid 99 daemon nbproc 1 pidfile /usr/local/haproxy/logs/haproxy.pid #debug #quiet defaults log 127.0.0.1 local3 mode http option httplog option httpclose option dontlognull option forwardfor option redispatch retries 2 maxconn 2000 balance roundrobin stats uri /haproxy-stats contimeout 5000 clitimeout 50000 srvtimeout 50000 listen web 192.168.200.101:8090 mode http balance roundrobin option forwardfor option httpclose option httpchk GET /index.html server s1 192.168.200.101:8080 weight 3 check server s3 192.168.200.101:9090 weight 3 check