[개발자가 하는 일 8] 로드밸런싱을 위한 Haproxy
이전화에 도메인에 대해 알아보았습니다.
이제 도메인과 IP를 연결(각 도메인 회사마다 조금씩 차이가 있어 생략합니다)
각 회사의 DNS 설정을 통해 진행하였습니다.
이제 mobileflow.co.kr 로 접속하게 되면 특정 IP로 이동하도록 DNS설정을 해두었습니다.
예를 들어 우리가 mobileflow.co.kr 을 치게되면 아래 그림과 같은 흐름으로 이동하게 됩니다.
그동안 설치했던 익숙한 그림들을 바탕으로 처음 보는 프로그램이 하나 있습니다.
바로 Haproxy입니다. Haproxy에 대한 개념은 아래의 주소가 정리가 잘되어 있습니다.
http://d2.naver.com/helloworld/284659
Haproxy에 대한 개념은 위의 링크를 참고하고 설치는 간단한 Yum으로 진행하겠습니다.
1) Haproxy Yum 설치
[root@mobileflow ~]# yum -y install haproxy
2) 설치 위치 확인
[root@mobileflow ~]# whereis haproxy
haproxy: /usr/sbin/haproxy /etc/haproxy /usr/local/sbin/haproxy /usr/share/haproxy /usr/share/man/man1/haproxy.1.gz
3) 설정 파일 확인
[root@mobileflow haproxy]# ls /etc/haproxy
haproxy.cfg
4) 설정 수정
[root@mobileflow haproxy]# vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
#
#
# 가이드 문서 주소
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
log 127.0.0.1 local2 #로그설정
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
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 #최대 동접 설정
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend PassThrough1 #
acl url_static path_beg -i /static /images /javascript /stylesheets /css /js /imgs
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend static
frontend http-in
mode http
bind *:80
option httplog
acl host_sub1 hdr(host) -i mobileflow-homepage.s3.ap-northeast-2.amazonaws.com/uploads/img/www
acl host_sub3 hdr(host) -i www.mobileflow.co.kr
acl host_sub5 hdr(host) -i demo.mobileflow.co.kr
use_backend static if host_sub1
use_backend main_app if host_sub3
use_backend demo_app if host_sub5
stats enable #통계
stats hide-version
stats uri /stats
stats realm Haproxy\ Statistics
stats auth haproxy:admin
default_backend main_app #기본 설정
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static #이미지 서버 설정
balance roundrobin
server static 127.0.0.1:4000 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend www_cluster #mobileflow.co.kr로 접속하면 www로 이동시켜준다.
option forwardfor except 127.0.0.1 header My-X-Forwarded-For
redirect prefix http://www.mobileflow.co.kr code 301 if { hdr(host) -i mobileflow.co.kr }
backend main_app #메인 웹 어플리케이션 서버
option forwardfor except 127.0.0.1 header My-X-Forwarded-For
balance roundrobin
server app1 127.0.0.1:8080 check
backend demo_app #데모서버
balance roundrobin
server app1 127.0.0.1:8081 check
5) Haproxy 시작
[root@mobileflow haproxy]# service haproxy start
Starting haproxy: [ OK ]

이전 내용은 이곳에서 보시면 됩니다.
[개발자가 하는 일 1] 서버 구축에 앞서..
[개발자가 하는 일 3] 본격적인 서버 구축 - 기본 설정 및 확인
[개발자가 하는 일 4] 본격적인 서버 구축 - vsftpd설치
[개발자가 하는 일 5] 본격적인 서버 구축 - 웹 서버 설치
[개발자가 하는 일 6] 본격적인 서버 구축 - 웹 어플리케이션 서버 설치
[개발자가 하는 일 7] 본격적인 서버 구축 - 도메인과 서브도메인