redhat 6.4(64位)下HAproxy+Keepalived 负载均衡架构搭建 联系客服

发布时间 : 星期六 文章redhat 6.4(64位)下HAproxy+Keepalived 负载均衡架构搭建更新完毕开始阅读7614fbab050876323012120d

capture cookie ASPSESSION len 32 srvtimeout 20000

option httpclose # disable keep-alive

option checkcache # block response if set-cookie & cacheab le

rspidel ^Set-cookie:\\ IP= # do not let this cookie tell our intern al IP address

errorloc 502 http://192.168.114.58/error502.html errorfile 503 /etc/haproxy/errors/503.http

编辑配置文件(两台Haproxy配置文件相同):

# vim /usr/local/haproxy/conf/haproxy.cfg

defaults

log global mode http option httplog option dontlognull retries 3

option redispatch maxconn 2000

contimeout 5000 clitimeout 50000 srvtimeout 50000

listen web 192.168.10.222:80

mode http

option httplog

log global

option httpchk HEAD /test/test.jsp

server ha1 192.168.10.71:8080 check inter 2000 fall 3 weight 20 server ha2 192.168.10.72:8080 check inter 2000 fall 3 weight 10

创建启动文件:

# vim /etc/rc.d/init.d/haproxy #!/bin/sh #

# haproxy #

# chkconfig: 35 85 15

# description: HAProxy is a free, very fast and reliable solution # offering high availability, load balancing, and # proxying for TCP and HTTP-based applications # processname: haproxy

# config: /usr/local/haproxy/conf/haproxy.cfg # pidfile: /var/run/haproxy.pid

# Source function library. . /etc/rc.d/init.d/functions

# Source networking configuration. . /etc/sysconfig/network

# Check that networking is up.

[ \

config=\exec=\prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/haproxy

check() {

$exec -c -V -f $config }

start() {

$exec -c -q -f $config if [ $? -ne 0 ]; then

echo \ return 1

fi

echo -n $\

# start it up here, usually something like \ daemon $exec -D -f $config -p /var/run/$prog.pid retval=$? echo

[ $retval -eq 0 ] && touch $lockfile return $retval }

stop() {

echo -n $\

# stop it here, often \ killproc $prog retval=$? echo

[ $retval -eq 0 ] && rm -f $lockfile return $retval }

restart() {

$exec -c -q -f $config if [ $? -ne 0 ]; then

echo \ return 1 fi stop start }

reload() {

$exec -c -q -f $config if [ $? -ne 0 ]; then

echo \ return 1 fi

echo -n $\

$exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid) retval=$? echo

return $retval }

force_reload() { restart }

fdr_status() { status $prog }

case \

start|stop|restart|reload) $1 ;;

force-reload) force_reload ;;

checkconfig) check ;; status)

fdr_status ;;

condrestart|try-restart)

[ ! -f $lockfile ] || restart ;; *)

echo $\ad|force-reload}\ exit 2 esac

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

3、启动测试haproxy

# service haproxy start

4、haproxy日志配置

默认情况下,HAProxy为了节省读写IO所消耗的性能,默认情况下没有日志输出,以下是我配置log的过程:

RHEL6.4 默认使用的是rsyslog管理log