2013년 7월 22일 월요일

HAProxy 설치

HAProxy 설치

  1. HAProxy의 구조
Figure 1 HAProxy의 연동구조
본 문서는 아래의 페이지를 참고하여 작성되었다.
HAProxy는 연속적이거나 L7 레벨의 처리가 필요로 하는 부하가 많은 웹 사이트에 적합하며, TCP, HTTP기반 애플리케이션을 위해 HA, 로드밸런싱, 프록시 기능을 제공한다.

  1. 계정 생성
계정 설정은 반드시 해야 할 필요는 없다.
groupadd -g 3322 haproxy
useradd -m -d /usr/local/haproxy -s /bin/bash -u 3322 -g 3322 haproxy

  1. 프로그램 설치
현재 최신 release는 1.5-dev19 이며 아래 사이트에서 다운로드 받을 수 있다.

프로그램을 설치하기 전에 dependency 패키지를 설치해준다.
apt-get install gcc

다음을 실행하여 컴파일과 파일 설치를 완료한다. (아래의 경우는 리눅스 64비트에 설치 예임)
make TARGET=linux2628 ARCH=-m64
sudo make install



  1. 설정
설치 후, config file을 설정한다. (링크는 1.5버전의 매뉴얼참조)

config 과정은 3가지의 주요 항목을 포함한다.
  1. 커맨드라인의 옵션 파라미터가 config 설정내역보다 항상 먼저 적용된다.
  2. global섹션은 프로세스 전체적으로 사용된다.
  3. proxies 섹션은 defaults, listen, frontend, backend 항목을 사용할 수 있다.
config의 문법은 매뉴얼에서 제공하는 키워드로 시작하고, 선택적으로 한 개 이상의 공백으로 구분된 파라미터를 설정 할 수 있다. 문자열 사이에 공백이 필요하면 백슬러시(‘\’)를 사용한다. 백슬러시 문자를 넣기 위해서는 백슬러시를 두 개(‘\\’) 사용한다

A) 시간설정
몇몇 파라미터는 시간을 입력하게 되어있다. 보통 밀리초를 사용하지만, 시간 단위 키워드를 사용할 수 있다. 다음은 옵션으로 설정할 수 있는 시간 단위이다.
us
microseconds. 1 microsecond = 1/1000000 second
ms
milliseconds. 1 millisecond = 1/1000 second. This is the default.
s
seconds. 1s = 1000ms
m
minutes. 1m = 60s = 60000ms
h
hours.   1h = 60m = 3600s = 3600000ms
d
days.    1d = 24h = 1440m = 86400s = 86400000ms



B) proxy 섹션
defaults
A "defaults" section sets default parameters for all other sections following
its declaration. Those default parameters are reset by the next "defaults"
section. See below for the list of parameters which can be set in a "defaults" section. The name is optional but its use is encouraged for better readability

frontend

A "frontend" section describes a set of listening sockets accepting client
connections.
backend
A "backend" section describes a set of servers to which the proxy will connect to forward incoming connections.
listen
A "listen" section defines a complete proxy with its frontend and backend parts combined in one section. It is generally useful for TCP-only traffic

C) 설정 예
# 모든 인터페이스에서 80포트로 들어오는 요청을, 백엔드 127.0.0.1(server1)의 8000포트로
# 포워드하는 간단한 설정 예
global
   daemon
   maxconn 256

# defaults <name>
defaults
   mode http
   timeout connect 5000ms
   timeout client 50000ms
   timeout server 50000ms

# frontend <name>
frontend http-in
   bind *:80
   # default_backend <backend>
   default_backend servers

# backend  <name>
backend servers
   #
server <name> <address>[:[port]] [param*]
   server server1 127.0.0.1:8000 maxconn 32

아래와 같이 설정 할 수도 있다.
# The same configuration defined with a single listen block. Shorter but
# less expressive, especially in HTTP mode.
global
   daemon
   maxconn 256

defaults
   # mode { tcp|http|health }
   mode http
   timeout connect 5000ms
   timeout client 50000ms
   timeout server 50000ms

# listen   <name>
listen http-in
   bind *:80
   server server1 127.0.0.1:8000 maxconn 32




  1. 실행
    $ sudo haproxy -f configuration.conf -c


댓글 없음:

댓글 쓰기