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)
  
四、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
        option  dontlognull  
        retries 2
        maxconn 2000
        balance roundrobin
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000
 
listen  web_proxy 0.0.0.0:1080
        option  httpchk GET /ping.jsp
        stats   uri     /haproxy-stats
 
listen  postgres
        bind    0.0.0.0:5433
        mode    tcp
        balance roundrobin
        server  db1 192.168.111.151:5432 weight 1 maxconn 10000 check inter 10s
        server  db2 192.168.111.152:5432 weight 1 maxconn 10000 check inter 10s
        server  db3 192.168.111.153:5432 weight 1 maxconn 10000 check inter 10s
        server  db4 192.168.111.154:5432 weight 1 maxconn 10000 check inter 10s
        server  db5 192.168.111.155:5432 weight 1 maxconn 10000 check inter 10s
        server  db6 192.168.111.156:5432 weight 1 maxconn 10000 check inter 10s
        server  db7 192.168.111.157:5432 weight 1 maxconn 10000 check inter 10s
        server  db8  192.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
 
6、測試
 
在瀏覽器裏面輸入:http://192.168.111.150:1080/haproxy-stats,能夠看到haproxy的監控界面。
相關文章
相關標籤/搜索