YUMSERV
article thumbnail
Published 2019. 8. 22. 01:27
haproxy 설정 LINUX/Load Balance
반응형

기본 설정파일에는 아래와 같이 설정이 되어있습니다.

# vi /etc/haproxy/haproxy.cfg

global

        log /dev/log    local0

        log /dev/log    local1 notice

        chroot /var/lib/haproxy

        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners

        stats timeout 30s

        user haproxy

        group haproxy

        daemon


        # Default SSL material locations

        ca-base /etc/ssl/certs

        crt-base /etc/ssl/private


        # Default ciphers to use on SSL-enabled listening sockets.

        # For more information, see ciphers(1SSL). This list is from:

        #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/

        # An alternative list with additional directives can be obtained from

        #  https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy

        ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS

        ssl-default-bind-options no-sslv3


defaults

        log     global

        mode    http

        option  httplog

        option  dontlognull

        timeout connect 5000

        timeout client  50000

        timeout server  50000

        errorfile 400 /etc/haproxy/errors/400.http

        errorfile 403 /etc/haproxy/errors/403.http

        errorfile 408 /etc/haproxy/errors/408.http

        errorfile 500 /etc/haproxy/errors/500.http

        errorfile 502 /etc/haproxy/errors/502.http

        errorfile 503 /etc/haproxy/errors/503.http

        errorfile 504 /etc/haproxy/errors/504.http


WEB 서버 2대, haproxy 서버 1대로 총 3대로 구성해 테스트 진행하겠습니다.


OS : Ubuntu 18.04

WEB서버 : APACHE2 

haproxy서버 : haproxy 1.8

※ WEB서버1 : 192.168.0.100

※ WEB서버2 : 192.168.0.200

※ haproxy 서버 : 192.168.0.5


WEB서버를 들어가게 되면 아래 이미지 처럼 뜹니다.




WEB서버1로 들어가면 web1로 뜨고

WEB서버2로 들어가면 web2로 뜨게됩니다.


haproxy 서버에서도 접근이 되게, curl 명령어로 테스트 진행합니다.

root@haproxy:/etc/haproxy# curl 192.168.0.100

<html><body><h1>WEB1</h1></body></html>

root@haproxy:/etc/haproxy# curl 192.168.0.200

<html><body><h1>WEB2</h1></body></html>



global : 프로세스 전체에 적용

defaults : frontend, backend, listen 3가지 선언했을 때 적용되는 옵션

frontend : 진입점 선언. 조건이 일치하는 경우 backend로 연결해주는 역할

backend : frontend가 실질적으로 연결할 server들을 선언하여 관리



설정 파일 필요한 내용만 적어놓았으며, 덧붙여 설명해놓았습니다.

# vi /etc/haproxy/haproxy.cfg

global

        log /dev/log    local0

        log /dev/log    local1 notice

        user haproxy 

        group haproxy

        daemon # 백그라운드에서 동작

        maxconn 4096 # 프로세스 별 최대 connection 갯수


defaults

        log     global

        mode    http

        option  httplog

        option  dontlognull

        timeout connect 5000

        timeout client  50000

        timeout server  50000

        errorfile 400 /etc/haproxy/errors/400.http

        errorfile 403 /etc/haproxy/errors/403.http

        errorfile 408 /etc/haproxy/errors/408.http

        errorfile 500 /etc/haproxy/errors/500.http

        errorfile 502 /etc/haproxy/errors/502.http

        errorfile 503 /etc/haproxy/errors/503.http

        errorfile 504 /etc/haproxy/errors/504.http


frontend http-in

        bind *:80 # listening 되어야 하는 IP,PORT 설정

        default_backend servers # default_backend를 servers 로 설정


backend servers

        mode http

        balance roundrobin # 분배 알고리즘을 roundrobin으로 설정

        http-check expect status 200 string OK # 응답 시 상태코드 200, 문자열 OK 확인

        server server1 192.168.0.100:80 check # 분배할 서버 ip,port 검사

        server server2 192.168.0.200:80 check # 분배할 서버 ip,port 검사


위와 같이 설정한 뒤에
# service haproxy start


haproxy 서버로 url를 접근했을 때, web1과 web2가 번갈아 뜨는것을 확인해볼 수 있습니다.


설정은 아래 사이트 참조하였습니다.

https://blog.whitelife.co.kr/321

반응형

'LINUX > Load Balance' 카테고리의 다른 글

haproxy 웹에서 통계리포트 보기  (0) 2019.08.22
CentOS - haproxy 설치  (0) 2019.08.22
Ubuntu - haproxy 설치  (0) 2019.08.22
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!