23.06.15
DEVOTEE를 활성화 시키면
지금 작성한 커뮤니티 글에 대해 1개의 댓글을 달아줍니다.
버튼을 누르면 글 수정 시 ChatGPT가 작성한 댓글이 수정됩니다.
| 컨텐츠 유형 | 제목 | 저장일 | 삭제 |
|---|
본인인증 로그인에 실패하였습니다.
회원이 아니시거나 본인인증 등록이
완료되지 않은 사용자입니다.
소개 내용 수준: Production Ready
아래 구성 방법은 SKT 내부에서 이미 검증 되었으며, Production 적용에 적합합니다.
Pacemaker
고가용성(HA) 도구에서 Pacemaker는 Keepalived 는 가장 널리 사용되고 있는 구성요소 입니다.
저는 2가지 모두 사용하고 있는데요..
간단한 TCP Load Balancing에는 Keepalived를 사용하고,
Kubernetes, Hadoop Echo System 내부 서비스 등...
복잡한 API 라우팅을 위해 Pacemaker/HAProxy 조합을 사용하고 있습니다.
이 둘은 고가용성(HA) 구축 시 항상 비교되는 도구들 인데요...
GPT-4o에게 둘의 장단점을 물어보았습니다.
Pacemaker와 Keepalived는 고가용성(HA) 클러스터 환경에서 자주 사용되는 두 가지 소프트웨어입니다.
각자의 장단점이 있으며, 특정 상황에 따라 적합한 선택이 달라질 수 있습니다. 아래에서 두 솔루션의 주요 장단점을 비교해 보겠습니다.
장점:
강력한 기능 및 유연성: Pacemaker는 복잡한 HA 환경을 지원하며, 다양한 리소스 유형과 고급 기능을 제공합니다. 이를 통해 복잡한 클러스터링 시나리오를 처리할 수 있습니다.
광범위한 리소스 에이전트: 많은 리소스 에이전트를 지원하여 다양한 애플리케이션과 서비스의 HA 구성을 쉽게 설정할 수 있습니다.
클러스터 상태 관리: 클러스터의 상태를 세밀하게 관리하고 모니터링할 수 있으며, 문제 발생 시 자동으로 조치를 취합니다.
확장성: 여러 노드를 포함한 대규모 클러스터 환경에서 안정적으로 동작합니다.
통합된 경고 및 알림 시스템: 문제 발생 시 관리자에게 경고를 보내고, 다양한 통합 옵션을 통해 신속하게 대응할 수 있습니다.
단점:
설정 복잡성: 설치 및 설정이 복잡하여, 초기 학습 곡선이 가파릅니다.
오버헤드: 비교적 무겁고 리소스 소비가 많아, 작은 규모의 클러스터에서는 과할 수 있습니다.
의존성: Corosync와 같은 다른 클러스터링 소프트웨어와 함께 사용해야 하는 경우가 많아, 설정과 관리가 복잡해질 수 있습니다.
장점:
간단한 설정: 설치 및 설정이 상대적으로 간단하며, 빠르게 구성할 수 있습니다.
경량화: 비교적 가볍고 리소스 소비가 적어, 작은 규모의 클러스터에 적합합니다.
Virtual Router Redundancy Protocol (VRRP): 기본적으로 VRRP를 사용하여 IP 페일오버를 처리하는 데 최적화되어 있습니다.
빠른 페일오버: 매우 빠른 페일오버 시간을 제공하여, IP 주소를 거의 즉시 다른 노드로 이동할 수 있습니다.
네트워크 중심: 주로 네트워크 서비스(예: 로드 밸런싱, 라우팅)의 고가용성에 적합합니다.
단점:
제한된 기능: Pacemaker에 비해 기능이 제한적이며, 복잡한 HA 시나리오를 지원하는 데 한계가 있습니다.
리소스 관리 제한: 주로 네트워크 서비스에 초점이 맞춰져 있어, 애플리케이션 레벨의 HA 설정이 어렵습니다.
확장성 한계: 대규모 클러스터 환경에서의 확장성이 제한적입니다.
제한된 모니터링 및 경고: 모니터링 및 경고 시스템이 비교적 단순하여, 복잡한 요구 사항을 충족하기 어려울 수 있습니다.
결론
Pacemaker와 Keepalived는 각기 다른 장단점을 가지고 있으며, 사용 환경과 요구 사항에 따라 적합한 솔루션이 달라질 수 있습니다.
복잡하고 다양한 애플리케이션의 고가용성을 필요로 하는 대규모 클러스터에서는 Pacemaker가 더 적합할 수 있으며,
단순하고 빠른 네트워크 서비스의 고가용성을 요구하는 작은 규모의 클러스터에서는 Keepalived가 더 적합할 수 있습니다.
와우! 생각보다 잘 정리해줘서 놀랬습니다. 잘했어~ OpenAI !
Keepalived는 설정이 너무 간단하고 설치가 쉬워서 구글링 해보면 금방 사용할 수 있다는 것을 알 수 있습니다.
반면에 Pacemaker/Corosync 및 HAProxy 의 경우, 설치과정이 복잡하고 설정 과정 역시 많은 경우의 수가 있어 쉽게 다가 가기가 힘듭니다.
특히 Pacemaker가 2 버전대로 올라가면서 Resource Failover 설정에도 변경이 생겨서 구글링 해서 나오는 상당 수 글들이 이제 먹히지 않는 경우가 많습니다.
이번 글에서는 RHEL/Rocky Linux 9 버전에서 Pacemaker/Corosync 및 HAProxy를 설치하고 사용하는 방법에 대해서 소개합니다.
구성요소 | 설치버전 |
|---|---|
OS | Rocky(RHEL) 9.4 |
HAProxy | 2.9.7 |
Pacemaker | 2.1.7 |
Corosync | 3.1.8 |
pcs | 0.11.7 |
대부분 최신버전을 사용합니다.
2대를 기준으로 설정합니다. 모두 동일한 하드웨어 스펙(Alder Lake 24 Cores/32GB RAM)을 가지고 있습니다.
연결 된 Network 는 2.5Gbps NIC이 연결되어 있습니다.
$ ip a s enp2s0
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c0:18:03:65:3f:1b brd ff:ff:ff:ff:ff:ff
inet 172.16.0.98/23 brd 172.16.1.255 scope global noprefixroute enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::d80d:676f:e7f2:b835/64 scope link noprefixroute
valid_lft forever preferred_lft forever
$ ethtool enp2s0
aiweaver@central1
Settings for enp2s0:
Supported ports: [ ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
2500baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
2500baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 2500Mb/s
Duplex: Full
Auto-negotiation: on
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
MDI-X: off (auto)
netlink error: Operation not permitted
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes2 노드에서 모두 설정합니다.
VIP 바인딩과 패킷 포워딩에 필요한 부분만 설정합니다.
참고로, Production 환경에서는 파일 디스크립터/네트워크 성능을 높일 수 있는 추가적인 튜닝을 해야 합니다.
##### 모든 노드에서 실행 #####
$ sudo systemctl disable --now firewalld
$ sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
$ sudo setenforce 0
setenforce: SELinux is disabled
$ sudo vi /etc/sysctl.conf
... 중략 ...
# Needed to bind to VIP
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2
# Enable packet forwarding.
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
$ sudo sysctl -p최신 버전의 RHEL 9 용 HAProxy를 설치합니다. 2가지 방법이 있습니다.
(방법 1) https://esnl.de/pkg/el/9/haproxy/2.9/x86_64/
(방법 2) RPM Package Repository 추가
https://esnl.de 사이트에 방문하면 repo 설정 내용을 확인할 수 있습니다.
esnl.de_haproxy.repo 를 자신이 원하는 HAProxy 버전에 맞게 /etc/yum.repos.d/ 경로 아래에 추가
##### 모든 노드에서 실행 #####
### HAProxy 2.9.x 설치
$ sudo dnf install https://esnl.de/pkg/el/9/haproxy/2.9/x86_64/haproxy-2.9.7-001.el9.x86_64.rpm
$ sudo mkdir -p /var/lib/haproxy
$ sudo chown -R haproxy: /var/lib/haproxy
### HAProxy 설정은 후반부에서 다시 설명합니다. ###
### HAProxy Daemon은 Pacemaker가 관리 할 예정이기 때문에 굳이 systemd enable 할 필요는 없음 ###Rocky/RHEL 9 에서는 최신 버전의 Pacemaker를 설치 할 수 있게 해주는 ${os-release}-addons.repo 가 없거나 있더라도 [highavailability] 섹션이 비활성화 되어 있습니다.
이 부분을 먼저 설정해겠습니다.
Rocky 9
Rocky 9의 경우 ${os-release}-addons.repo 파일은 있지만 [highavailability] 섹션이 비활성화 되어 있습니다.
전체 내용중에 앞 부분에 있는 [highavailability], [highavailability-debug], [highavailability-source] 섹션의 내용을 아래 내용으로 변경 해 줍니다.
mirrorlist 를 주석처리하고 rocky mirror 사이트 중에 KAIST 서버를 직접적으로 이용하도록 수정했습니다.
##### 모든 노드에서 실행 #####
$ sudo vi /etc/yum.repos.d/rocky-addons.repo
[highavailability]
name=Rocky Linux $releasever - High Availability
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=HighAvailability-$releasever$rltype
baseurl=https://ftp.kaist.ac.kr/$contentdir/$releasever/HighAvailability/$basearch/os/
gpgcheck=1
enabled=1
countme=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[highavailability-debug]
name=Rocky Linux $releasever - High Availability - Debug
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=HighAvailability-$releasever-debug$rltype
baseurl=https://ftp.kaist.ac.kr/$contentdir/$releasever/HighAvailability/$basearch/debug/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[highavailability-source]
name=Rocky Linux $releasever - High Availability - Source
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=HighAvailability-$releasever-source$rltype
baseurl=https://ftp.kaist.ac.kr/$contentdir/$releasever/HighAvailability/source/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
### 제대로 설정했는지 repolist 확인 ###
$ sudo dnf clean && sudo dnf repolistRHEL 9
SKT TiDC 등에서 배포되는 RHEL 9 에는 ${os-release}-addons.repo 파일이 아예 없습니다.
Red Hat Subscription-Manager를 통해 해당 repo를 추가해주거나, Rocky 9의 addons repo를 추가해줘야 합니다.
여기서는 rocky 9의 addons repo 파일을 추가하는 방식으로 진행합니다. Rocky는 RHEL Clone 이기 때문에 호환성에 문제가 없기 때문입니다.
방법은 /etc/yum.repos.d/rocky-addons.repo 파일에 아래 내용을 추가한 후에 rocky-gpg-keys 패키지를 추가로 설치 해 줘야 합니다.
##### 모든 노드에서 실행 #####
$ sudo vi /etc/yum.repos.d/rocky-addons.repo
# rocky-addons.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for Rocky updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[highavailability]
name=High Availability
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=HighAvailability-$releasever$rltype
baseurl=https://ftp.kaist.ac.kr/pub/rocky/9/HighAvailability/x86_64/os/
gpgcheck=1
enabled=1
countme=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[highavailability-debug]
name=High Availability - Debug
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=HighAvailability-$releasever-debug$rltype
baseurl=https://ftp.kaist.ac.kr/pub/rocky/9/HighAvailability/x86_64/debug/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
[highavailability-source]
name=High Availability - Source
# mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=HighAvailability-$releasever-source$rltype
baseurl=https://ftp.kaist.ac.kr/pub/rocky/9/HighAvailability/source/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
### rocky-gpg-keys 패키지를 추가로 설치 ###
$ sudo dnf install https://dl.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/Packages/r/rocky-gpg-keys-9.4-1.5.el9.noarch.rpm
### 제대로 설정했는지 repolist 확인 ###
$ sudo dnf clean && sudo dnf repolist
$ sudo dnf list | grep pacemakerPacemaker/CoroSync/PCS 설치
##### 모든 노드에서 실행 #####
$ sudo dnf install pacemaker pcs resource-agents fence-agents-all
### 위에서 설치하는 resource-agents 에는 HAProxy Agent가 원래는 있었지만
이제는 빠지게 되어 별도로 설치해줘야 합니다. ###
### HAProxy OCF Resource Agent 설치 ###
$ cd /usr/lib/ocf/resource.d/heartbeat
$ sudo curl -O https://raw.githubusercontent.com/thisismitch/cluster-agents/master/haproxy
$ sudo chmod +x haproxy
### hacluster 계정 패스워드 설정 - 암호를 알맞게 설정해주세요! ###
$ echo '!changemypassword00' | sudo passwd hacluster --stdin여기서 부터는 한 노드에서만 진행 합니다.
##### HA Cluster 노드 중 한대에서만 실행 #####
### central[1-2].aiweaver.net은 자신의 호스트에 맞게 수정합니다. ###
### 호스트명은 반드시 FQDN이 아니여도 됩니다. ###
$ sudo pcs host auth central1.aiweaver.net central2.aiweaver.net -u hacluster -p '!changemypassword00'
$ sudo pcs cluster setup aiweaver-pacemaker --start central1.aiweaver.net central2.aiweaver.net
$ sudo pcs cluster start --all
$ sudo corosync-cmapctl | egrep -i members
runtime.members.1.config_version (u64) = 0
runtime.members.1.ip (str) = r(0) ip(172.16.0.98)
runtime.members.1.join_count (u32) = 1
runtime.members.1.status (str) = joined
runtime.members.2.config_version (u64) = 0
runtime.members.2.ip (str) = r(0) ip(172.16.0.99)
runtime.members.2.join_count (u32) = 8
runtime.members.2.status (str) = joined
### 노드를 2개로 구성할 경우 quorum-policy를 ignore 로 설정 ###
$ sudo pcs property set no-quorum-policy=ignore
### Pacemaker 기본 권장 설정 ###
$ sudo pcs property set stonith-enabled=false
$ sudo pcs property set start-failure-is-fatal=true
### 설정 확인 ###
$ sudo pcs property
Cluster Properties: cib-bootstrap-options
cluster-infrastructure=corosync
cluster-name=aiweaver-pacemaker
dc-version=2.1.7-5.el9_4-0f7f88312
have-watchdog=false
last-lrm-refresh=1713877268
no-quorum-policy=ignore
stonith-enabled=false
$ sudo pcs status corosync
Membership information
----------------------
Nodeid Votes Name
1 1 central1.aiweaver.net (local)
2 1 central2.aiweaver.net$ sudo pcs property set stonith-enabled=false
### VIP와 HAProxy 리소스를 생성하고 리소스그룹으로 묶어 줍니다 ###
### 여기서는 리소스그룹을 2개를 생성합니다.
### 리소스그룹1(HAProxyGroup): K8s API HA 용 (VIP: 172.16.0.200)
리소스그룹2(HAProxyGroup2): Squid Forward Proxy 용(VIP: 172.16.0.201)
### HAProxyGroup (VIP: 172.16.0.200, Subnet: 23비트 대역, nic=enp4s0 으로 지정)
### VIP/Subnet/nic 은 자신의 서버에 맞게 수정이 필요합니다.
$ sudo pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=172.16.0.200 cidr_netmask=23 nic=enp4s0 op monitor interval=10s
$ sudo pcs resource create HAProxy systemd:haproxy
$ sudo pcs resource group add HAProxyGroup VirtualIP HAProxy
$ sudo pcs resource update HAProxy meta failure-timeout=60s
### HAProxyGroup2 (VIP: 172.16.0.201, Subnet: 23비트 대역, nic=enp4s0 으로 지정)
### VIP/Subnet/nic 은 자신의 서버에 맞게 수정이 필요합니다.
$ sudo pcs resource create VirtualIP2 ocf:heartbeat:IPaddr2 ip=172.16.0.201 cidr_netmask=23 nic=enp4s0 op monitor interval=10s
$ sudo pcs resource create HAProxy2 systemd:haproxy
$ sudo pcs resource group add HAProxyGroup2 VirtualIP2 HAProxy2
$ sudo pcs resource update HAProxy2 meta failure-timeout=60s
### 생성한 리소스 확인 ###
$ sudo pcs resource
* Resource Group: HAProxyGroup:
* VirtualIP (ocf:heartbeat:IPaddr2): Started central1.aiweaver.net
* HAProxy (systemd:haproxy): Started central1.aiweaver.net
* Resource Group: HAProxyGroup2:
* VirtualIP2 (ocf:heartbeat:IPaddr2): Started central2.aiweaver.net
* HAProxy2 (systemd:haproxy): Started central2.aiweaver.net
### 클러스터 상태 확인 ###
### Pacemaker 가 리소스를 알아서 잘 분산해주고 있습니다.
HAProxyGroup은 central1 노드에 바인딩
HAProxyGroup2는 central2 노드에 바인딩
$ sudo pcs status
Cluster name: aiweaver-pacemaker
Cluster Summary:
* Stack: corosync (Pacemaker is running)
* Current DC: central1.aiweaver.net (version 2.1.7-5.el9_4-0f7f88312) - partition with quorum
* Last updated: Sun Jun 2 23:18:36 2024 on central1.aiweaver.net
* Last change: Sun Jun 2 21:37:22 2024 by hacluster via hacluster on central2.aiweaver.net
* 2 nodes configured
* 4 resource instances configured
Node List:
* Online: [ central1.aiweaver.net central2.aiweaver.net ]
Full List of Resources:
* Resource Group: HAProxyGroup:
* VirtualIP (ocf:heartbeat:IPaddr2): Started central1.aiweaver.net
* HAProxy (systemd:haproxy): Started central1.aiweaver.net
* Resource Group: HAProxyGroup2:
* VirtualIP2 (ocf:heartbeat:IPaddr2): Started central2.aiweaver.net
* HAProxy2 (systemd:haproxy): Started central2.aiweaver.net
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
### 클러스터 설정 확인 ###
$ sudo pcs config show
Cluster Name: aiweaver-pacemaker
Corosync Nodes:
central1.aiweaver.net central2.aiweaver.net
Pacemaker Nodes:
central1.aiweaver.net central2.aiweaver.net
Resources:
Group: HAProxyGroup
Resource: VirtualIP (class=ocf provider=heartbeat type=IPaddr2)
Attributes: VirtualIP-instance_attributes
cidr_netmask=23
ip=172.16.0.200
nic=enp2s0
Operations:
monitor: VirtualIP-monitor-interval-10s
interval=10s
start: VirtualIP-start-interval-0s
interval=0s timeout=20s
stop: VirtualIP-stop-interval-0s
interval=0s timeout=20s
Resource: HAProxy (class=systemd type=haproxy)
Operations:
monitor: HAProxy-monitor-interval-60
interval=60 timeout=100
start: HAProxy-start-interval-0s
interval=0s timeout=100
stop: HAProxy-stop-interval-0s
interval=0s timeout=100
Group: HAProxyGroup2
Resource: VirtualIP2 (class=ocf provider=heartbeat type=IPaddr2)
Attributes: VirtualIP2-instance_attributes
cidr_netmask=23
ip=172.16.0.201
nic=enp2s0
Operations:
monitor: VirtualIP2-monitor-interval-10s
interval=10s
start: VirtualIP2-start-interval-0s
interval=0s timeout=20s
stop: VirtualIP2-stop-interval-0s
interval=0s timeout=20s
Resource: HAProxy2 (class=systemd type=haproxy)
Operations:
monitor: HAProxy2-monitor-interval-60
interval=60 timeout=100
start: HAProxy2-start-interval-0s
interval=0s timeout=100
stop: HAProxy2-stop-interval-0s
interval=0s timeout=100
Resources Defaults:
Meta Attrs: build-resource-defaults
resource-stickiness=1 (id: build-resource-stickiness)
Cluster Properties: cib-bootstrap-options
cluster-infrastructure=corosync
cluster-name=aiweaver-pacemaker
dc-version=2.1.7-5.el9_4-0f7f88312
have-watchdog=false
last-lrm-refresh=1713877268
no-quorum-policy=ignore
stonith-enabled=false
### 각 노드에서 확인해보면 VIP 해당 노드에 바인딩 된것을 확인할 수 있습니다.
### central1 에서 확인 ###
$ ip a s enp2s0
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c0:18:03:65:3c:4e brd ff:ff:ff:ff:ff:ff
inet 172.16.0.99/23 brd 172.16.1.255 scope global noprefixroute enp2s0
valid_lft forever preferred_lft forever
inet 172.16.0.200/23 brd 172.16.1.255 scope global secondary enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::b7f9:ffb4:d288:7a79/64 scope link noprefixroute
valid_lft forever preferred_lft forever마지막으로 HAProxy 설정에 해당 VIP로 원하는 API를 바인딩 해줍니다.
아래는 HAProxy 예제입니다.
VIP1(172.16.0.200) 과 VIP2(172.16.0.201) 를 찾아보시면 어떤 구조인지 파악할 수 있습니다.
아래 설정에서 자신의 서버 Core수에 맞게 nbthread 값을 늘려 주십시오.
##### 모든 노드에서 동일하게 배포 #####
$ sudo vi /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
# log 127.0.0.1 local2 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
# stats socket /var/lib/haproxy/stats user haproxy group haproxy mode 600 level admin
user haproxy
group haproxy
node haproxy
maxconn 1024000
spread-checks 5
daemon
# debug
quiet
# tune.bufsize 65536
# tune.maxrewrite 4096
# ssl-server-verify none
# tune.ssl.default-dh-param 2048
# ssl-default-bind-ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
# ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
# ssl-default-server-ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
# ssl-default-server-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-tickets
nbthread 2
stats socket /var/lib/haproxy/stats user haproxy group haproxy mode 600 level admin
defaults # Apply to all services
log global
mode tcp
balance roundrobin
option dontlognull
option tcp-smart-accept
option tcp-smart-connect
option redispatch
maxconn 102400
# option abortonclose
option http-server-close
# option httpclose
# option forwardfor except 127.0.0.0/8
retries 2
timeout connect 10s
timeout server 300s
timeout client 300s
timeout queue 600s
timeout http-request 300s
timeout http-keep-alive 10s
timeout check 10s
frontend aiweaver-rke-server-proxy
description "AIWEAVER-RKE Server Cluster"
bind 172.16.0.200:9345 alpn h2,http/1.1
mode tcp
timeout client 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout tarpit 300s
default_backend aiweaver-rke-server-cluster
backend aiweaver-rke-server-cluster
description "AIWEAVER-RKE Server Cluster"
mode tcp
balance leastconn
timeout connect 10s
timeout server 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout queue 300s
timeout tarpit 300s
option tcpka # enable the keepalive
# acl internal_networks src 192.168.0.0/16 172.16.0.0/12 100.64.0.0/10 10.0.0.0/8 127.0.0.0/8
# tcp-request content reject if ! internal_networks
# stick on src
# stick-table type ip size 200k expire 86400s
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 1024000 maxqueue 128 weight 100
server controller1 172.16.0.100:9345 check
server controller2 172.16.0.101:9345 check
server controller3 172.16.0.102:9345 check
frontend aiweaver-k8s-api-proxy
description "AIWEAVER-K8S API Cluster"
bind 172.16.0.200:6443 alpn h2,http/1.1
mode tcp
timeout client 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout tarpit 300s
default_backend aiweaver-k8s-api-cluster
backend aiweaver-k8s-api-cluster
description "AIWEAVER-K8S API Cluster"
mode tcp
balance leastconn
timeout connect 10s
timeout server 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout queue 300s
timeout tarpit 300s
option tcpka # enable the keepalive
# acl internal_networks src 192.168.0.0/16 172.16.0.0/12 100.64.0.0/10 10.0.0.0/8 127.0.0.0/8
# tcp-request content reject if ! internal_networks
# stick on src
# stick-table type ip size 200k expire 86400s
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 1024000 maxqueue 128 weight 100
server controller1 172.16.0.100:6443 check
server controller2 172.16.0.101:6443 check
server controller3 172.16.0.102:6443 check
frontend aiweaver-etcd-server-proxy
description "AIWEAVER-ETCD Server Cluster"
bind 172.16.0.200:2379 alpn h2,http/1.1
mode tcp
timeout client 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout tarpit 300s
default_backend aiweaver-etcd-server-cluster
backend aiweaver-etcd-server-cluster
description "AIWEAVER-ETCD Server Cluster"
mode tcp
balance leastconn
timeout connect 10s
timeout server 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout queue 300s
timeout tarpit 300s
option tcpka # enable the keepalive
# acl internal_networks src 192.168.0.0/16 172.16.0.0/12 100.64.0.0/10 10.0.0.0/8 127.0.0.0/8
# tcp-request content reject if ! internal_networks
# stick on src
# stick-table type ip size 200k expire 86400s
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 1024000 maxqueue 128 weight 100
server controller1 172.16.0.100:2379 check
server controller2 172.16.0.101:2379 check
server controller3 172.16.0.102:2379 check
frontend aiweaver-proxy-server-proxy
description "AIWEAVER-PROXY Server Cluster"
bind 172.16.0.201:10203
mode tcp
timeout client 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout tarpit 300s
default_backend aiweaver-proxy-server-cluster
backend aiweaver-proxy-server-cluster
description "AIWEAVER-PROXY Server Cluster"
mode tcp
balance leastconn
timeout connect 10s
timeout server 30s
timeout http-keep-alive 5s
timeout http-request 30s
timeout queue 300s
timeout tarpit 300s
option tcpka # enable the keepalive
# acl internal_networks src 192.168.0.0/16 172.16.0.0/12 100.64.0.0/10 10.0.0.0/8 127.0.0.0/8
# tcp-request content reject if ! internal_networks
# stick on src
# stick-table type ip size 200k expire 86400s
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 1024000 maxqueue 128 weight 100
server central1 172.16.0.98:10203 check
server central2 172.16.0.99:10203 check
listen LoadBalancerCluster
description "AIWEAVER L7 Load Balancer"
bind 172.16.0.200:8000
log global
mode tcp
# option http-server-close
# option forwardfor except 127.0.0.1
# option forwardfor
option tcpka # enable the keepalive
# option httpchk
# timeout http-request 10s
timeout connect 10s
timeout server 300s
timeout client 300s
# stats enable
balance roundrobin
default-server inter 2s downinter 5s rise 3 fall 2 slowstart 60s maxconn 102400 maxqueue 128 weight 100
server central1 172.16.0.98:8000 check
server central2 172.16.0.99:8000 check
# HAProxy Access User Configuration(admin/stats)
userlist STATSUSERS
group admin users admin
user admin insecure-password !haproxy00
user stats insecure-password !haproxy00
# Wildcard 주소(0.0.0.0)에 bind 시키면 VIP와 포트 충돌이 발생하기 때문에, 각 노드의 IP로 bind 시켜줍니다.
listen stats
bind 172.16.0.98:8000
# bind 172.16.0.99:8000
mode http
stats enable
stats refresh 60s
stats uri /
stats hide-version
acl AuthOkay_ReadOnly http_auth(STATSUSERS)
acl AuthOkay_Admin http_auth_group(STATSUSERS) admin
stats http-request auth realm Haproxy_Admin_Page unless AuthOkay_ReadOnly
# stats admin if AuthOkay_Admin
### 설정을 수정한 후에는 reload/restart 하기전에 반드시 설정을 검증하십시오 ###
$ sudo haproxy -c -V -f /etc/haproxy/haproxy.cfg
Configuration file is valid
$ sudo systemctl reload haproxy마지막으로 시스템 재부팅 시 필수 데몬들이 자동으로 시작될 수 있도록 설정합니다.
다시 말씀드리지만, HAProxy 데몬 제어는 Pacemaker가 하기 때문에 별도로 enable 하지 않습니다.
### pcsd/corosync/pacemaker daemon 자동시작 활성화 ###
$ sudo systemctl enable pcsd
$ sudo systemctl enable corosync
$ sudo systemctl enable pacemaker테스트로 HAProxy Web Console에 접근해보겠습니다.
haproxy.cfg 에는 LoadBalancerCluster 섹션에 172.16.0.200:8000 으로 설정되어 있으므로, 브라우저에서 해당 주소를 입력합니다.
아이디 암호는 haproxy.cfg에 설정한 암호를 입력합니다. (admin/!haproxy00)
로그인에 성공하면 아래와 같은 상태 정보를 볼 수 있습니다.
balance mode 가 roundrobin 이기 때문에, Refresh 할때마다 HAProxy 가 구동되는 서버를 돌아가면서 한번씩 보여줍니다.
Reverse Proxy 설정을 추가하여 url에 따라 특정 HAProxy 서버의 상태를 볼 수 있도록 설정할 수도 있습니다.
HAProxy의 경우 Multi Process/Thread로 동작시키면 매우 고성능을 발휘합니다.
그리고 정말 복잡한 health check 로직과 nginx 등에서는 지원하지 않는 고급 기능을 지원합니다.
아래는 제가 Hadoop에서 사용하는 HAProxy 몇가지 로직입니다.
... 중략 ...
frontend skt-hadoop-namenode-proxy
description "Hadoop HDFS HA - Active NameNode"
bind ${NM_VIP}:50070
timeout client 300s
mode http
option httpclose
option forwardfor except 127.0.0.1
default_backend skt-hadoop-namenode-cluster
backend skt-hadoop-namenode-cluster
description "Hadoop HDFS HA - Active NameNode"
log global
mode http
option http-server-close
option forwardfor except 127.0.0.1
balance first
# acl internal_networks src 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.0/8 150.0.0.0/8
# http-request deny if ! internal_networks
option httpchk GET '/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus'
http-check expect rstring '"State"\s*:\s*"active"'
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 32768 maxqueue 128 weight 100
server ${NM_HOST1} ${NM_HOST1}:50070 check
server ${NM_HOST2} ${NM_HOST2}:50070 check backup
frontend skt-hadoop-namenode-rpc-proxy
description "Hadoop HDFS HA - Active NameNode RPC"
bind ${NM_VIP}:8020
timeout client 86400s
mode tcp
option tcplog
default_backend skt-hadoop-namenode-rpc-cluster
backend skt-hadoop-namenode-rpc-cluster
description "Hadoop HDFS HA - Active NameNode RPC"
balance first
mode tcp
timeout connect 180s
timeout server 86400s
option httpchk GET '/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus'
http-check expect rstring '"State"\s*:\s*"active"'
default-server inter 5s downinter 5s rise 3 fall 2 slowstart 60s maxconn 32768 maxqueue 128 weight 100
server ${NM_HOST1} ${NM_HOST1}:8020 check port 50070
server ${NM_HOST2} ${NM_HOST2}:8020 check port 50070 backup
... 후략 ...여기까지 Pacemaker와 HAProxy를 이용한 HA 방법에 대해서 알아보았습니다.
저희는 Hadoop을 제외 한 모든 서비스들이 K8s 기반으로 구동되고 있고, 최근에 MetalLB, KubeVIP 가 나오고, Cilium CNI의 경우에는 자체 LoadBalancer IPAM이 내장되어 있어
최근에는 HAProxy 사용빈도가 많이 줄었습니다.
하지만, K8s 클러스터 초기 구축, 업그레이드, 점검(planned maintenance) 때에는 K8s 상에서 구동되는 LoadBalancer가 정상 동작하지 않기 때문에,
K8s 클러스터와 독립적으로 동작하는 LoadBalancer 는 반드시 필요합니다.
Hadoop, K8s 등...데이터 분석 Production 환경에서 하루에 수십 TiB 데이터를 처리하고 있습니다.
믿고 사용하셔도 될 것 같습니다.
DEVOTEE를 활성화 시키면
지금 작성한 댓글에 AI가 댓글을 달아줍니다.