2022 Zabbix中国峰会
2022 Zabbix中国峰会

1 Red Hat Enterprise Linux/CentOS

概述

本章节提供了在 Red Hat Enterprise Linux/CentOS 上使用 Zabbix 二进制包,从 Zabbix 3.4.x 成功升级至 Zabbix 4.0 所需的步骤。

This section provides the steps required for a successful upgrade from Zabbix 3.4.x to Zabbix 4.0.x using official Zabbix packages for Red Hat Enterprise Linux/CentOS.

虽然升级 Zabbix agent 不是强制性的,但建议将其升级,而 Zabbix server 和 Zabbix proxy 必须具有 相同的主要版本。因此,在 Zabbix server 和 Zabbix proxy 的架构升级时,Zabbix server 和所有的 Zabbix proxy 必须停止并升级。

While upgrading Zabbix agents is not mandatory (but recommended), Zabbix server and proxies must be of the same major version. Therefore, in a server-proxy setup, Zabbix server and all proxies have to be stopped and upgraded.

为了最大限度地减少升级期间的停机时间和数据丢失的几率,建议先停机并升级 Zabbix server,然后再逐个停机并升级 Zabbix proxy,待升级完毕后,先启动 Zabbix proxy,再启动 Zabbix server。在 Zabbix server 停机期间,运行中的 Zabbix Proxy 将继续采集和存储数据,并在 Zabbix server 启动并运行后,将数据传递给 Zabbix server。 只有在升级的 Zabbix server 启动后,才会生成 Zabbix server停机期间出现问题的任何通知。

To minimize downtime and data loss during the upgrade, it is recommended to stop and upgrade Zabbix server and then stop, upgrade and start Zabbix proxies one after another. When all proxies are upgraded, start Zabbix server. During the Zabbix server downtime, running proxies will keep collecting and storing data and will pass the data to Zabbix server when the server is up and running. Any notifications for problems during Zabbix server downtime will be generated only after the upgraded server is started.

请注意,对于 Zabbix proxy 上的 SQLite 数据库,升级前 Zabbix proxy 的历史数据将丢失,因为不支持 SQLite 数据库升级,而且必须手动删除 SQLite 数据库文件。 当第一次启动 Zabbix proxy 并且缺少 SQLite 数据库文件时,Zabibx proxy 会自动创建它。

Note that with SQLite database on proxies, history data from proxies before the upgrade will be lost, because SQLite database upgrade is not supported and the SQLite database file has to be manually removed. When proxy is started for the first time and the SQLite database file is missing, proxy creates it automatically.

根据其数据库大小,数据库升级到 4.0 版本可能需要很长时间。

Depending on database size the database upgrade to version 4.0 may take a long time.

<note warning>值得注意的是,在升级之前,请务必阅读相关的升级说明! :::

Before the upgrade make sure to read the relevant upgrade notes!

请阅读下面的升级说明:

The following upgrade notes are available:

早期版本 详细的 本升级说明 版本之间升级的重要说明/
3.4.x 升级至 4.0 'l bpthread' 和 'zlib' 库现在是必需的。;
Support for plain text protocol dropped and header is mandatory;
不再支持 1.4 版本之前的 Zabbix agent;
Zabibx proxy 被动模式配置的 Server 参数现在是必需的。
3.2.x 升级至 3.4 SQ ite support as backend database dropped for Zabbix server/frontend;
Perl Compatible Regular Expressions (PCRE) supported instead of POSIX extended;
'libpcre' and 'libevent' libraries mandatory for Zabbix server;
Exit code checks added for user parameters, remote commands and system.run[] items without the 'nowait' flag as well as Zabbix server executed scripts;
Zabbix Java gateway has to be upgraded to support new functionality
3.0.x 升级至 3.2 Da abase upgrade may be slow, depending on the history table size
Upgrade from Read full upgrade notes Important notes/changes between versions
3.4.x For 4.0 'libpthread' and 'zlib' libraries now mandatory;
Support for plain text protocol dropped and header is mandatory;
Pre-1.4 version Zabbix agents are no longer supported;
The Server parameter in passive proxy configuration now mandatory
3.2.x Also for 3.4 SQLite support as backend database dropped for Zabbix server/frontend;
Perl Compatible Regular Expressions (PCRE) supported instead of POSIX extended;
'libpcre' and 'libevent' libraries mandatory for Zabbix server;
Exit code checks added for user parameters, remote commands and system.run[] items without the 'nowait' flag as well as Zabbix server executed scripts;
Zabbix Java gateway has to be upgraded to support new functionality
3.0.x Also for 3.2 Database upgrade may be slow, depending on the history table size

此外,还需检查升级至 Zabbix 4.0 的需求

You may also want to check the requirements for 4.0.

建议在升级期间运行两个 SSH 会话,其中一个会话执行升级步骤,另一个会话监控其升级期间的日志。例如,在第二个 SSH 会话上运行 tail -f zabbix_server.logtail -f zabbix_proxy.log,以实时显示最新的常规日志输出或错误日志输出。这对生产环境至关重要。

