wcdz 发表于 2015-9-5 03:24:26

HAProxy负载均衡安装配置

1.下载HAProxy
   http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz

2. 安装haproxy
   #tar zxvf haproxy-1.4.22.tar.gz
   #cd haproxy-1.4.22
   #make TARGET=linux26
   #make install   
   
3. 创建haproxy用户和组
   #groupadd haproxy
   #useradd haproxy(useradd -g haproxy haproxy)

4、haproxy配置文件(/etc/haproxy.cfg)
----------------------------------------------------------------------------------------------------------

global
      log 127.0.0.1   local0
      maxconn 4096
      chroot /usr/local
      uid 99
      gid 99
      daemon
      nbproc 1
      pidfile /usr/local/run/haproxy.pid
      #debug
      #quiet

defaults
      log   127.0.0.1       local3
      mode    http
      optiondontlognull
      retries 2
      maxconn 2000
      balance roundrobin
      contimeout      5000
      clitimeout      50000
      srvtimeout      50000

listenweb_proxy 0.0.0.0:1080
      optionhttpchk GET /ping.jsp
      stats   uri   /haproxy-stats

listenpostgres
      bind    0.0.0.0:5433
      mode    tcp
      balance roundrobin
      serverdb1 192.168.111.151:5432 weight 1 maxconn 10000 check inter 10s
      serverdb2 192.168.111.152:5432 weight 1 maxconn 10000 check inter 10s
      serverdb3 192.168.111.153:5432 weight 1 maxconn 10000 check inter 10s
      serverdb4 192.168.111.154:5432 weight 1 maxconn 10000 check inter 10s
      serverdb5 192.168.111.155:5432 weight 1 maxconn 10000 check inter 10s
      serverdb6 192.168.111.156:5432 weight 1 maxconn 10000 check inter 10s
      serverdb7 192.168.111.157:5432 weight 1 maxconn 10000 check inter 10s
      serverdb8192.168.111.158:5432 weight 1 maxconn 10000 check inter 10s
----------------------------------------------------------------------------------------------------------
5. 创建haproxy服务
1)创建haproxy启动脚本
#/etc/init.d/haproxy
文件内容如下
----------------------------------------------------------------------------------------------------------

#! /bin/sh

PROGDIR=/usr/local
PROGNAME=haproxy
DAEMON=$PROGDIR/sbin/$PROGNAME
CONFIG=/etc/$PROGNAME.cfg
PIDFILE=$PROGDIR/run/$PROGNAME.pid
DESC="HAProxy daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
start()
{
    echo -n "Starting $DESC: $PROGNAME"
    $DAEMON -f $CONFIG
    echo "."
}
stop()
{
    echo -n "Stopping $DESC: $PROGNAME"
    cat $PIDFILE | xargs kill
    echo "."
}
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
*)
    echo "Usage: $SCRIPTNAME {start|stop}" >&2
    exit 1
    ;;
esac
exit 0
----------------------------------------------------------------------------------------------------------
启动服务
service haproxy start
可能问题:

创建run目录
2)创建haxproxy服务
#chkconfig --add haproxy
#chkconfig haproxy on

六、测试

在浏览器里面输入:http://192.168.111.150:1080/haproxy-stats,可以看到haproxy的监控界面。
  
页: [1]
查看完整版本: HAProxy负载均衡安装配置