본문 바로가기
haproxy

haproxy balance 설정



1.haproxy balance
- haproxy 는 haproxy balancing 설정을 backend 에서 사용될 balancing 알고리즘을 설정 할 수 있으며 

1-1. roundrobin 알고리즘 
- roundrobin 으로 순서대로 blancing 된다.

# 아래 예제처럼 기존 설정에 이름이 중복 안되게 real server 를 추가 와, balance 지시자를 추가 해준다.

global
        daemon
        maxconn 256

    defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

    frontend http-in
        bind *:80
        default_backend servers

    backend servers
        balance roundrobin <- roundrobin으로 balancing 설정 
        server server1 192.168.229.135:80 <- 첫번째 접속될 real server
        server server2 192.168.229.136:80 <- 두번째 접속될 real server

## curl 테스트로 라운드로빈 되는 것을 확인 할 수 있다.
[root@NODE0 haproxy]# curl 192.168.229.138
node1
[root@NODE0 haproxy]# curl 192.168.229.138
node2
[root@NODE0 haproxy]# curl 192.168.229.138
node1
[root@NODE0 haproxy]# curl 192.168.229.138
node2

1-2. leastconn 알고리즘
- leastconn 알고리즘은 접속수가 가장 적은 서버로 balancing 되며, 해당 프로세스에서 proxy 되는 기준으로 선택 된다.

global
        daemon
        maxconn 256

    defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

    frontend http-in
        bind *:80
        default_backend servers

    backend servers
        balance leastconn <- leastconn 으로 balancing 설정 
        server server1 192.168.229.135:80
        server server2 192.168.229.136:80 <- 해당 server1,2 기준으로 가장 적은 접속수가 있는 서버로 연결 된다.


1-3 그외 알고리즘 

- static-rr 서버에 weight 가중치를 줘서 , 부여된 가중치에 따라서 연결 된다.

- source: 소스 아이피 기준으로 해싱 하여 연결된다.

- balance url_param: HTTP GET 요청에 대해서 특정 패턴이 있는지 여부 확인 후  조건에 맞는 서버로 분배(조건 없는 경우 round robin으로 처리)

- balance hdr: HTTP 헤더 에서 hdr(<name>)으로 지정된 조건이 있는 경우에 대해서만 분배

(조건 없는 경우 round robin으로 처리)


반응형