Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mold 용 Fencing Agent 개발 #353

Open
4 tasks done
Tracked by #281
gigs4014 opened this issue Dec 12, 2023 · 3 comments
Open
4 tasks done
Tracked by #281

Mold 용 Fencing Agent 개발 #353

gigs4014 opened this issue Dec 12, 2023 · 3 comments
Assignees

Comments

@gigs4014
Copy link

gigs4014 commented Dec 12, 2023

Mold 용 Fencing Agent

개요

기존의 Fencing Agent를 ipmilan를 활용하였으며, 해당 Agent를 활용하기 위해서는 가상머신에 vbmc 디바이스를 연결 후 해당 가상머신이 운영중인 호스트에 VBMC 포트포워딩을 연결 해줘야 구성이 가능함

해당 방식을 이용할 경우 문제점은 아래와 같다

  1. 가상머신을 fencing agent 로 정지할 경우 Mold에서 가상머신 정지 이유를 알지 못하여 compute offering 옵션중 HA옵션을 사용할 수 없다.
  2. 가상머신이 운영중인 호스트에서 vbmc 포트포워딩이 되어 있어 가상머신을 다른 호스트로 마이그레이션을 할 수 없다.

이와 같은 이유로 Mold에서 위 문제점을 해결 할 수 있는 Mold 용 Agent 를 개발을 진행 한다.

개발 방식

  1. 기존의 가상머신 상태체크는 pacemaker를 이용하며, 해당 pacemaker에서 가상머신의 동작 이상을 발견할 경우 Mold로 API명령어를 이용하여 동작 이상이 발견된 가상머신을 정지 시킨다.
  2. Mold Agent는 Mold와 통신이 가능한 대역으로 가상 네트워크가 생성이 되어야 한다.
  3. Mold Agent는 Mold의 IP, Port, API key, 비밀키를 이용하여 Mold API와 통신이 가능 해야하다.
  4. Mold IP, Port, API key, 비밀키는 수정이 가능해야 하다.

개발 완료 후 테스트 항목

  • Mold Agent 를 이용한 정상 동작
  • HA 발생시 동작여부
  • 마이그레이션 정상 작동 및 Agent 정상 동작 여부
  • Shared Volume 을 이용한 스토리지 구성 및 해당 볼륨을 이용한 가상머신 이중화 테스트 진행
@stardom3645
Copy link

stardom3645 commented Jan 30, 2024

Linux 환경에서의 Pacemaker와 Mold fence agent를 이용한 Mysql FailOver 구성

  1. 구성 환경
  2. Pacemaker 클러스터 구성
  3. shared disk를 활용한 Mysql 구성
  4. mold_fence agent 설치 및 stonith 구성
  5. mysql failover를 위한 pcs resource 구성

1. 구성 환경

  • OS
    • VM: Rokcy 9
  • 네트워크
    • VM1(lilo-ha1): 10.10.254.100
    • VM2(lilo-ha2): 10.10.254.101
    • VIP: 10.10.254.199
  • Affinity 그룹
    • host anti-affinity

2. Pacemaker 클러스터 구성

방화벽 해제

==== [VM1, VM2 실행]

firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --permanent --zone=public --add-service=high-availability
firewall-cmd --add-service=high-availability

pacemaker 패키지 설치

==== [VM1, VM2 실행]

dnf -y upgrade
dnf -y config-manager --set-enabled crb
dnf -y install epel-release
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf --enablerepo=highavailability -y install pacemaker pcs fence-agents-all

서비스 시작 및 등록

systemctl start pcsd
systemctl enable pcsd
systemctl enable corosync
systemctl enable pacemaker

클러스터 계정 존재여부 확인

cat /etc/passwd |grep hacluster
passwd hacluster

hosts 파일 변경

vi /etc/hosts
----------------------------------------------------

####Pacemaker Hearbeat IP####
10.10.254.100 lilo-ha1
10.10.254.101 lilo-ha2
systemctl restart NetworkManager

Pacemaker 클러스터 구성 및 시작

==== [VM1 실행]

pcs host auth lilo-ha1 lilo-ha2 -u hacluster -p Ablecloud1!
pcs cluster setup hacluster --start lilo-ha1 lilo-ha2

==== [VM1, VM2 실행]

systemctl start pacemaker

3. Shared disk를 활용한 Mysql 구성

==== [VM1, VM2 실행]

  • Mold에서 Shared Disk를 구성합니다.
  • 볼륨 파티션, 포멧, 마운트를 합니다.
fdisk /dev/sdb
  => n, 엔터, 엔터, 엔터, 엔터, 엔터, t, 8e, w

