OpenEuler高可用部署Zabbix7.2

Keepalived + Zabbix 主備架構(gòu):


前提條件

1. 兩臺服務(wù)器:主機(jī)(192.168.1.10) 和 備機(jī) (192.168.1.11)

2. 共享虛擬IP (VIP):192.168.1.100

3. 確保兩臺服務(wù)器時間同步(使用NTP)

4. 相同的操作系統(tǒng)環(huán)境

###各組件部署方案參考:超詳細(xì)| 如何在OpenEuler系統(tǒng)下安裝Zabbix 7.2?

部署步驟

步驟1:數(shù)據(jù)庫主從復(fù)制 (MariaDB/MySQL)

在主機(jī)上(192.168.1.10):

Bash# 編輯MariaDB配置文件sudo vi /etc/my.cnf.d/server.cnf# 添加以下內(nèi)容:[mysqld]server-id=1log-bin=mysql-binbinlog-format=ROWbinlog-do-db=zabbix

在備機(jī)上(192.168.1.11):

Bash# 編輯MariaDB配置文件sudo vi /etc/my.cnf.d/server.cnf# 添加以下內(nèi)容:[mysqld]server-id=2relay-log=mysql-relay-binread-only=1replicate-do-db=zabbix

在主機(jī)上創(chuàng)建復(fù)制用戶:

SQLCREATE USER 'replica'@'192.168.1.11' IDENTIFIED BY 'StrongPassword123!';GRANT REPLICATION SLAVE ON *.* TO 'replica'@'192.168.1.11';FLUSH PRIVILEGES;

在備機(jī)上配置主從復(fù)制:

SQLCHANGE MASTER TOMASTER_HOST='192.168.1.10',MASTER_USER='replica',MASTER_PASSWORD='StrongPassword123!',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=XXX; -- 從主機(jī)執(zhí)行 SHOW MASTER STATUS; 獲取具體值START SLAVE;

步驟2:在兩臺服務(wù)器上安裝Zabbix

Zabbix服務(wù)端安裝(二選一方案)

方案A:源碼編譯安裝(推薦)

Bash# 安裝依賴dnf install gcc make libevent-devel openssl-devel pcre-devel mysql-devel -y# 下載源碼wget https://cdn.zabbix.com/zabbix/sources/stable/7.2/zabbix-7.2.0.tar.gztar -zxvf zabbix-7.2.0.tar.gzcd zabbix-7.2.0# 編譯安裝./configure \--prefix=/app/zabbix \--enable-server \--enable-agent \--with-mysqlmake -j$(nproc)make install# 創(chuàng)建系統(tǒng)用戶groupadd --system zabbixuseradd --system -g zabbix -d /app/zabbix -s /sbin/nologin zabbix

方案B:RPM倉庫安裝

Bash# 添加Zabbix官方倉庫rpm -Uvh https://repo.zabbix.com/zabbix/7.2/release/centos/9/noarch/zabbix-release-latest-7.2.el9.noarch.rpm# 安裝核心組件dnf install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

步驟3:配置Zabbix

在主機(jī)上配置Zabbix數(shù)據(jù)庫連接:

Bashsudo vi /etc/zabbix/zabbix_server.conf# 修改以下參數(shù):DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=YourZabbixDBPassword

在備機(jī)上配置Zabbix數(shù)據(jù)庫連接:

Bashsudo vi /etc/zabbix/zabbix_server.conf# 修改以下參數(shù):DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=YourZabbixDBPassword# 添加以下參數(shù)禁用數(shù)據(jù)收集(備機(jī)只做熱備)StartPollers=0StartPollersUnreachable=0StartPingers=0

Web前端配置(兩臺服務(wù)器相同):

Bashsudo vi /etc/zabbix/web/zabbix.conf.php<?php$DB['TYPE'] ????= 'MYSQL';$DB['SERVER'] ??= 'localhost';$DB['PORT'] ????= '0';$DB['DATABASE'] = 'zabbix';$DB['USER'] ????= 'zabbix';$DB['PASSWORD'] = 'YourZabbixDBPassword';$ZBX_SERVER ?????= '192.168.1.100'; // 使用虛擬IP$ZBX_SERVER_PORT = '10051';$ZBX_SERVER_NAME = 'Zabbix HA Cluster';

