본문 바로가기
Linux/OpenShift

RHOCP Installation (6) - HAProxy + KeepAlived 이중화 구성

by LILO 2023. 7. 23.
반응형

INTRO

아래의 구성에서 Bastion 서버에 HAProxy를 구축할 예정입니다.

이중화 구성은 HAProxy를 Active-Active 구조로 양 쪽 서버에 모두 실행중으로 만들 예정입니다.

 

 

 

HAProxy 설치

Bastion 서버에 HAProxy를 구축할 예정입니다.

HAProxy는 HW LB를 대체하는 SW LB로 L4(Layer 4), L7(Layer 7)를 지원하는 오픈소스 SW LB입니다.

 

Nginx로 LB 역할을 대체할 수 있지만 RedHat Docs에 예시로 나와있는 HAProxy를 이용하여 Ingress router, API Server, MC(Machine Config) Server에 대하여 LB의 부하분산 기능(Round Robin)을 사용하려고 합니다.

 

Installing a user-provisioned bare metal cluster on a restricted network - Installing on bare metal | Installing | OpenShift Con

alibabacloud, aws, azure, gcp, ibmcloud, nutanix, openstack, ovirt, powervs, vsphere, or {}

docs.openshift.com

 

HAProxy를 설치합니다.

# dnf install haproxy

HAProxy 설정과 관련된 파일을 백업합니다.

# cp /etc/haproxy/haproxy.cfg  /etc/haproxy/haproxy.cfg_bak

RHOCP(OpenShift)의 Ingress router, API Server, MC(Machine Config) Server를 대상으로 부하분산 설정을 합니다.

# cat << EOF > /etc/haproxy/haproxy.cfg
global
  log         127.0.0.1 local2
  pidfile     /var/run/haproxy.pid
  maxconn     4000
  daemon

defaults
  mode                    http
  log                     global
  option                  dontlognull
  option http-server-close
  option                  redispatch
  retries                 3
  timeout http-request    10s
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout http-keep-alive 10s
  timeout check           10s
  maxconn                 3000

# K8s API Server
listen api-server-6443
    bind *:6443
    mode tcp
    server bootstrap bootstrap.ocp4.example.com:6443 check  ## Master node 설치 완료 후 주석
    server master1 master1.ocp4.example.com:6443 check inter 1s
    server master2 master2.ocp4.example.com:6443 check inter 1s
    server master3 master3.ocp4.example.com:6443 check inter 1s

# RHOCP MC Server
listen machine-config-server-22623
    bind *:22623
    mode tcp
    server bootstrap bootstrap.ocp4.example.com:22623 check  ## Master node 설치 완료 후 주석
    server master1 master1.ocp4.example.com:22623 check inter 1s
    server master2 master2.ocp4.example.com:22623 check inter 1s
    server master3 master3.ocp4.example.com:22623 check inter 1s

# RHOCP Ingress Router for 443 port
listen ingress-router-443
    bind *:443
    mode tcp
    balance source
    server worker1 worker1.ocp4.example.com:443 check inter 1s
    server worker2 worker2.ocp4.example.com:443 check inter 1s

# RHOCP Ingress Router for 80 port
listen ingress-router-80
    bind *:80
    mode tcp
    balance source
    server worker1 worker1.ocp4.example.com:80 check inter 1s
    server worker2 worker2.ocp4.example.com:80 check inter 1s
EOF

bastion2번 서버도 HAProxy를 설치하고 HAProxy 설정 파일을 백업합니다.

(이 예시는 SSH 명령을 이용하여 명령어를 입력하였고 bastion2번 서버에 직접 접속해서 진행하여도 무관합니다.)

# ssh root@bastion2.ocp4.example.com  "dnf install -y haproxy"
# ssh root@bastion2.ocp4.example.com  "cp /etc/haproxy/haproxy.cfg  /etc/haproxy/haproxy.cfg_bak"

SCP 명령어를 이용하여 bastion1번에서 작성한 HAProxy 설정 파일을 2번으로 전송합니다.

(반복적인 수동 작업 줄이려고 원격지로 복사하는 방안으로 진행하였습니다.)

# scp /etc/haproxy/haproxy.cfg   root@bastion2.ocp4.example.com:/etc/haproxy/

bastion1번, bastion2번 서버 모두 HAProxy 데몬을 enable 시키고 기동합니다.

# systemctl enable --now haproxy

HAProxy 데몬 상태와 Port Listen 상태를 확인합니다.

# systemctl is-active haproxy
active

# netstat -atnlp |grep -i haproxy
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1363669/haproxy
tcp        0      0 0.0.0.0:22623           0.0.0.0:*               LISTEN      1363669/haproxy
tcp        0      0 0.0.0.0:6443            0.0.0.0:*               LISTEN      1363669/haproxy
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1363669/haproxy

 

