haproxy+tomcat集群搭建

web1和web2的部署可参考我之前的文章《Tomcat集群搭建》,这里就省去该过程了。

 

#安装haproxy-1.4.17
tar -zxf haproxy-1.4.17.tar.gz
cd haproxy-1.4.17/
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 40960
    chroot /usr/local/haproxy
    uid 99
    gid 99
    daemon
    nbproc 1
    pidfile /usr/local/haproxy/logs/haproxy.pid

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    option redispatch
    maxconn 20480
    contimeout 5000
    clitimeout 50000
    srvtimeout 50000
    
listen web
    bind :80
    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:8080 weight 1 maxconn 10000 check inter 3s rise 3 fall 3
    server web2 192.168.11.121:9080 weight 1 maxconn 10000 check inter 3s rise 3 fall 3

#日志输出配置,haproxy调用的是系统日志集中管理接口
#比如,我这里是rsyslog,syslog或syslog-ng配置方法与此类似
vi /etc/rsyslog.conf
ModLoad imudp
UDPServerRun 514
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观察日志输出情况。

 

posted @ 2014-12-25 16:00  lichmama  阅读(1144)  评论(0编辑  收藏  举报