步驟4:安裝和配置Keepalived

在兩臺服務(wù)器上安裝Keepalived:

Bashsudo dnf install keepalived -y

在主機(jī)上(192.168.1.10) 配置Keepalived:

Bashsudo vi /etc/keepalived/keepalived.confvrrp_script chk_zabbix {script "/usr/bin/pgrep zabbix_server"interval 2weight 50}vrrp_script chk_httpd {script "/usr/bin/pgrep httpd"interval 2weight 50}vrrp_instance VI_1 {state MASTERinterface ens33 ?# 使用實(shí)際網(wǎng)卡名virtual_router_id 51priority 200 ?????# 主機(jī)優(yōu)先級更高????authentication {auth_type PASSauth_pass kylin123}????virtual_ipaddress {192.168.1.100/24 dev ens33 ?# VIP配置}????track_script {chk_zabbixchk_httpd}????notify_master "/etc/keepalived/master.sh"notify_backup "/etc/keepalived/backup.sh"notify_fault "/etc/keepalived/fault.sh"}

在備機(jī)上(192.168.1.11) 配置Keepalived:

Bashsudo vi /etc/keepalived/keepalived.confvrrp_script chk_zabbix {script "/usr/bin/pgrep zabbix_server"interval 2weight 50}vrrp_script chk_httpd {script "/usr/bin/pgrep httpd"interval 2weight 50}vrrp_instance VI_1 {state BACKUPinterface ens33virtual_router_id 51priority 100 ?????# 備機(jī)優(yōu)先級較低????authentication {auth_type PASSauth_pass kylin123}????virtual_ipaddress {192.168.1.100/24 dev ens33}????track_script {chk_zabbixchk_httpd}????notify_master "/etc/keepalived/master.sh"notify_backup "/etc/keepalived/backup.sh"notify_fault "/etc/keepalived/fault.sh"}

創(chuàng)建狀態(tài)切換腳本(兩臺服務(wù)器相同):

Bashsudo mkdir /etc/keepalived/scriptssudo vi /etc/keepalived/master.sh#!/bin/bash# 當(dāng)此服務(wù)器成為MASTER時執(zhí)行systemctl start zabbix-serversystemctl start httpdsystemctl start mariadbexit 0sudo vi /etc/keepalived/backup.sh#!/bin/bash# 當(dāng)此服務(wù)器成為BACKUP時執(zhí)行systemctl stop zabbix-serversystemctl stop httpdsystemctl stop mariadbexit 0sudo vi /etc/keepalived/fault.sh#!/bin/bash# 當(dāng)發(fā)生故障時執(zhí)行l(wèi)ogger "Keepalived進(jìn)入FAULT狀態(tài)"exit 0# 設(shè)置腳本權(quán)限sudo chmod +x /etc/keepalived/*.sh

步驟5:啟動服務(wù)

在兩臺服務(wù)器上:

Bash# 啟動Keepalivedsudo systemctl enable keepalivedsudo systemctl start keepalived# 啟動Zabbix服務(wù)(注意:備機(jī)上會自動停止)sudo systemctl enable zabbix-server zabbix-agent httpdsudo systemctl start zabbix-server zabbix-agent httpd

步驟6:驗(yàn)證高可用性

[if !supportLists]1.?[endif]檢查VIP狀態(tài):

Bash ??ip addr show ens33# 在主機(jī)上應(yīng)該看到192.168.1.100

[if !supportLists]2.?[endif]模擬故障轉(zhuǎn)移:

Bash ??# 在主機(jī)上停止Keepalivedsudo systemctl stop keepalived???# 在備機(jī)上檢查VIP是否轉(zhuǎn)移ip addr show ens33???# 檢查備機(jī)上Zabbix服務(wù)是否啟動systemctl status zabbix-server

[if !supportLists]3.?[endif]訪問Web界面:

http://192.168.1.100/zabbix

[if !supportLists]4.?[endif]驗(yàn)證數(shù)據(jù)庫復(fù)制狀態(tài):

SQL ??# 在備機(jī)上執(zhí)行SHOW SLAVE STATUS\G???# 確保Slave_IO_Running和Slave_SQL_Running都是Yes

故障排除

[if !supportLists]1.?[endif]VIP不漂移:

[if !supportLists]–?[endif]檢查防火墻是否允許VRRP協(xié)議:

[if !supportLists]?[endif]

Bash ????sudo firewall-cmd --add-protocol=vrrp --permanentsudo firewall-cmd --reload

[if !supportLists]??[endif]驗(yàn)證兩臺服務(wù)器是否在同一個二層網(wǎng)絡(luò)

[if !supportLists]??[endif]檢查keepalived.conf中的virtual_router_id是否一致且唯一

[if !supportLists]2.?[endif]數(shù)據(jù)庫復(fù)制中斷:

[if !supportLists]–?[endif]檢查主從狀態(tài):SHOW SLAVE STATUS\G

[if !supportLists]–?[endif]修復(fù)復(fù)制錯誤:

[if !supportLists]?[endif]

SQL ????STOP SLAVE;SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;START SLAVE;

[if !supportLists]3.?[endif]Zabbix服務(wù)不自動啟動/停止:

[if !supportLists]–?[endif]檢查腳本權(quán)限:chmod +x /etc/keepalived/*.sh

[if !supportLists]–?[endif]查看Keepalived日志:journalctl -u keepalived

[if !supportLists]?[endif]

維護(hù)建議

[if !supportLists]1.?[endif]定期備份:

Bash ??# 備份Zabbix配置mysqldump -u zabbix -p zabbix > zabbix_backup_$(date +%F).sql

[if !supportLists]2.?[endif]監(jiān)控Keepalived集群:

[if !supportLists]–?[endif]在Zabbix中添加對兩臺服務(wù)器和VIP的監(jiān)控

[if !supportLists]–?[endif]設(shè)置告警規(guī)則(VIP切換、服務(wù)狀態(tài)變化)

[if !supportLists]?[endif]

[if !supportLists]3.?[endif]升級流程:

1. 在備機(jī)上停止Keepalived2. 升級備機(jī)上的Zabbix3. 手動切換VIP到備機(jī)4. 升級原主機(jī)上的Zabbix5. 恢復(fù)主備關(guān)系

此方案確保了Zabbix服務(wù)的高可用性,當(dāng)主機(jī)故障時,VIP會自動漂移到備機(jī),同時備機(jī)上的Zabbix服務(wù)會自動啟動接管工作。數(shù)據(jù)庫主從復(fù)制保證了數(shù)據(jù)的實(shí)時同步。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • """1.個性化消息: 將用戶的姓名存到一個變量中,并向該用戶顯示一條消息。顯示的消息應(yīng)非常簡單,如“Hello ...
    她即我命閱讀 4,815評論 0 6
  • 為了讓我有一個更快速、更精彩、更輝煌的成長,我將開始這段刻骨銘心的自我蛻變之旅!從今天開始,我將每天堅(jiān)持閱...
    李薇帆閱讀 2,224評論 1 4
  • 似乎最近一直都在路上,每次出來走的時候感受都會很不一樣。 1、感恩一直遇到好心人,很幸運(yùn)。在路上總是...
    時間里的花Lily閱讀 1,703評論 1 3
  • 1、expected an indented block 冒號后面是要寫上一定的內(nèi)容的(新手容易遺忘這一點(diǎn)); 縮...
    庵下桃花仙閱讀 1,053評論 1 2
  • 一、工具箱(多種工具共用一個快捷鍵的可同時按【Shift】加此快捷鍵選取)矩形、橢圓選框工具 【M】移動工具 【V...
    墨雅丫閱讀 1,428評論 0 0

友情鏈接更多精彩內(nèi)容