반응형
pacemaker로 nginx 고가용성(High Availability) 설정하기
테스트 환경
호스트 이름 | 서버 아이피 | 도메인 | 운영체제 | 비고 |
VIP | 192.168.0.60 | vip.cluster.local | ||
control1 | 192.168.0.51 | control1.cluster.local | Ubuntu 22.04 LTS | |
node3 | 192.168.0.63 | node3.cluster.local | Ubuntu 22.04 LTS |
pcs status
$ pcs status
Cluster name: hacluster
Cluster Summary:
* Stack: corosync
* Current DC: node3.cluster.local (version 2.1.2-ada5c3b36e2) - partition with quorum
* Last updated: Tue Feb 7 12:45:51 2023
* Last change: Tue Feb 7 11:05:49 2023 by root via cibadmin on node3.cluster.local
* 2 nodes configured
* 1 resource instance configured
Node List:
* Online: [ control1.cluster.local node3.cluster.local ]
Full List of Resources:
* VirtualIP (ocf:heartbeat:IPaddr2): Started control1.cluster.local
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
ngixn를 클러스터 리소스로 추가
cd /usr/lib/ocf/resource.d/heartbeat
wget -q https://raw.githubusercontent.com/ClusterLabs/resource-agents/master/heartbeat/nginx
chmod +x /usr/lib/ocf/resource.d/heartbeat/nginx
pcs resource agents ocf:heartbeat
$ pcs resource agents ocf:heartbeat
IPaddr2
iscsi
iSCSILogicalUnit
iSCSITarget
LVM-activate
nginx
nginx 고가용성 설정하기
nginx 설치
apt-get install -y nginx
echo '<h1>webserver 01</h1>' > /var/www/html/index.html
echo '<h1>webserver 02</h1>' > /var/www/html/index.html
systemctl restart nginx
리소스(resource) 추가
pcs resource create nginx_webserver ocf:heartbeat:nginx configfile=/etc/nginx/nginx.conf op monitor interval=30s
pcs status resources
$ pcs status resources
* VirtualIP (ocf:heartbeat:IPaddr2): Started control1.cluster.local
* webserver (ocf:heartbeat:nginx): Started node3.cluster.local
클러스터 리소스 그룹
pcs constraint colocation add webserver with VirtualIP INFINITY
pcs constraint
$ pcs constraint
Location Constraints:
Resource: VirtualIP
Enabled on:
Node: control1.cluster.local (score:200)
Node: node3.cluster.local (score:100)
Ordering Constraints:
Colocation Constraints:
webserver with VirtualIP (score:INFINITY)
Ticket Constraints:
$ pcs constraint order VirtualIP then webserver
Adding VirtualIP webserver (kind: Mandatory) (Options: first-action=start then-action=start)
$ pcs status resources
* VirtualIP (ocf:heartbeat:IPaddr2): Started control1.cluster.local
* webserver (ocf:heartbeat:nginx): Started control1.cluster.local
수동으로 리소스 이동
pcs constraint location webserver prefers node3.cluster.local=INFINITY
$ pcs status resources
* VirtualIP (ocf:heartbeat:IPaddr2): Started node3.cluster.local
* webserver (ocf:heartbeat:nginx): Started node3.cluster.local
$ pcs constraint --full
Location Constraints:
Resource: VirtualIP
Enabled on:
Node: control1.cluster.local (score:200) (id:location-VirtualIP-control1.cluster.local-200)
Node: node3.cluster.local (score:100) (id:location-VirtualIP-node3.cluster.local-100)
Resource: webserver
Enabled on:
Node: node3.cluster.local (score:INFINITY) (id:location-webserver-node3.cluster.local-INFINITY)
Ordering Constraints:
start VirtualIP then start webserver (kind:Mandatory) (id:order-VirtualIP-webserver-mandatory)
Colocation Constraints:
webserver with VirtualIP (score:INFINITY) (id:colocation-webserver-VirtualIP-INFINITY)
Ticket Constraints:
728x90
반응형
'리눅스' 카테고리의 다른 글
[리눅스] consul 서비스 등록 - 2 (0) | 2023.02.10 |
---|---|
java(jdk) 설치 및 java 환경 설정 (0) | 2023.02.07 |
우분투에서 Pacemaker와 VIP(Virtual IP)를 구성하여 고가용성 클러스터를 운영하는 방법 (0) | 2023.02.06 |
[리눅스] consul-template 설치(install consul-template) (0) | 2023.02.03 |
[리눅스] 유닉스 타임스탬프 변환기(unix timestamp converter) (0) | 2023.02.03 |