HAProxy

오픈소스 비즈니스 컨설팅
둘러보기로 가기 검색하러 가기

LoadBalance와 Proxy 기능을 제공하는 HAProxy를 정리 합니다.

HAProxy 개요

HAProxy는 L4 Switch, L7 Switch와 Load Balance 기능을 소프트웨어적으로 제공 한다. 초당 8만건의 트래픽을 처리 한다.

Load Balance 기술

  • NAT (Network Address Translation)
  • DSR (Dynamic Source Routing)
  • Tunneling


Load Balance 동작 모드

  • Bridge/Transparent Mode : 목적지 IP와 MAC 주소를 재설정
  • Router Mode : 출발지와 목적지의 IP와 MAC 주소를 재설정
  • One Arm Mode : 목적지 IP와 MAC 주소를 재설정, 응답시 IP pool의 주소를 사용
  • DSR (Direct Server Return) Mode : 목적지 MAC 주소를 재설정

HAProxy 설치

CentOS에서 HAProxy를 설치 합니다.

yum install haproxy

 service haproxy start
 #chkconfig  haproxy  on


HAProxy 설정 파일

  • /etc/haproxy/haproxy.cfg

HAProxy 설정

HAProxy 1.4.24 기본 설정

vi /etc/haproxy/haproxy.cfg

global                                                         #--- Global 설정
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    stats socket /var/lib/haproxy/stats

defaults                                                      #--- Default 설정
    mode                    http                            #--- 처리할 프로토콜 지정 (http, tcp)
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

frontend  main *:5000                                   #--- 모든 IP의 5000 port 요청에 대한 처리 설정
    #--- 시작 url과 종료 url로 url_static를 설정 합니다.
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static          if url_static         #--- url_static 요청은 static backend에서 처리 합니다.
    default_backend             app                    #--- Default 요청은 app backend에서 처리 합니다.

backend static                                             #--- static backend 설정
    balance     roundrobin
    server      static 127.0.0.1:4331 check

backend app                                               #--- app backend 설정
    balance     roundrobin
    server  app1 127.0.0.1:5001 check
    server  app2 127.0.0.1:5002 check
    server  app3 127.0.0.1:5003 check
    server  app4 127.0.0.1:5004 check

Load Balance 설정

vi /etc/haproxy/haproxy.cfg

frontend  main *:5000                                   #--- 모든 IP의 5000 port 요청에 대한 처리 설정
    #--- 시작 url과 종료 url로 url_static를 설정 합니다.
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js
    
acl is_ossbiz hdr_end(host) -i www.ossbiz.co.kr   #--- 호스트명

    use_backend static          if url_static         #--- url_static 요청은 static backend에서 처리 합니다.
    use_backend ossbiz         if is_ossibz        #--- is_ossbiz 요청은 ossbiz backend에서 처리 합니다.
    default_backend             jopenbusiness     #--- Default 요청은 jopenbusiness backend에서 처리 합니다.

backend static                                             #--- static backend 설정
    balance     roundrobin
    server      static 127.0.0.1:4331 check

backend ossbiz
    balance     roundrobin
    server  ossbiz01 127.0.0.1:8101 check

backend jopenbusiness                                #--- app backend 설정
    balance     roundrobin
    server  app1 127.0.0.1:8001 check
    server  app2 127.0.0.1:8002 check

Cluster 설정

ppp

참고 문헌