#安装haproxy-1.4.
tar -zxf haproxy-1.4..tar.gz
cd haproxy-1.4./
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
#创建目录结构
cd /usr/local/haproxy
mkdir conf/
mkdir logs/
#修改haproxy配置
vi conf/haproxy.cfg
global
log 127.0.0.1 local0
maxconn
chroot /usr/local/haproxy
uid
gid
daemon
nbproc
pidfile /usr/local/haproxy/logs/haproxy.pid
defaults
log global
mode http
option httplog
option dontlognull
retries
option redispatch
maxconn
contimeout
clitimeout
srvtimeout
listen web
bind :
mode http
balance roundrobin
stats uri /haproxy-stats
stats refresh 10s
stats realm Haproxy\ statistics
stats auth admin:admin
option httpchk HEAD /index.html
server web1 192.168.11.120: weight maxconn check inter 3s rise 3 fall 3
server web2 192.168.11.121: weight maxconn check inter 3s rise 3 fall 3
#日志输出配置,haproxy调用的是系统日志集中管理接口
#比如,我这里是rsyslog,syslog或syslog-ng配置方法与此类似
vi /etc/rsyslog.conf
ModLoad imudp
UDPServerRun
local0.* /var/log/haproxy.log
#重启日志系统
service rsyslog restart
#启动web1、web2
web1/bin/startup.sh
web2/bin/startup.sh
#启动haproxy
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
#测试,访问
http://localhost/haproxy-stats
http://localhost/index.html
http://192.168.11.120:8080/index.html
http://192.168.11.121:9080/index.html
等页面观察是否正常,可查看/var/log/haproxy.log观察日志输出情况。