It may be handy to run two parallel SSH sessions during the upgrade, executing the upgrade steps in one and monitoring the server/proxy logs in another. For example, run tail -f zabbix_server.log or tail -f zabbix_proxy.log in the second SSH session showing you the latest log file entries and possible errors in real time. This can be critical for production instances.

升级步骤

1 停止 Zabbix 进程

停止 Zabbix server 以确保没有新数据插入数据库。

Stop Zabbix server to make sure that no new data is inserted into database.

# systemctl stop zabbix-server

如果需要升级 Zabbix proxy,那么同样停止 Zabbix proxy 进程。

If upgrading the proxy, stop proxy too.

# systemctl stop zabbix-proxy

众所周知,仅升级 Zabbix server 而不升级 Zabbix proxy ,并且未升级的 Zabibx proxy 将数据发送至升级后的 Zabbix server 是可能的(Zabbix proxy 无法其刷新配置)。但是,不建议这样,Zabbix 不支持这样,选择这样做您需为其独自承担风险。

It is known to be possible to upgrade the server only and have older, yet unupgraded proxies report data to a newer server (the proxies can't refresh their configuration though). This approach, however, is not recommended and not supported by Zabbix and choosing it is entirely at your own risk.

2 备份当前的数据库

这是非常重要的步骤。升级前请确保备份了数据库。如果升级失败(因磁盘空间不足、断电或其他意外导致的升级失败),备份的数据库将大有帮助。

This is a very important step. Make sure that you have a backup of your database. It will help if the upgrade procedure fails (lack of disk space, power off, any unexpected problem).

3 备份配置文件、PHP 文件和 Zabbix 二进制文件

在升级前请确保备份了配置文件、PHP 文件和 Zabbix 二进制文件。

Make a backup copy of Zabbix binaries, configuration files and the PHP file directory.

配置文件:

# mkdir /opt/zabbix-backup/
       # cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
       # cp /etc/httpd/conf.d/zabbix.conf  /opt/zabbix-backup/

PHP 文件和 Zabbix 二进制文件:

# cp -R /usr/share/zabbix/ /opt/zabbix-backup/
       # cp -R /usr/share/doc/zabbix-* /opt/zabbix-backup/
4 升级 Zabbix 软件仓库配置包

在升级之前,必须更新当前的软件仓库包:

To proceed with the upgrade your current repository package has to be updated.

# rpm -Uvh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.centos.noarch.rpm
5 升级 Zabbix 组件

运行以下命令以升级 Zabbix 组件:

To upgrade Zabbix components you may run something like:

# yum upgrade zabbix-server-mysql zabbix-web-mysql zabbix-agent

如果使用 PostgreSQL 数据库,请将命令中的 mysql 替换为 pgsql。如果升级 Zabbix proxy,请将命令中的 server 替换为 proxy

If using PostgreSQL, substitute mysql with pgsql in the command. If upgrading the proxy, substitute server with proxy in the command.

6 检查 Zabbix 组件配置文件的参数

在新版本中,Zabbix 组件的配置文件发生了一些变化,关于这些强制变更,详见升级说明。

See the upgrade notes for details on mandatory changes.

7 启动 Zabbix 进程

启动升级后的 Zabbix 组件。

Start the updated Zabbix components.

# systemctl start zabbix-server
       # systemctl start zabbix-proxy
       # systemctl start zabbix-agent
8 清除浏览器的 Cookies 和缓存

待升级完毕后,可能需要清除浏览器的 Cookies 和缓存,以便 Zabbix 的 Web 界面能正常工作。

After the upgrade you may need to clear web browser cookies and web browser cache for the Zabbix web interface to work properly.

Zabbix 次要版本之间的升级

如果要升级 Zabbix 的次要版本(例如,从 4.0.1 升级至 4.0.3),是非常容易的:

It is possible to upgrade between minor versions of 4.0.x (for example, from 4.0.1 to 4.0.3). Upgrading between minor versions is easy.

在升级 Zabbix 所有组件的次要版本时,只需运行以下命令:

To execute Zabbix minor version upgrade it is required to run:

$ sudo yum upgrade 'zabbix-*'

在升级 Zabbix server 的次要版本时,只需运行以下命令:

To execute Zabbix server minor version upgrade run:

$ sudo yum upgrade 'zabbix-server-*'

在升级 Zabbix agent 的次要版本时,只需运行以下命令:

To execute Zabbix agent minor version upgrade run:

$ sudo yum upgrade 'zabbix-agent-*'

请注意,您也可以在这些命令中使用 'update' 而不是 'upgrade'。 虽然 'upgrade' 会删除过时的包,但 'update' 会保留它们。

Note that you may also use 'update' instead of 'upgrade' in these commands. While 'upgrade' will delete obsolete packages, 'update' will preserve them.