pvcreate /dev/sdb1
pvdisplay

vgcreate able /dev/sdb1
vgdisplay

lvcreate -l 100%FREE -n lv_data able
lvdisplay

mkfs.xfs -f /dev/able/lv_data

lvm.conf 설정

==== [VM1, VM2 실행]
LVM-activate를 등록할 때 해당 system_id를 사용하기 때문에 /etc/lvm/lvm.conf 구성 파일에서 system_id_source 구성 옵션을 uname 으로 설정합니다.

vi /etc/lvm/lvm.conf 

system-id 확인

vgs -o+systemid

Mysql 설치 및 구성

==== [VM1, VM2 실행]

Mysql를 설치합니다.

  • mysql 서비스는 enable 하지 않습니다. Mysql pcs resource에 의해 mysql이 실행됩니다.
dnf install -y mysql-server

mysql을 구성합니다.

mysqld --initialize --datadir=/mnt/share/mysql
semanage fcontext -a -t mysqld_db_t "/mnt/share/mysql(/.*)?"
restorecon -R -v /mnt/share/mysql
chown -R mysql:mysql /mnt/share/mysql
chmod -R 750 /mnt/share/mysql
systemctl restart mysqld
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ablecloud1!';
FLUSH PRIVILEGES;
vi /etc/my.cnf.d/mysql-server.cnf
------------------------------------------------
[mysqld]
datadir=/mnt/share/mysql
socket=/mnt/share/mysql/mysql.sock

[client]
socket=/mnt/share/mysql/mysql.sock

4. mold_fence agent 설치 및 stonith 구성

  • Mold Agent는 Mold와 통신이 가능한 구성에서 사용 가능합니다.
  • Mold Agent의 fencing 처리 절차
    1. Master node 장애 발생
    2. Slave node에서 동작 중인 'fence-node1' stonith를 통해 Master node를 fencing 처리
      1. delay 옵션 설정에 의해 fencing 처리 대기
      2. Mold 상태 값 조회
      3. 해당 VM 종료 명령
    3. Master 에서 Slave node로 서비스 이관 (환경에 따라 20초~1분 정도 소요)

Mold fence agent 설치

==== [VM1, VM2 실행]

wget -P /root/ https://images.ablecloud.io/fence-mold-1.0-1.el9.x86_64.rpm
rpm -Uvh /root/fence-mold-1.0-1.el9.x86_64.rpm --force

PCS resource 등록

fencing 처리를 위한 stonith resource 구성

각 노드에 fencing 처리를 위한 stonith를 생성하고 구성.

  • 명령어 정보는 fence_mold -h 를 입력하여 확인
  1. stonith 생성
pcs stonith create fence-node1 fence_mold \
api_protocol="http" \
m_ip="10.10.1.10" \
m_port="8080" \
api_key="ew68uZifMjNXd6PbRUGtvVA98TnohwDc6R73-kq_tvI" \
secret_key="xrWdgQNJMoAzhtnJYl7-fGApjLxhz4GHqnuMrSbVn2E" \
vm_id="0d859221-87a6-428b-9516-f9727e22ec20" \
delay="15"
pcmk_host_list="lilo-ha1" \
pcmk_reboot_action="off"


## 옵션 설명
delay: 펜싱 프로세스에서 오탐지를 유발할 수 있는 일시적인 문제로부터 시스템이 복구할 수 있는 시간을 제공하며 동시에 fencing되는 현상 방지
## 추가 옵션 (아래 기본 값으로 설정되어있음.)
# m_total_timeout ="600" 
# m_interval = "10"
# power off 시 mold mngt 서버 상태 값이 Up이 될 때까지 지정된 값 만큼 대기하고 fencing 처리. (기본값 -> 대기시간: 600초, 체크시도 횟수: 대기시간/10)


pcs stonith create fence-node2 fence_mold \
api_protocol="http" \
m_ip="10.10.1.10" \
m_port="8080" \
api_key="ew68uZifMjNXd6PbRUGtvVA98TnohwDc6R73-kq_tvI" \
secret_key="xrWdgQNJMoAzhtnJYl7-fGApjLxhz4GHqnuMrSbVn2E" \
vm_id="fb42b9ff-43c2-49b2-9641-1ca2c67e43f9" \
pcmk_host_list="lilo-ha2" \
pcmk_reboot_action="off"
  • stonith 업데이트 방법
    설정 요소 변경에 따른 업데이트 명령어는 다음과 같습니다.
