'haproxy'에 해당되는 글 1건

  1. 2017.09.11 HAproxy 설치하기
카테고리 없음2017. 9. 11. 21:39

출처 : http://livegs.tistory.com/43

 

HAproxy는 고가용성 프록시를 의미합니다. 

이름에서도 알 수 있다시피 High Availability proxy 입니다

C 언어로 작성되었으며 무료 오픈소스 프로그램입니다. 

HAproxy는 TCP / HTTP 로드 밸런서로 프록시 솔루션에 사용됩니다. 

HAproxy의 일반적인 용도는 웹서버, DB 서버 등 부하를 분산시키는 용도로 많이 사용되고 있습니다.

BSD, 리눅스, 솔라리스 등에서 사용할 수 있으며, 물론 윈도우는 안됩니다. (-0-;)

(여담이지만, 윈도우는 뭐 다 돈이네요 ;;;)


**********************************************************************************************************

* 환경

OS : Ubuntu 16.04.1 LTS

HAproxy : 1.6.7

WebServer : Apache/2.4.18 (Ubuntu)

VM : VirtualBox 5.1.2


* 참고

sudo 로 진행하지 않고 root 로 진행합니다.

**********************************************************************************************************

* 준비사항

VM 환경에서 진행되며, 로드밸런서이기 때문에

HAproxy 를 설치할 VM 하나, 웹서버 VM 2개를 먼저 준비합니다.

VM 을 만드는 부분은 여기서 설명하지 않습니다.

VM 의 상세 내역은 아래와 같습니다.


VM

OS

IP

Hostname

HAproxy

Ubuntu 16.04.1 LTS 64bit

172.16.1.5

HAproxy

 Webserver01

Ubuntu 16.04.1 LTS 64bit

172.16.1.15

webserver-01

Webserver02

Ubuntu 16.04.1 LTS 64bit

172.16.1.16

webserver-02

 


**********************************************************************************************************


1. Apache 설치

# apt-get install apache2 

  - 모든 VM 에 apache 를 모두 설치합니다.


2. HAproxy 저장소 등록 및 업데이트

# apt-add-repository ppa:vbernat/haproxy-1.6

# apt-get update


3. HAproxy 설치

# apt-get install haproxy


4. haproxy.cfg 수정

# vi /etc/haproxy/haproxy.cfg


global

        #log /dev/log   local0

        #log /dev/log   local1 notice

        log 127.0.0.1 local2

        chroot /var/lib/haproxy

        stats socket /run/haproxy/admin.sock mode 660 level admin

        stats timeout 30s

        user haproxy

        group haproxy

        daemon

 . . .


위처럼 log 를 주석처리 해주고 log 127.0.0.1 local2 를 입력해 줍니다.


5. rsyslog.conf 파일 수정

# vi /etc/rsyslog.conf


$ModLoad imudp

$UDPServerRun 514 


파일에 위 부분이 주석처리 되어 있다면 주석을 풀어주시고 없다면 입력해 줍니다.


6. haproxy.conf 파일 생성하고 내용 추가

# vi /etc/rsyslog.d/haproxy.conf


 

local2.*        /var/log/haproxy.log

 

 


7. rsyslog 서비스 재시작

# service rsyslog restart


8. haproxy.cfg 수정

# vi /etc/haproxy/haproxy.cfg


defaults

        log     global

        mode    http

        option  httplog

        option  dontlognull

        option  http-server-close

        option  forwardfor except 127.0.0.0/8

        option  redispatch

        retries 3

        timeout http-request    20

        timeout queue            86400

        timeout connect          86400

        timeout client             86400

        timeout server             86400

        timeout http-keep-alive 30

        timeout check             20

        maxconn                    50000 


frontend LB

        bind 172.16.1.5:80

        reqadd X-Forwarded-Proto:\ http

        default_backend bkLB


backend bkLB

        mode http

        stats enable

        stats hide-version

        stats uri /stats

        stats realm Haproxy\ Statistics

        stats auth haproxy:admin

        balance roundrobin

        option httpchk

        option httpclose

        option forwardfor

        cookie LB insert

        server webserver-01 172.16.1.15:80 cookie webserver-01 check

        server webserver-02 172.16.1.16:80 cookie webserver-02 check



10. HAproxy 재시작

# service haproxy restart


11. 시스템 시작시 자동으로 시작하기 위해 파일 수정

# vi /etc/default/haproxy


ENABLED=1 

 



12. 정상적으로 동작하는지 확인하기 위해 웹서버 index.html 를 수정

- webserver-01 에서

# mv /var/www/html/index.html /var/www/html/index.html.backup

# vi /var/www/html/index.html

webserver-01 

 


- webserver-02 에서

# mv /var/www/html/index.html /var/www/html/index.html.backup

# vi /var/www/html/index.html

webserver-02


13. 로드밸런싱이 되는지 확인

# curl 172.16.1.5

webserver-01

# curl 172.16.1.5

webserver-02

# curl 172.16.1.5

webserver-01

# curl 172.16.1.5

webserver-02


위 처럼 roundrobin 형식으로 정상적으로 나오는지 확인


14. HAproxy 통계 페이지 확인

- 웹브라우저에서 172.16.1.5/stats 를 입력

  로그인 화면에서 haproxy / admin 으로 로그인






* 참고

hosts 파일 수정


127.0.0.1       localhost

127.0.1.1       HAproxy


# The following lines are desirable for IPv6 capable hosts

::1     localhost ip6-localhost ip6-loopback

ff02::1 ip6-allnodes

ff02::2 ip6-allrouter


172.16.1.15  webserver-01

172.16.1.16  webserver-02 





출처: http://livegs.tistory.com/43 [if (feel)]

출처: http://livegs.tistory.com/43 [if (feel)]

Posted by 배움나눔