HAProxy 예제
HAProxy는 Linux에서 실행되는 무료 부하 분산입니다. HAProxy는 매우 강력하며 기본 제공 모니터링 기능을 지원합니다.
해당 구성에 대한 자세한 내용은 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html을 참조하십시오.
글로벌 설정
전역 설정은 프런트 엔드 서버와 백엔드 서버 전체에서 적용되며 일반적으로 무시할 수 있습니다.
예를 들면 다음과 같습니다.
#--------------------------------------------------------------------- #
Global settings
#---------------------------------------------------------------------
global
# setup logging and force level to debug. Logs require rsyslog be setup.
chroot /var/lib/haproxy
log /dev/log local0 debug
# maximum number of connections allowed
maxconn 10000
# turn on stats unix socket
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
# user and group haproxy will run as
user haproxy
group haproxy
기본 설정
기본 설정은 백엔드 서버의 기본 구성에 대한 설정입니다.
log
전역 설정에 구성된 로깅을 사용합니다.
mode
요청을 분석하는 방법을 결정합니다. 이 예에서는 http 처리를 사용합니다.
option
예를 들면 다음과 같습니다.
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
default-server init-addr last,libc,none
log global
mode http
option httplog
option redispatch
option forwardfor
timeout connect 10s
timeout client 60s
timeout server 60s
timeout tunnel 1h
프런트 엔드 설정
모든 응용 프로그램이 통과하는 프런트 엔드입니다. 수신 요청을 처리하는 데 사용되는 백엔드 서버를 결정하는 라우팅 규칙을 포함합니다.
bind
수신 요청이 수신되는 포트를 나타냅니다.
capture
HAProxy http 요청 로깅에 세션 ID 쿠키를 포함합니다.
acl
확인 중인 조건에 따라 변수를 생성합니다. 예를 들어, -i -m beg <string><string>으로 시작하는 URI를 확인합니다.
use_backend
변수 값이 true인지 false인지에 따라 특정 백엔드 서버 그룹으로 라우팅합니다.
default
다른 규칙과 일치하지 않으면 백엔드가 사용됩니다.
예를 들면 다음과 같습니다.
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend ft_web
bind *:8080 name web
# log the session cookie if passed
capture cookie JSESSIONID= len 32
## path based routing to connection server
acl path_cxserver path -i -m beg /Thingworx/WS
acl path_tunnelserver path -i -m beg /Thingworx/WSTunnelServer
acl path_tunnelclient path -i -m beg /Thingworx/WSTunnelClient
use_backend cxserver if path_cxserver or path_tunnelserver or path_tunnelclient

# default traffic to platform
default_backend platform
ThingWorx Flow에 대한 예
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend ft_web
bind *:8443 ssl crt /certs/haproxy.pem name sslweb
# log the session cookie if passed
capture cookie JSESSIONID= len 32
##path based routing to ThingWorx Flow
acl p_flow1 path -i -m beg /Thingworx/Composer/apps/flow
acl p_flow2 path -i -m beg /Thingworx/Flow
acl p_flow3 path -i -m beg /Thingworx/Triggers
acl p_flow4 path -i -m beg /Thingworx/Lookups
acl p_flow5 path -i -m beg /Thingworx/Oauths
acl p_flow6 path -i -m beg /Thingworx/Subsystems/EventProcessingSubsystem/Subscriptions
acl p_flow7 path -i -m beg /enterprise/v1/fetchconfig
use_backend flow if p_flow1 or p_flow2 or p_flow3 or p_flow4 or p_flow5 or p_flow6 or p_flow7
백엔드 플랫폼 설정
백엔드는 프런트 엔드 및 특정 구성에서 전달된 요청을 처리할 수 있는 서버 그룹입니다.
balance
부하 분산 알고리즘입니다. 기본값은 라운드 로빈이며, 사용 가능한 다음 연결을 찾기 위해 사용 가능한 서버를 차례로 이동합니다.
cookie
후속 요청을 동일한 서버로 라우팅하기 위해 부하 분산에서 사용하는 쿠키를 삽입합니다.
예를 들면 다음과 같습니다.
#---------------------------------------------------------------------
# BackEnd Platform Configuration
#---------------------------------------------------------------------
backend platform
balance roundrobin
# sticky sessions
cookie SERVER insert indirect nocache
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
# health check
option httpchk GET /Thingworx/health
# configure platform instances
server platform1 10.0.10.10:8080 check inter 1000 fastinter 1000 cookie twx1
server platform2 10.0.10.11:8080 check inter 1000 fastinter 1000 cookie twx2
ThingWorx Flow에 대한 예
#---------------------------------------------------------------------
# BackEnd Flow Configuration
#---------------------------------------------------------------------
backend flow
balance source

option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }

# configure flow instances
server nginx {nginx_ip}:443 check ssl verify none
백엔드 Connection Server 설정
예:
#---------------------------------------------------------------------
# BackEnd Connection Server Configuration
#---------------------------------------------------------------------
backend cxserver
balance source
#hash-type consistent
option httpchk GET /
# configure connection server instances
server cxserver1 10.0.10.20:8080 check port 9009
server cxserver2 10.0.10.21:8080 check port 9009
모니터링
HAProxy에는 트래픽 흐름을 보는 데 사용할 수 있는 모니터링 UI가 있습니다. 수신 포트 및 선택적 자격 증명을 구성할 수 있습니다.
#---------------------------------------------------------------------
#HAProxy Monitoring Config
#---------------------------------------------------------------------
listen stats
bind *:1936
mode http
option forwardfor
option httpclose
stats enable
stats uri /
stats refresh 5s
stats show-legends
stats realm Haproxy\ Statistics
전체 예
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# setup logging and force level to debug. Logs require rsyslog be setup.
chroot /var/lib/haproxy
log /dev/log local0 debug
# maximum number of connections allowed
maxconn 10000
# turn on stats unix socket
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
# user and group haproxy will run as
user haproxy
group haproxy
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
default-server init-addr last,libc,none
log global
mode http
option httplog
option redispatch
option forwardfor
timeout connect 10s
timeout client 60s
timeout server 60s
timeout tunnel 1h
#---------------------------------------------------------------------
# FrontEnd Configuration
#---------------------------------------------------------------------
frontend ft_web
bind *:8080 name web
# log the session cookie if passed
capture cookie JSESSIONID= len 32
## path based routing to connection server
acl path_cxserver path -i -m beg /Thingworx/WS
acl path_tunnelserver path -i -m beg /Thingworx/WSTunnelServer
acl path_tunnelclient path -i -m beg /Thingworx/WSTunnelClient
use_backend cxserver if path_cxserver or path_tunnelserver or path_tunnelclient
# default traffic to platform
default_backend platform
#---------------------------------------------------------------------
# BackEnd Platform Configuration
#---------------------------------------------------------------------
backend platform
balance roundrobin
# sticky sessions
cookie SERVER insert indirect nocache
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
# health check
option httpchk GET /Thingworx/health
# configure platform instances
server platform1 10.0.10.10:8080 check inter 1000 fastinter 1000" cookie twx1
server platform2 10.0.10.11:8080 check inter 1000 fastinter 1000" cookie twx2
#---------------------------------------------------------------------
# BackEnd Connection Server Configuration
#---------------------------------------------------------------------
backend cxserver
balance source
#hash-type consistent
option httpchk GET /
# configure connection server instances
server cxserver1 10.0.10.20:8080 check port 9009
server cxserver2 10.0.10.21:8080 check port 9009
#---------------------------------------------------------------------
#HAProxy Monitoring Config
#---------------------------------------------------------------------
listen stats
bind *:1936
mode http
option forwardfor
option httpclose
stats enable
stats uri /
stats refresh 5s
stats show-legends
stats realm Haproxy\ Statistics
도움이 되셨나요?