# pcs stonith update my-stonith attribute1=value1 attribute2=value2
pcs stonith update fence-node1 api_key="3568uZifMjNXd6PSDFEsfdtvVA98TnohwDc6R73-kq_tvI" m_port="8443"
  1. stonith 정책 설정
    서로 다른 노드에서 실행되도록 설정
pcs constraint location fence-node1 avoids lilo-ha1
pcs constraint location fence-node2 avoids lilo-ha2

기본 stonith 액션을 power off로 변경

pcs property set stonith-action=off

5. Mysql Failover를 위한 pcs resource 구성

lvm, file system, mysql을 pcs resource로 등록하고 그룹화하여 한 Node에서만 실행되고 이동되도록 구성합니다.

  • resource group은 등록 순서에 따라 실행됩니다.

LVM-activate resource 에이전트 등록

# pcs resource create <resource name> LVM-activate vgname=<vgname> vg_access_mode=system_id --group <groupname>

pcs resource create cluster-vg ocf:heartbeat:LVM-activate vgname=able activation_mode=exclusive vg_access_mode=system_id --group test-grp

Filesystem resource 에이전트 등록

# pcs resource create <resource name> Filesystem device="/dev/<vgname>/<lvname>" directory="<directory name>" fstype="xfs" --group <groupname>

pcs resource create cluster-fs ocf:heartbeat:Filesystem device=/dev/able/lv_data directory=/mnt/share/ fstype=xfs --group test-grp

VIP resource 등록

pcs resource create vip ipaddr2 ip=10.10.254.199 cidr_netmask=16 op monitor interval=10 --group test-grp
pcs resource meta vip migration-threshold=1
pcs resource meta vip resource-stickiness=50

Mysql resource 에이전트 등록

  • mysql은 systemctl service로 실행되는 것이 아닌, pcs agent에 의해 실행됩니다.
pcs resource create mysql ocf:heartbeat:mysql binary="/usr/sbin/mysqld" config="/etc/my.cnf.d/mysql-server.cnf" datadir="/mnt/share/mysql" pid="/run/mysql/mysqld.pid" socket="/mnt/share/mysql/mysql.sock" op start timeout=60s op stop timeout=60s op monitor interval=20s timeout=30s --group test-grp

구성 완료된 pcs 상태 확인

image
image

@stardom3645
Copy link

stardom3645 commented Jan 31, 2024

Mold Agent 개발 방법 및 패키징

  1. fence agent 저장소 Fork
  2. linux vm 생성
  3. fork한 저장소 clone
  4. /root/fence-agents/agents/mold/fence_mold.py 코드 수정
  5. Build requirements 설치
    • dnf builddep fence-agents-all
  6. 매개변수나 설명이 업데이트된 경우 ./autogen.sh && ./configure를 실행한 다음 make install을 실행합니다.
  7. rpmbuild
    • RPM 빌드 환경 생성
      • mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
    • 소스 파일 및 spec 파일 준비
      • cp /root/fence-agents/agents/mold/fence_mold /root/fence-agents/agents/mold/fence_mold.8 /root/rpmbuild/SOURCES/
      • vi /root/rpmbuild/SPECS/fence-mold.spec
       Summary: Fence Agent for Something
       Name: fence-mold
       Version: 1.0
       Release: 1%{?dist}
       License: GPLv2+
       Source0: fence_mold
       Source1: fence_mold.8
       
       %description
       This is a fence agent for something.
       
       %install
       mkdir -p %{buildroot}/usr/sbin
       install -m 755 %{SOURCE0} %{buildroot}/usr/sbin
       
       mkdir -p %{buildroot}/usr/share/man/man8
       install -m 644 %{SOURCE1} %{buildroot}/usr/share/man/man8
       
       %files
       %doc
       %{_mandir}/man8/fence_mold.8.gz
       /usr/sbin/fence_mold
      
  8. rpm 빌드
    • rpmbuild -ba /root/rpmbuild/SPECS/fence-mold.spec

@stardom3645
Copy link

stardom3645 commented Feb 1, 2024

마이그레이션 정상 작동 및 Agent 정상 동작 여부 테스트

테스트 개요

상기 기술된 'Linux 환경에서의 Pacemaker와 Mold fence agent를 이용한 Mysql FailOver 구성' 내용에 따라 pcs 클러스터를 구성한 상태에서 VM1(Master)을 다른 호스트로 마이그레이션 할 경우를 테스트 하였습니다.

결과

  • 마이그레이션 시점부터 완료시점까지 pcs resource를 VM1(Master)가 fence 처리되지 않고 계속 소유합니다. 즉 VM1(Master)이 Slave로 전환되지 않습니다.
  • 마이그레이션으로 인한 서비스 중단은 발견되지 않았습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants