Zabbix6.0升级为7.2

Zabbix 7.0 进行了全新升级,本文讲解如何从 6.0 版本升级至最新版本 7.2。在 CentOS 8 上通过RPM 方式安装 Zabbix 服务

一、环境信息

我是CentOS 7安装的服务端,在该机器在通过源码去安装 Zabbix 7.0 版本的话,会比较费劲,因为有很多依赖包要去逐一解决,索性我们用 CentOS 8 来做 Zabbix-Sever 服务端,并且 CentOS 8 支持 RPM 方式来安装,会更加的方便。

1. 版本要求

2. 版本信息

环境 升级前 升级后
操作系统 CentOS 7.3 CentOS 8.4
MySQL 8.0.28 8.0.40
PHP 7.4.30 8.2
Zabbix-Server-MySQL 6.0.8 7.2.20
Zabbix-Web-MySQL 6.0.8 7.2.20

具体数据库升级,请参考: 这篇文章内容有如何进行数据库升级

二、安装PHP

必须要先安装好 PHP 相关软件,后续安装 Zabbix 相关软件时会依赖于 PHP 包,但是系统自带默认的 PHP 是7.2, 不满足要求。

1. 安装基础软件

bash 复制代码
# dnf install epel-release
# dnf install glib* gcc* libxml* libxml2*  OpenIPMI*

2. 安装PHP 8.2

这个 remi 直接下载后强制安装,在线安装会一直弹依赖问题,导致安装不了。

bash 复制代码
# rpm -ivh  remi-release-8.rpm --nodeps --force
# dnf module list php
# dnf module reset php -y
# dnf module install php:remi-8.2 -y
# dnf install php82-php-fpm  -y

# php -v 
PHP 8.2.27 (cli) (built: Dec 17 2024 11:39:23) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.27, Copyright (c) Zend Technologies

三、安装Zabbix 软件

1. 软件安装

bash 复制代码
# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent

2. 修改配置

bash 复制代码
# 修改 Nginx 配置文件
# cat /etc/nginx/conf.d/zabbix.conf 
server {
        listen          8080;
        server_name     xxx.xxx.xxx.xxx;

......

3. 服务启动

bash 复制代码
# systemctl start zabbix-server
# systemctl start php-fpm
# systemctl start nginx

查看 Zabbix 升级成功日志

bash 复制代码
# tailf /tmp/zabbix-server.log
 3322:20241219:170512.116 completed 72% of database upgrade
  3322:20241219:170516.011 slow query: 3.823381 sec, "update items set lifetime='7d' where flags in (0,2,4)"
  3322:20241219:170516.268 completed 73% of database upgrade
  3322:20241219:170516.565 completed 74% of database upgrade
  3322:20241219:170516.575 completed 75% of database upgrade
  3322:20241219:170516.602 completed 76% of database upgrade
  3322:20241219:170516.612 completed 77% of database upgrade
  3322:20241219:170516.646 completed 78% of database upgrade
  3322:20241219:170516.691 completed 79% of database upgrade
  3322:20241219:170516.725 completed 80% of database upgrade
  3322:20241219:170516.850 completed 81% of database upgrade
  3322:20241219:170517.127 completed 82% of database upgrade
  3322:20241219:170517.223 completed 83% of database upgrade
  3322:20241219:170517.278 completed 84% of database upgrade
  3322:20241219:170517.353 completed 85% of database upgrade
  3322:20241219:170517.412 completed 86% of database upgrade
  3322:20241219:170517.438 completed 87% of database upgrade
  3322:20241219:170517.485 completed 88% of database upgrade
  3322:20241219:170518.185 completed 89% of database upgrade
  3322:20241219:170518.188 completed 90% of database upgrade
  3322:20241219:170518.194 completed 91% of database upgrade
  3322:20241219:170518.233 completed 92% of database upgrade
  3322:20241219:170518.238 completed 93% of database upgrade
  3322:20241219:170518.243 completed 94% of database upgrade
  3322:20241219:170520.911 completed 95% of database upgrade
  3322:20241219:170520.926 completed 96% of database upgrade
  3322:20241219:170521.239 completed 97% of database upgrade
  3322:20241219:170521.244 completed 98% of database upgrade
  3322:20241219:170521.247 completed 99% of database upgrade
  3322:20241219:170521.252 completed 100% of database upgrade
  3322:20241219:170522.053 database upgrade fully completed

4. 前端配置

通过浏览器输入 IP:Port 访问前端界面进行配置。

四、处理报错

查看 服务端日志,会有一个 不能更新数据库 组件的提示。database could be upgraded to use primary keys in history tables

1. 报错原因

Zabbix历史的数据和趋势数据的数值(浮点型)数据类型支持的精度更高,需要手动更新数据库补丁。

处理补丁的地址: https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/database/mysql/double.sql

2. 解决方式

bash 复制代码
#进入zabbix库执行命令
> ALTER TABLE trends
	MODIFY value_min DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
	MODIFY value_avg DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
	MODIFY value_max DOUBLE PRECISION DEFAULT '0.0000' NOT NULL;
ALTER TABLE history MODIFY value DOUBLE PRECISION DEFAULT '0.0000' NOT NULL;

> ALTER TABLE history MODIFY value DOUBLE PRECISION DEFAULT '0.0000' NOT NULL;

执行了上面的操作之后,依旧会报 database could be upgraded to use primary keys in history tables,猜测可能是里面有数据导致,清空数据重新创建表则不会报这个提示了。不改也不影响使用,后续随着历史数据的自动清理就慢慢恢复正常。

处理的这个问题的 SQL 在前端文件里面有这个,路径如下:

bash 复制代码
[root@10-10-83-202 option-patches]# pwd 
/usr/share/zabbix/sql-scripts/mysql/option-patches
[root@10-10-83-202 option-patches]# cat history_upgrade_prepare.sql |grep -i DOUBLE
        `value` DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,

Reference:
https://www.zabbix.com/cn/whats_new_7_2
https://www.zabbix.com/documentation/current/zh/manual/installation/requirements
https://www.zabbix.com/documentation/current/en/manual/appendix/install/db_primary_keyshttps://www.myfreax.com/how-to-install-php-8-2-on-centos-8/amp/

相关推荐
连胜优佳2 小时前
1.zabbix概述
前端·zabbix
小王格子16 小时前
Zabbix6.0升级为6.4
zabbix·zabbix 6.0·zabbix升级
海绵宝宝990011 天前
如何实现远程对主机进行关机、重启操作
运维·服务器·zabbix
zhlh_xt13 天前
Zabbix监控Oracle 19c数据库完整配置指南
数据库·oracle·zabbix·sop·监控oracle数据库
小城印象19 天前
使用zabbix监控k8s
容器·kubernetes·zabbix
胆小如鼠21 天前
zabbix搭建教程
zabbix
zhlh_xt22 天前
CentOS上如何离线批量自动化部署zabbix 7.0版本客户端
centos·自动化·zabbix·zabbix-agent2·自动化安装脚本
OpsEye22 天前
Grafana插件安装并接入zabbix数据源
数据库·zabbix·grafana
乐维_lwops22 天前
Zabbix 模板翻译自动化教程
zabbix·zabbix模板