zabbix高可用方案
本次采用rhcs高可用套件pacemaker+corosync+pcs完成zabbix系統高可用部署。當然zabbix官方也已經從6.0版本開始原生支援高可用,不再依賴第三方元件來實作高可用,此文通過使用紅帽官方高可用套件來實作zabbix系統的高可用性,對比使用keepalived實作zabbix高可用,此方案更加簡潔高效。有興趣的也可以參考此方案配置舉一反三嘗試實作其他業務場景的高可用性。
1、伺服器規劃
伺服器主機名 | 位址 | 軟體 |
---|---|---|
zabbix-server1 | 192.168.59.128 | pacemaker corosync pcs zabbix5.x php72 httpd |
zabbix-server2 | 192.168.59.129 | pacemaker corosync pcs zabbix5.x php72 httpd |
mysql-server | 192.168.59.130 | mariadb |
vip:192.168.59.162
資料庫安裝及zabbix安裝忽略
2、系統環境初始化
- 時間同步
- 關閉系統防火牆
- 關閉selinux
- 主機名解析
3、高可用套件安裝(兩台zabbix主機上執行)
安裝
yum install pacemaker pcs -y
4、設定叢集使用者mima
echo 123456 |passwd --stdin hacluster
5、啟動pcsd
systemctl enable pcsd && systemctl start pcsd
6、認證(在任意一台節點執行即可)
pcs cluster auth zabbix-server1 zabbix-server2
Username: hacluster
Password:
zabbix-server1: Authorized
zabbix-server2: Authorized
7、建立叢集(在任意一台節點執行即可)
pcs cluster setup --name zabbixserver zabbix-server1 zabbix-server2
8、啟動叢集并設定開機自啟(在任意一台節點執行即可)
pcs cluster start --all
pcs cluster enable --all
9、檢視叢集狀态
pcs status cluster

10、配置服務
# 由于沒有配置fence裝置,是以關閉stonith
pcs property set stonith-enabled=false
# 由于叢集是雙節點,是以關閉仲裁機制
pcs property set no-quorum-policy=ignore
# 配置vip
pcs resource create cluster_vip ocf:heartbeat:IPaddr2 ip=192.168.59.162 cidr_netmask=24 op monitor interval=20s
# 配置php-fpm
pcs resource create php-fpm systemd:rh-php72-php-fpm op monitor interval=10s
# 配置httpd
pcs resource create httpd systemd:httpd op monitor interval=10s
# 配置zabbix-server
pcs resource create zabbix_server systemd:zabbix-server op monitor interval=10s
# 配置zabbix-agent
pcs resource create zabbix_agent systemd:zabbix-agent op monitor interval=10s
# 配置資源組
pcs resource group add grp_zabbix_httpd php-fpm zabbix_server httpd zabbix_agent
# 配置資源綁定(確定vip資源和zabbix服務在同一台節點上啟動)
pcs constraint colocation add grp_zabbix_httpd cluster_vip INFINITY
# 配置資源啟動順序
pcs constraint order cluster_vip then grp_zabbix_httpd
# 檢視資源狀态
pcs status
[root@zabbix-server1 web]# pcs status
Cluster name: zabbixserver
Stack: corosync
Current DC: zabbix-server2 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum
Last updated: Sat Aug 20 09:43:39 2022
Last change: Fri Aug 19 18:53:24 2022 by root via cibadmin on zabbix-server1
2 nodes configured
5 resource instances configured
Online: [ zabbix-server1 zabbix-server2 ]
Full list of resources:
cluster_vip (ocf::heartbeat:IPaddr2): Started zabbix-server1
Resource Group: grp_zabbix_httpd
php-fpm (systemd:rh-php72-php-fpm): Started zabbix-server1
zabbix_server (systemd:zabbix-server): Started zabbix-server1
httpd (systemd:httpd): Started zabbix-server1
zabbix_agent (systemd:zabbix-agent): Started zabbix-server1
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
11、故障轉移測試
# 将zabbix-server1設定為standby或者直接關機,檢視資源轉移及運作情況
[root@zabbix-server1 ~]# pcs node standby
[root@zabbix-server1 ~]# pcs status nodes
Pacemaker Nodes:
Online: zabbix-server2
Standby: zabbix-server1
Standby with resource(s) running:
Maintenance:
Offline:
Pacemaker Remote Nodes:
Online:
Standby:
Standby with resource(s) running:
Maintenance:
Offline:
[root@zabbix-server1 ~]# pcs status
Cluster name: zabbixserver
Stack: corosync
Current DC: zabbix-server2 (version 1.1.23-1.el7_9.1-9acf116022) - partition with quorum
Last updated: Sat Aug 20 09:54:10 2022
Last change: Sat Aug 20 09:51:42 2022 by root via cibadmin on zabbix-server1
2 nodes configured
5 resource instances configured
Node zabbix-server1: standby
Online: [ zabbix-server2 ]
Full list of resources:
cluster_vip (ocf::heartbeat:IPaddr2): Started zabbix-server2
Resource Group: grp_zabbix_httpd
php-fpm (systemd:rh-php72-php-fpm): Started zabbix-server2
zabbix_server (systemd:zabbix-server): Started zabbix-server2
httpd (systemd:httpd): Started zabbix-server2
zabbix_agent (systemd:zabbix-agent): Started zabbix-server2
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled