linux搭建haproxy

1.准备搭建的材料

本人使用的是haproxy-1.6.9.tar.gz

2.开始搭建

 tar -zxf haproxy-1.6.9.tar.gz -C /usr/local

 cd /usr/local

 ln -s haproxy-1.6.9 haproxy

 uname -r   

 make TARGET=linux2632

 make install

 帮助命令 haproxy -h

3.创建配置文件和服务

 cd /usr/local/haproxy-1.6.9

 cp -p examples/haproxy.init /etc/rc.d/init.d/haproxy

 chmod +x /etc/rc.d/init.d/haproxy

 chkconfig --add haproxy

 useradd haproxy 

 groupadd haproxy

 cat /etc/haproxy/haproxy.cfg #需自己创建

 global
    log         127.0.0.1 local2
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon


defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 30000


listen stats
    mode http
    bind 0.0.0.0:1080
    stats enable
    stats hide-version
    stats uri     /haproxyadmin?stats
    stats realm   Haproxy\ Statistics
    stats auth    admin:admin
    stats admin if TRUE


frontend http-in
    bind *:80
    mode http
    log global
    option httpclose
    option logasap
    option dontlognull
    capture request  header Host len 20
    capture request  header Referer len 60
    default_backend servers


frontend healthcheck
    bind :1099
    mode http
    option httpclose
    option forwardfor
    default_backend servers


backend servers
  balance roundrobin
  server websrv1 192.168.254.156:80 check maxconn 2000
  server websrv2 192.168.254.157:80 check maxconn 2000

4.启动服务

service haproxy start
/etc/init.d/haproxy: line 98: /usr/sbin/haproxy: No such file or directory
Errors found in configuration file, check it with 'haproxy check'.

vim /etc/rc.d/init.d/haproxy

BIN=/usr/sbin/$BASENAME  ---> BIN=/usr/local/sbin/$BASENAME

因为安装时显示install haproxy  /usr/local/sbin而不是/usr/sbin

service haproxy restart

 

posted @ 2016-11-23 14:07  不二呆呆  阅读(2514)  评论(0编辑  收藏  举报