Centos 编译安装Haproxy

一.环境介绍

  1.Centos6

  2. haproxy-1.4.25.tar.gz

 

二.安装

$ curl -O http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.25.tar.gz
$ tar zxvf haproxy-1.4.25.tar.gz
$ cd haproxy-1.4.25

$ make TARGET=linux26 PREFIX=/usr/local/haproxy
$ make install PREFIX=/usr/local/haproxy

$ cp examples/haproxy.cfg /usr/local/haproxy/
$ cp examples/haproxy.init /etc/init.d/haproxy
$ chmod 755 /etc/init.d/haproxy

$ ln -s /usr/local/haproxy /etc/
$ ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin/

$ groupadd haproxy
$ useradd -g haproxy haproxy -s /sbin/nologin -M
$ grep haproxy /etc/passwd
haproxy:x:507:507::/home/haproxy:/sbin/nologin

 

 

三.配置

$ vi /etc/haproxy/haproxy.cfg
global
    log 127.0.0.1    local0
    log 127.0.0.1    local1 notice
    #log loghost    local0 info
    maxconn 40960
    chroot /usr/local/haproxy
    uid 803
    gid 803
    daemon
    nbproc 1
    #debug
    #quiet

defaults
    log    global
    mode    http
    option    httplog
    option    dontlognull
    option  forwardfor
    option  httpclose
    retries    3
    option  redispatch
    maxconn    2000
    timeout connect 500000
    timeout client  5000000
    timeout server  50000000

frontend http-in
    bind    192.168.233.2:80
    mode    http
    option  httplog
    log     global
    acl is_a hdr_beg(host) -i www.test.com
    acl is_a hdr_beg(host) -i test.com
    use_backend a_server if is_a


    stats enable
    stats hide-version
    stats uri     /admin-status
    stats auth    admin:admin123
    stats admin if TRUE

        
backend a_server
    balance roundrobin
    cookie  SESSION_COOKIE  insert indirect nocache
    option  httpchk HEAD /Default.aspx HTTP/1.0
    fullconn 10000
    server web58 192.168.233.158:80 minconn 100 maxconn 1000 cookie web1 weight 6 check inter 2000 rise 2 fall 4
    server web85 192.168.233.185:80 minconn 100 maxconn 1000 cookie web2 weight 6 check inter 2000 rise 2 fall 4

 

  

 

四.启动

/etc/init.d/haproxy start

 

  

posted @ 2015-09-09 23:41  ca0guo  阅读(476)  评论(0编辑  收藏  举报