반응형

 

* selinux 및 firewalld를 disabled 후 진행 했습니다.

 

  • HAProxy URL based routing & load balancing  (haproxy 로드밸런싱, haproxy 라우팅)

  • haproxy 설치
yum -y install haproxy

 

  • /etc/haproxy/haproxy.cfg 설정 파일 수정 (환경에 따라 도메인 및 routing 또는 loadbalancing으로 써있는 부분을 바꿔서 맞춰주면 됩니다.)
defaults
        log     global
        log 127.0.0.1 local2
        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 http
        bind *:80
        acl routing hdr(host) -i routing.nirsa.com
        acl loadbalancing hdr(host) -i loadbalancing.nirsa.com  
        use_backend routing if routing
        use_backend loadbalancing if loadbalancing
        
# 1. URL Based Routing
backend routing
        option httpclose
        option forwardfor
        server routing 10.10.10.10:80

# 2. URL Based LoadBalancing  
backend loadbalancing
        mode http
        stats enable
        stats hide-version
        stats uri /stats
        stats realm Haproxy\ Statistics
        
        # monitoring:monitoring은 loadbalancing.nirsa.com/stats (세션 등 모니터링 페이지)
        ## 도메인에 입력될 ID/PW 이므로 변경 후 사용 해야 합니다.
        stats auth monitoring:monitoring
        
        # 로드밸런싱 방식은 roundrobin으로 사용 했습니다.
        balance roundrobin
        option httpclose
        option forwardfor
        cookie LB insert
        server test-01 10.10.10.20:80 check
        server test-02 10.20.10.30:80 check

 

위와 같이 설정이 끝났다면 서비스 재시작 하고 DNS서버에 웹서버의 A레코드를 HAProxy IP로 변경 후 재대로 라우팅 및 로드밸런싱이 되는지 확인 하시면 됩니다. 참고로, haproxy의 로그는 /var/log/haproxy.log에 남겨지니 참고 하시길 바랍니다.

systemctl restart haproxy
systemctl enable haproxy

 

반응형

+ Recent posts