haproxy安装与基本配置

环境:RHEL 5.1

一、haproxy的安装
下载得到文件
haproxy-1.4.4.tar.gz
解压缩
tar zxvf haproxy-1.4.4.tar.gz
移动到工作目录
mv haproxy-1.4.4 /usr/local/haproxy
转到工作目录
cd /usr/local/haproxy
编译
make TARGET=linux26
安装
make install
执行
haproxy
返回:
HA-Proxy version 1.4.4 2010/04/07
Copyright 2000-2010 Willy Tarreau <[email protected]>
证明安装已经成功

二、haproxy的简单配置
vim haproxy.cfg
文件内容如下(括号里面是注释):

global
        log 127.0.0.1   local0
        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
        stats    refresh   5s
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen web_proxy 0.0.0.0:80
        #option httpchk GET /ping.php (这行如果加上的话可以让haproxy检查服务器的状态,但需在Web目录下面放一个测试文件,如ping.php)
        cookie SERVERID insert indirect nocache (这行设置sticky sessions)
        server s1 127.0.0.1:8088 cookie appinst1 check
        server s2 127.0.0.1:8089 cookie appinst2 check (这里填写你的各台服务器的IP与端口)

启动命令
haproxy -f haproxy.cfg

访问:
http://[ip地址]/haproxy-stats

可以看到haproxy的一个状态页面,里面会显示各服务器的运行状态

参考:http://hi.baidu.com/luohuazju/blog/item/f74f7ac4e94a97a08226ac14.html

猜你喜欢

转载自liyuan462.iteye.com/blog/679016