HAProxy로 Apache 이중화

cloud·2024년 11월 14일
0

Reverse Proxy

목록 보기
5/5

1. HAProxy 설치

sudo dnf install haproxy

2. HAProxy 설정 파일 구성

vim /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
    bind *:81
    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 172.27.0.254:80  check
    server  app2 172.27.0.32:80   check

bind 포트 : Apache에서 80을 사용하므로 다른 포트로 설정
backend server : Apache를 이중화할 예정이므로 Apache 서버 IP를 입력

Apache서버 모두 동일하게 설정해준다

3. keepalived 설치

sudo dnf install keepalived

4. keepalived 설정

vim /etc/keepalived/keepalived.conf

마스터 서버

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.100  # VIP 설정
    }
}

백업 서버

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.100  # VIP 설정
    }
}

5. 서비스 재시작

sudo systemctl restart httpd
sudo systemctl restart haproxy
sudo systemctl restart keepalived

0개의 댓글

관련 채용 정보