"HAProxy"의 두 판 사이의 차이

오픈소스 비즈니스 컨설팅
둘러보기로 가기 검색하러 가기
잔글
잔글
 
(같은 사용자의 중간 판 7개는 보이지 않습니다)
1번째 줄: 1번째 줄:
 
LoadBalance와 Proxy 기능을 제공하는 HAProxy를 정리 합니다.
 
LoadBalance와 Proxy 기능을 제공하는 HAProxy를 정리 합니다.
*홈페이지 :  
+
 
*다운로드 :  
+
*홈페이지 : http://www.haproxy.org/, [https://github.com/cbonte/haproxy-dconv https://github.com/cbonte/haproxy-dconv]
*라이선스 :  
+
**매뉴얼 : [http://cbonte.github.io/haproxy-dconv/index.html http://cbonte.github.io/haproxy-dconv/index.html]
*플랫폼   :  
+
**[http://cbonte.github.io/haproxy-dconv/configuration-1.5.html http://cbonte.github.io/haproxy-dconv/configuration-1.5.html]
 +
**[http://cbonte.github.io/haproxy-dconv/configuration-1.4.html http://cbonte.github.io/haproxy-dconv/configuration-1.4.html]
 +
*다운로드 : http://www.haproxy.org/#down
 +
*라이선스 : [[GNU GPLv2|GNU GPLv2]], ...
 +
*플랫폼  : C
  
 
== HAProxy 개요 ==
 
== HAProxy 개요 ==
42번째 줄: 46번째 줄:
  
 
== HAProxy 설정 ==
 
== HAProxy 설정 ==
 +
 +
=== HAProxy 1.4.24 기본 설정 ===
 +
 +
vi /etc/haproxy/haproxy.cfg
 +
 +
{| cellspacing="1" cellpadding="1" style="color: rgb(0, 0, 0); font-family: sans-serif; line-height: 20.7999992370605px; width: 859px;"
 +
|-
 +
| style="background-color: rgb(241, 241, 241);" |
 +
global &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- Global 설정<br/>&nbsp; &nbsp; log &nbsp; &nbsp; &nbsp; &nbsp; 127.0.0.1 local2
 +
 +
&nbsp; &nbsp; chroot &nbsp; &nbsp; &nbsp;/var/lib/haproxy<br/>&nbsp; &nbsp; pidfile &nbsp; &nbsp; /var/run/haproxy.pid<br/>&nbsp; &nbsp; maxconn &nbsp; &nbsp; 4000<br/>&nbsp; &nbsp; user &nbsp; &nbsp; &nbsp; &nbsp;haproxy<br/>&nbsp; &nbsp; group &nbsp; &nbsp; &nbsp; haproxy<br/>&nbsp; &nbsp; daemon
 +
 +
&nbsp; &nbsp; stats socket /var/lib/haproxy/stats
 +
 +
defaults &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- Default 설정<br/>&nbsp; &nbsp; mode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- 처리할 프로토콜 지정 (http, tcp)<br/>&nbsp; &nbsp; log &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; global<br/>&nbsp; &nbsp; option &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;httplog<br/>&nbsp; &nbsp; option &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dontlognull<br/>&nbsp; &nbsp; option http-server-close<br/>&nbsp; &nbsp; option forwardfor &nbsp; &nbsp; &nbsp; except 127.0.0.0/8<br/>&nbsp; &nbsp; option &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;redispatch<br/>&nbsp; &nbsp; retries &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3<br/>&nbsp; &nbsp; timeout http-request &nbsp; &nbsp;10s<br/>&nbsp; &nbsp; timeout queue &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1m<br/>&nbsp; &nbsp; timeout connect &nbsp; &nbsp; &nbsp; &nbsp; 10s<br/>&nbsp; &nbsp; timeout client &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1m<br/>&nbsp; &nbsp; timeout server &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1m<br/>&nbsp; &nbsp; timeout http-keep-alive 10s<br/>&nbsp; &nbsp; timeout check &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10s<br/>&nbsp; &nbsp; maxconn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3000
 +
 +
frontend &nbsp;main *:5000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- 모든 IP의 5000 port 요청에 대한 처리 설정<br/>&nbsp;&nbsp; &nbsp;#--- 시작 url과 종료 url로 url_static를 설정 합니다.<br/>&nbsp; &nbsp; acl url_static &nbsp; &nbsp; &nbsp; path_beg &nbsp; &nbsp; &nbsp; -i /static /images /javascript /stylesheets<br/>&nbsp; &nbsp; acl url_static &nbsp; &nbsp; &nbsp; path_end &nbsp; &nbsp; &nbsp; -i .jpg .gif .png .css .js
 +
 +
&nbsp; &nbsp; use_backend static &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if url_static &nbsp; &nbsp; &nbsp; &nbsp; #--- url_static 요청은 static backend에서 처리 합니다.<br/>&nbsp; &nbsp; default_backend &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; app &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#--- Default 요청은 app backend에서 처리 합니다.
 +
 +
backend static &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- static backend 설정<br/>&nbsp; &nbsp; balance &nbsp; &nbsp; roundrobin<br/>&nbsp; &nbsp; server &nbsp; &nbsp; &nbsp;static 127.0.0.1:4331 check
 +
 +
backend app &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- app backend 설정<br/>&nbsp; &nbsp; balance &nbsp; &nbsp; roundrobin<br/>&nbsp; &nbsp; server &nbsp;app1 127.0.0.1:5001 check<br/>&nbsp; &nbsp; server &nbsp;app2 127.0.0.1:5002 check<br/>&nbsp; &nbsp; server &nbsp;app3 127.0.0.1:5003 check<br/>&nbsp; &nbsp; server &nbsp;app4 127.0.0.1:5004 check
 +
 +
|}
 +
 +
=== Load Balance 설정 ===
 +
 +
vi /etc/haproxy/haproxy.cfg
 +
 +
{| cellspacing="1" cellpadding="1" style="line-height: 20.7999992370605px; color: rgb(0, 0, 0); font-family: sans-serif; width: 859px;"
 +
|-
 +
| style="background-color: rgb(241, 241, 241);" |
 +
<font color="#333333" face="sans-serif, Arial, Verdana, Trebuchet MS">frontend &nbsp;main *:5000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- 모든 IP의 5000 port 요청에 대한 처리 설정<br/>&nbsp;&nbsp; &nbsp;#--- 시작 url과 종료 url로 url_static를 설정 합니다.<br/>&nbsp; &nbsp; acl url_static &nbsp; &nbsp; &nbsp; path_beg &nbsp; &nbsp; &nbsp; -i /static /images /javascript /stylesheets<br/>&nbsp; &nbsp; acl url_static &nbsp; &nbsp; &nbsp; path_end &nbsp; &nbsp; &nbsp; -i .jpg .gif .png .css .js<br/>&nbsp;&nbsp; &nbsp;</font>acl is_ossbiz&nbsp;hdr_end(host) -i www.ossbiz.co.kr&nbsp; &nbsp;#--- 호스트명
 +
 +
<font color="#333333" face="sans-serif, Arial, Verdana, Trebuchet MS">&nbsp; &nbsp; use_backend static &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if url_static &nbsp; &nbsp; &nbsp; &nbsp; #--- url_static 요청은 static backend에서 처리 합니다.<br/>&nbsp;&nbsp; &nbsp;use_backend ossbiz &nbsp; &nbsp; &nbsp; &nbsp; if is_ossibz &nbsp; &nbsp; &nbsp; &nbsp;#--- is_ossbiz 요청은 ossbiz backend에서 처리 합니다.<br/>&nbsp; &nbsp; default_backend &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jopenbusiness&nbsp; &nbsp; &nbsp;#--- Default 요청은 jopenbusiness backend에서 처리 합니다.</font>
 +
 +
<font color="#333333" face="sans-serif, Arial, Verdana, Trebuchet MS">backend static &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- static backend 설정<br/>&nbsp; &nbsp; balance &nbsp; &nbsp; roundrobin<br/>&nbsp; &nbsp; server &nbsp; &nbsp; &nbsp;static 127.0.0.1:4331 check</font>
 +
 +
<font color="#333333" face="sans-serif, Arial, Verdana, Trebuchet MS">backend ossbiz<br/>&nbsp;&nbsp; &nbsp;balance &nbsp; &nbsp; roundrobin<br/>&nbsp;&nbsp; &nbsp;server &nbsp;ossbiz01 127.0.0.1:8101 check</font>
 +
 +
<font color="#333333" face="sans-serif, Arial, Verdana, Trebuchet MS">backend jopenbusiness&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #--- app backend 설정<br/>&nbsp; &nbsp; balance &nbsp; &nbsp; roundrobin<br/>&nbsp; &nbsp; server &nbsp;app1 127.0.0.1:8001&nbsp;check<br/>&nbsp; &nbsp; server &nbsp;app2 127.0.0.1:8002&nbsp;check</font>
 +
 +
|}
 +
 +
=== Cluster 설정 ===
 +
 +
ppp
  
 
== 참고 문헌 ==
 
== 참고 문헌 ==

2015년 6월 19일 (금) 09:17 기준 최신판

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

참고 문헌