OpenEuler高可用部署Zabbix7.2

Keepalived + Zabbix 主备架构:


前提条件

1. 两台服务器:主机(192.168.1.10) 和 备机 (192.168.1.11)

2. 共享虚拟IP (VIP):192.168.1.100

3. 确保两台服务器时间同步(使用NTP)

4. 相同的操作系统环境

###各组件部署方案参考:超详细| 如何在OpenEuler系统下安装Zabbix 7.2?

部署步骤

步骤1:数据库主从复制 (MariaDB/MySQL)

在主机上(192.168.1.10):

Bash# 编辑MariaDB配置文件sudo vi /etc/my.cnf.d/server.cnf# 添加以下内容:[mysqld]server-id=1log-bin=mysql-binbinlog-format=ROWbinlog-do-db=zabbix

在备机上(192.168.1.11):

Bash# 编辑MariaDB配置文件sudo vi /etc/my.cnf.d/server.cnf# 添加以下内容:[mysqld]server-id=2relay-log=mysql-relay-binread-only=1replicate-do-db=zabbix

在主机上创建复制用户:

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

在备机上配置主从复制:

SQLCHANGE MASTER TOMASTER_HOST='192.168.1.10',MASTER_USER='replica',MASTER_PASSWORD='StrongPassword123!',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=XXX; -- 从主机执行 SHOW MASTER STATUS; 获取具体值START SLAVE;

步骤2:在两台服务器上安装Zabbix

Zabbix服务端安装(二选一方案)

方案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# 创建系统用户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

在主机上配置Zabbix数据库连接:

Bashsudo vi /etc/zabbix/zabbix_server.conf# 修改以下参数:DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=YourZabbixDBPassword

在备机上配置Zabbix数据库连接:

Bashsudo vi /etc/zabbix/zabbix_server.conf# 修改以下参数:DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=YourZabbixDBPassword# 添加以下参数禁用数据收集(备机只做热备)StartPollers=0StartPollersUnreachable=0StartPingers=0

Web前端配置(两台服务器相同):

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

在两台服务器上安装Keepalived:

Bashsudo dnf install keepalived -y

在主机上(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  # 使用实际网卡名virtual_router_id 51priority 200      # 主机优先级更高    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"}

在备机上(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      # 备机优先级较低    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"}

创建状态切换脚本(两台服务器相同):

Bashsudo mkdir /etc/keepalived/scriptssudo vi /etc/keepalived/master.sh#!/bin/bash# 当此服务器成为MASTER时执行systemctl start zabbix-serversystemctl start httpdsystemctl start mariadbexit 0sudo vi /etc/keepalived/backup.sh#!/bin/bash# 当此服务器成为BACKUP时执行systemctl stop zabbix-serversystemctl stop httpdsystemctl stop mariadbexit 0sudo vi /etc/keepalived/fault.sh#!/bin/bash# 当发生故障时执行logger "Keepalived进入FAULT状态"exit 0# 设置脚本权限sudo chmod +x /etc/keepalived/*.sh

步骤5:启动服务

在两台服务器上:

Bash# 启动Keepalivedsudo systemctl enable keepalivedsudo systemctl start keepalived# 启动Zabbix服务(注意:备机上会自动停止)sudo systemctl enable zabbix-server zabbix-agent httpdsudo systemctl start zabbix-server zabbix-agent httpd

步骤6:验证高可用性

[if !supportLists]1. [endif]检查VIP状态:

Bash   ip addr show ens33# 在主机上应该看到192.168.1.100

[if !supportLists]2. [endif]模拟故障转移:

Bash   # 在主机上停止Keepalivedsudo systemctl stop keepalived   # 在备机上检查VIP是否转移ip addr show ens33   # 检查备机上Zabbix服务是否启动systemctl status zabbix-server

[if !supportLists]3. [endif]访问Web界面:

http://192.168.1.100/zabbix

[if !supportLists]4. [endif]验证数据库复制状态:

SQL   # 在备机上执行SHOW SLAVE STATUS\G   # 确保Slave_IO_Running和Slave_SQL_Running都是Yes

故障排除

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

[if !supportLists]– [endif]检查防火墙是否允许VRRP协议:

[if !supportLists] [endif]

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

[if !supportLists]• [endif]验证两台服务器是否在同一个二层网络

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

[if !supportLists]2. [endif]数据库复制中断:

[if !supportLists]– [endif]检查主从状态:SHOW SLAVE STATUS\G

[if !supportLists]– [endif]修复复制错误:

[if !supportLists] [endif]

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

[if !supportLists]3. [endif]Zabbix服务不自动启动/停止:

[if !supportLists]– [endif]检查脚本权限:chmod +x /etc/keepalived/*.sh

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

[if !supportLists] [endif]

维护建议

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

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

[if !supportLists]2. [endif]监控Keepalived集群:

[if !supportLists]– [endif]在Zabbix中添加对两台服务器和VIP的监控

[if !supportLists]– [endif]设置告警规则(VIP切换、服务状态变化)

[if !supportLists] [endif]

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

1. 在备机上停止Keepalived2. 升级备机上的Zabbix3. 手动切换VIP到备机4. 升级原主机上的Zabbix5. 恢复主备关系

此方案确保了Zabbix服务的高可用性,当主机故障时,VIP会自动漂移到备机,同时备机上的Zabbix服务会自动启动接管工作。数据库主从复制保证了数据的实时同步。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • """1.个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消息应非常简单,如“Hello ...
    她即我命阅读 8,519评论 0 5
  • 为了让我有一个更快速、更精彩、更辉煌的成长,我将开始这段刻骨铭心的自我蜕变之旅!从今天开始,我将每天坚持阅...
    李薇帆阅读 5,941评论 0 3
  • 似乎最近一直都在路上,每次出来走的时候感受都会很不一样。 1、感恩一直遇到好心人,很幸运。在路上总是...
    时间里的花Lily阅读 5,211评论 0 2
  • 1、expected an indented block 冒号后面是要写上一定的内容的(新手容易遗忘这一点); 缩...
    庵下桃花仙阅读 3,541评论 0 1
  • 一、工具箱(多种工具共用一个快捷键的可同时按【Shift】加此快捷键选取)矩形、椭圆选框工具 【M】移动工具 【V...
    墨雅丫阅读 3,508评论 0 0