haproxy的安装和基本设置

来源:互联网 发布:正浩网络是干嘛的 编辑:程序博客网 时间:2024/06/08 12:34

haproxy的安装和基本设置

首页
http://haproxy.1wt.eu/

中文资料
http://cn.haproxy.org/download/1.3/doc/configuration-cn.txt

参考WIKI
http://blog.csdn.net/cenwenchu79/archive/2009/08/04/4409343.aspx

一、haproxy的安装
下载得到文件
解开压缩
执行

mkdir –p /usr/local/haproxy/logs/ 

 

 make TARGET=linux26PREFIX=/usr/local/haproxy 

. make install PREFIX=/usr/local/haproxy 

 

 

[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/sbin
[root@Template-Redhat54 haproxy-1.4.20]# install haproxy /usr/local/sbin
[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/share/man/man1
[root@Template-Redhat54 haproxy-1.4.20]# install -m 644 doc/haproxy.1 /usr/local/share/man/man1
[root@Template-Redhat54 haproxy-1.4.20]# install -d /usr/local/doc/haproxy
[root@Template-Redhat54 haproxy-1.4.20]# for x in configuration architecture haproxy-en haproxy-fr; do \
>                 install -m 644 doc/$x.txt /usr/local/doc/haproxy ; \
>         done
[root@Template-Redhat54 haproxy-1.4.20]#

 

检查安装结果:


 

[root@Template-Redhat54 haproxy-1.4.20]# haproxy
HA-Proxy version 1.4.20 2012/03/10
Copyright 2000-2012 Willy Tarreau <w@1wt.eu>

Usage : haproxy [-f <cfgfile>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ]
        [ -p <pidfile> ] [ -m <max megs> ]
        -v displays version ; -vv shows known build options.
        -d enters debug mode ; -db only disables background mode.
        -V enters verbose mode (disables quiet mode)
        -D goes daemon
        -q quiet mode : don't display messages
        -c check mode : only check config files and exit
        -n sets the maximum total # of connections (2000)
        -m limits the usable amount of memory (in MB)
        -N sets the default, per-proxy maximum # of connections (2000)
        -p writes pids of all children to this file
        -de disables epoll() usage even when available
        -ds disables speculative epoll() usage even when available
        -dp disables poll() usage even when available
        -sf/-st [pid ]* finishes/terminates old pids. Must be last arguments.

 

证明安装已经成功

二、haproxy
vi 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
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen web_proxy 0.0.0.0:80
        option httpchk GET /demo/ping.jsp

        server s1 127.0.0.1:8080 weight 3 check
        server s2 127.0.0.1:8081 weight 3 check

启动命令
haproxy -f haproxy.cfg
报错:
[root@localhost haproxy]# haproxy -f haproxy.cfg
[ALERT] 236/112258 (5538) : [haproxy.main()] Cannot create pidfile /usr/local/haproxy/logs/haproxy.pid
mkdir /usr/local/haproxy/logs 就可以了

访问:
http://192.168.95.129:80/haproxy-stats

调试启动命令:
haproxy -f haproxy.cfg -d

 

原创粉丝点击