2 Debian/Ubuntu
概述
本章节提供了在 Debian/Ubuntu 上使用 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 Debian/Ubuntu.
虽然升级 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:
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.log
或 tail -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.
# service zabbix-server stop
如果需要升级 Zabbix proxy,那么同样停止 Zabbix proxy 进程。
If upgrading Zabbix proxy, stop proxy too.
# service zabbix-proxy stop
众所周知,仅升级 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.
配置文件:
Configuration files:
# mkdir /opt/zabbix-backup/
# cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
# cp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix-backup/
PHP 文件和 Zabbix 二进制文件:
PHP files and Zabbix binaries:
# cp -R /usr/share/zabbix/ /opt/zabbix-backup/
# cp -R /usr/share/doc/zabbix-* /opt/zabbix-backup/
4 升级 Zabbix 软件仓库配置包
在升级之前,必须卸载当前的软件仓库包:
To proceed with the update your current repository package has to be uninstalled.
# rm -Rf /etc/apt/sources.list.d/zabbix.list
然后再安装新的软件仓库包:
Then install the new repository configuration package.
在 Debian 9 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/debian/pool/main/z/zabbix-release/zabbix-release_3.5-1+stretch_all.deb
# dpkg -i zabbix-release_3.5-1+stretch_all.deb
在 Debian 8 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/debian/pool/main/z/zabbix-release/zabbix-release_3.5-1+jessie_all.deb
# dpkg -i zabbix-release_3.5-1+jessie_all.deb
在 Debian 7 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/debian/pool/main/z/zabbix-release/zabbix-release_3.5-1+wheezy_all.deb
# dpkg -i zabbix-release_3.5-1+wheezy_all.deb
在 Ubuntu 18.04 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.5-1+bionic_all.deb
# dpkg -i zabbix-release_3.5-1+bionic_all.deb
在 Ubuntu 16.04 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.5-1+xenial_all.deb
# dpkg -i zabbix-release_3.5-1+xenial_all.deb
在 Ubuntu 14.04 上运行:
# wget http://repo.zabbix.com/zabbix/3.5/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.5-1+trusty_all.deb
# dpkg -i zabbix-release_3.5-1+trusty_all.deb
更新软件仓库信息。
Update the repository information.
# apt-get update
5 升级 Zabbix 组件
运行以下命令以升级 Zabbix 组件:
To upgrade Zabbix components you may run something like:
# apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php 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.
关于新的选项参数,详见 Zabbix 4.0.0 新特性 章节。
For new optional parameters, see the What’s new section.
7 启动 Zabbix 进程
启动升级后的 Zabbix 组件。
Start the updated Zabbix components.
# service zabbix-server start
# service zabbix-proxy start
# service zabbix-agent start
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 minor versions of 4.0.x (for example, from 4.0.1 to 4.0.3). It is easy.
在升级 Zabbix 所有组件的次要版本时,只需运行以下命令:
To upgrade Zabbix minor version please run:
$ sudo apt install --only-upgrade 'zabbix.*'
在升级 Zabbix server 的次要版本时,只需运行以下命令:
To upgrade Zabbix server minor version please run:
$ sudo apt install --only-upgrade 'zabbix-server.*'
在升级 Zabbix agent 的次要版本时,只需运行以下命令:
To upgrade Zabbix agent minor version please run:
$ sudo apt install --only-upgrade 'zabbix-agent.*'