Q: HAProxy 데몬 기동이 실패되거나 Activating 상태에서 Hang이 걸려요

- HAProxy 설정 파일 재확인

- DNS Zone 파일 레코드 재확인

- 방화벽 및 SELinux Disable 확인

- HAProxy에 설정한 DNS에 대한 A 레코드 IP가 ping이 나가지 않는 경우 Activating 상태에서 Hang이 걸릴 수도 있습니다.

 

 

 

KeepAlived 구축 (bastion1번 서버)

KeepAlived를 이용하여 HAProxy와 named 서비스가 지속적으로 Active 상태를 유지하고 VIP를 사용하여 서버에 fault가 발생하여도 사용자가 이용하는데 불편이 없게 하는 것이 최종 목표입니다.

 

KeepAlived 패키지를 설치합니다.

# dnf install keepalived

KeepAlived와 관련된 설정 파일을 백업합니다.

# cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf_bak

Active 서버에 대한 설정을 작성합니다.

vvrp_script 기능을 이용하여 HAProxy에 대한 데몬 상태를 확인하여 이상이 생기면 Standby 서버로 Failover하는 설정을 추가하였습니다. (# echo $?  : 0은 정상   나머지는 비정상)

nopreempt 옵션을 추가하여 Active 서버가 살아나도 VIP가 Auto Failback되지 않게 하는 설정을 추가합니다.

master, backup로 전환시, HAProxy 데몬 이상 감지시(vvrp_check) 스크립트가 동작하는 notify 설정 추가하였습니다.

# cat << EOF > /etc/keepalived/keepalived.conf
vrrp_script check_haproxy
{
    script "/usr/bin/systemctl is-active --quiet haproxy"
    interval 5
    fall 2
    rise 2
}

vrrp_instance OCP {
    state BACKUP
    interface ens3
    virtual_router_id 50
    priority 200
    advert_int 5
    nopreempt
    authentication {
        auth_type PASS
        auth_pass passwd123
    }
    virtual_ipaddress {
    192.168.56.29/24
    }
    track_script
    {
        check_haproxy
    }

    notify_master /etc/keepalived/start.sh
    notify_backup /etc/keepalived/start.sh
    notify_fault /etc/keepalived/start.sh
}
EOF

notify에 설정된 스크립트를 작성합니다.

HAProxy 데몬이 Active 상태가 아닐 경우, master 및 backup router로 전환시에 HAProxy, named 서비스가 실행되게 설정하여 서버가 종료되지 않는다면 양 쪽 서버에 모두 HAProxy와 named가 실행될 수 있게 설정하였습니다. (Active-Active)

# cat << EOF > /etc/keepalived/start.sh
#!/bin/sh

systemctl start haproxy
systemctl start named
EOF

Keepalived 데몬을 실행합니다.

# systemctl enable --now keepalived

 

 

KeepAlived 구축 (bastion2번 서버)

KeepAlived 패키지를 설치합니다.

# dnf install keepalived

KeepAlived와 관련된 설정 파일을 백업합니다.

# cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf_bak

BACKUP 서버에 대한 설정을 작성합니다.

cat << EOF > /etc/keepalived/keepalived.conf
vrrp_script check_haproxy
{
    script "/usr/bin/systemctl is-active --quiet haproxy"
    interval 5
    fall 2
    rise 2
}

vrrp_instance OCP-CONSOLE {
    state BACKUP
    interface ens3
    virtual_router_id 50
    priority 100
    advert_int 5
    nopreempt
    authentication {
        auth_type PASS
        auth_pass passwd123
    }
    virtual_ipaddress {
    192.168.56.29/24
    }
    track_script
    {
        check_haproxy
    }

    notify_master /etc/keepalived/start.sh
    notify_backup /etc/keepalived/start.sh
    notify_fault /etc/keepalived/start.sh
}

notify에 설정된 스크립트를 작성합니다.

# cat << EOF > /etc/keepalived/start.sh
#!/bin/sh

systemctl start haproxy
systemctl start named
EOF

Keepalived 데몬을 실행합니다.

# systemctl enable --now keepalived

 

KeepAlived 구성 후 상태 확인

양 쪽 서버에 모두 데몬 실행이 정상적으로 완료되었으면 Active 서버에 VIP가 등록된 것을 확인할 수 있습니다.

# ip a |grep inet |grep ens3
    inet 192.168.56.30/24 brd 192.168.30.255 scope global noprefixroute ens3
    inet 192.168.56.29/24 scope global secondary ens3

 

반응형