HAProxy 설치 사용
yum -y install make gcc pcre*
mkdir -p/data/app_platform/haproxy/conf/
useradd -r haproxy -s/sbin/nologin
wget http://www.haproxy.org/download/1.4/src/haproxy-1.4.26.tar.gz
tar zxvf haproxy-1.4.26.tar.gz
cd haproxy-1.4.26
make TARGET=linux26 PREFIX=/data/app_platform/haproxy/
make install PREFIX=/data/app_platform/haproxy/
2. 프로파일 추가
/data/app_platform/haproxy/conf/haproxy.cfg
global
chroot /data/app_platform/haproxy/share/
log 127.0.0.1 local3 info
daemon
user haproxy
group haproxy
pidfile /var/run/haproxy.pid
nbproc 1
stats socket /tmp/haproxy level admin
stats maxconn 20
node master_loadbalance1
description xxxx
maxconn 65536
nosplice
spread-checks 3
defaults
option httpchk GET /php-fpm_status
log global
mode http
option httpclose
option abortonclose
no option accept-invalid-http-response
option allbackups
#option http-server-close
#option httplog
#option log-health-checks
#option tcp-smart-connect
option tcpka
option redispatch
option forwardfor except 127.0.0.1
retries 3
timeout check 60s
timeout connect 600s
timeout http-keep-alive 600s
timeout http-request 600s
timeout queue 600s
timeout server 600s
timeout tarpit 60s
timeout client 600s
frontend game_pool 0.0.0.0:80
mode http
no option accept-invalid-http-request
option http-server-close
log global
option httplog
option log-separate-errors
#option forwardfor except 127.0.0.1 header X-Real-IP
option forwardfor except 127.0.0.1
# acl path_web_inf path_beg -i /WEB-INF
# block if path_web_inf
acl game_url hdr_reg(host) -i ^(s\d*.xxxx.com|s\d*.xxx.com|s\d*.xxx.com|s\d*.xxx.com)$
use_backend game_pool if game_url
backend game_pool
mode http
balance roundrobin
cookie SERVERID insert indirect
# http-check disable-on-404
# http-check send-state
# option httpchk GET /check.php HTTP/1.1\r
Host:\ example.com
default-server inter 2s fastinter 1s downinter 5s slowstart 60s rise 2 fall 5 weight 30
server xxx-taiwan-game1 192.168.1.183:80 cookie xxx-taiwan-game1_80 check maxconn 2000
server xxx-taiwan-game2 192.168.1.184:80 cookie xxx-taiwan-game2_80 check maxconn 2000
listen monitor1 0.0.0.0:10443
mode http
balance roundrobin
stats enable
stats uri /nc-haproxy # - default is haproxy?stats
stats realm Haproxy\ statistics # - Enable statistics and set authentication realm
stats show-desc example gintama-taiwan-lb1 status page
stats auth ncadmin:taiwan
stats refresh 30s
stats show-legends # - Enable reporting additional informations on the statistics page
timeout check 10s
timeout client 45s
timeout connect 45s
timeout http-keep-alive 45s
timeout http-request 45s
timeout queue 45s
timeout server 45s
timeout tarpit 45s
3. 시작 스크립트 추가
#!/bin/sh
#
# haproxy
#
# chkconfig: - 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: /data/app_platform/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.
[ "$NETWORKING" = "no" ] && exit 0
exec="/data/app_platform/haproxy/sbin/haproxy"
prog=$(basename $exec)
conf_file="/data/app_platform/haproxy/conf/haproxy.cfg"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/haproxy
check() {
$exec -c -V -f $conf_file
}
start() {
$exec -c -q -f $conf_file
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
echo -n $"Starting $prog: "
# start it up here, usually something like "daemon $exec"
daemon $exec -D -f $conf_file -p /var/run/$prog.pid
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
$exec -c -q -f $conf_file
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
stop
start
}
reload() {
$exec -c -q -f $conf_file
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
echo -n $"Reloading $prog: "
$exec -D -f $conf_file -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)
retval=$?
echo
return $retval
}
force_reload() {
restart
}
fdr_status() {
status $prog
}
case "$1" in
start|stop|restart|reload)
$1
;;
force-reload)
force_reload
;;
check)
check
;;
status)
fdr_status
;;
condrestart|try-restart)
[ ! -f $lockfile ] || restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
exit 2
esac
4. 로그 출력 추가
/etc/rsyslog.d/haproxy.conf
local3.* /var/log/haproxy.log
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
service rsyslog restart
5. HAProxy 시작
service haproxy start
tail -f /var/log/haproxy.log
Feb 9 17:43:53 127.0.0.1 haproxy[25770]: backend game_pool has no server available!
Feb 9 17:44:02 127.0.0.1 haproxy[25810]: Proxy game_pool started.
Feb 9 17:44:02 127.0.0.1 haproxy[25810]: Proxy game_pool started.
Feb 9 17:44:02 127.0.0.1 haproxy[25810]: Proxy monitor1 started.
Feb 9 17:44:03 127.0.0.1 haproxy[25828]: Proxy game_pool started.
Feb 9 17:44:03 127.0.0.1 haproxy[25828]: Proxy game_pool started.
Feb 9 17:44:03 127.0.0.1 haproxy[25828]: Proxy monitor1 started.
Feb 9 17:44:05 127.0.0.1 haproxy[25829]: Server game_pool/xxx-taiwan-game1 is DOWN, reason: Layer4 timeout, check duration: 2001ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Feb 9 17:44:05 127.0.0.1 haproxy[25829]: Server game_pool/xxx-taiwan-game2 is DOWN, reason: Layer4 timeout, check duration: 2001ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Feb 9 17:44:05 127.0.0.1 haproxy[25829]: backend game_pool has no server available!
6. HAProxy 전원 켜기 시작 설정
chkconfig --level 35 haproxy on
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
HAProxy로 HA화된 Elasticsearch 클러스터 구축이 기사는 의 18 일째입니다. 실험실에있는 ESXi에 Elasticsearch 클러스터를 구축했습니다. 선생님으로부터 중복을 고려한 구축을 제안되었으므로, SPOF의 배제를 목표로 했습니다. 설정 파일은 다음과 같...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.