升级至Zabbix 6.0后遇到了数据库错误

环境

・Ubuntu 20.04
・MariaDB 10.3
将 Zabbix 4.2 升级至 6.0

升级到Zabbix6.0

由于公式手续已准备好,我们将按照这些步骤进行升级。

 

麻烦

Zabbix升级顺利完成,但前端显示数据库错误。

The Zabbix database version does not match current requirements. 
Your database version: 4020000. Required version: 6000000. Please contact your system administrator.

在/var/log/zabbix/zabbix_server.log文件中没有任何日志输出,原因不明。

在MariaDB的情况下,数据库的支持版本首先需要10.5以上,因此我们将MariaDB从10.3升级到了10.5。

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 53948
Server version: 10.5.15-MariaDB-1:10.5.15+maria~focal mariadb.org binary distribution

在升级MariaDB后,尽管前端仍然显示上述的数据库错误,但是现在日志已经开始输出到/var/log/zabbix/zabbix_server.log文件中。

  4859:20220329:010905.627 Starting Zabbix Server. Zabbix 6.0.1 (revision a80cb13868).
 ・・・(略)
  4859:20220329:010905.628 using configuration file: /etc/zabbix/zabbix_server.conf
  4859:20220329:010905.664 Zabbix supports only "utf8,utf8mb3,utf8mb4" character set(s). Database "zabbix" has default character set "latin1"
  4859:20220329:010905.664 Zabbix supports only "utf8_bin,utf8mb3_bin,utf8mb4_bin" collation(s). Database "zabbix" has default collation "latin1_swedish_ci"
  4859:20220329:010905.690 character set name or collation name that is not supported by Zabbix found in 392 column(s) of database "zabbix"
  4859:20220329:010905.694 only character set(s) "utf8,utf8mb3,utf8mb4" and corresponding collation(s) "utf8_bin,utf8mb3_bin,utf8mb4_bin" should be used in database
  4859:20220329:010905.696 current database version (mandatory/optional): 04030004/04030004
  4859:20220329:010905.696 required mandatory version: 06000000
  4859:20220329:010905.696 starting automatic database upgrade
  4859:20220329:010906.335 [Z3005] query failed: [1366] Incorrect string value: '\xE3\x81\x9D\xE3\x81\xAE...' for column `zabbix`.`item_rtdata`.`error` at row 68 [insert into item_rtdata (itemid,lastlogsize,state,mtime,error) select i.itemid,i.lastlogsize,i.state,i.mtime,i.error from items i join hosts h on i.hostid=h.hostid where h.status in (0,1) and i.flags<>2]
  4859:20220329:010906.378 database upgrade failed

解决问题

检查日志中的item_rtdata列后发现其Collation为latin1_swedish_ci,因此执行以下命令。

ALTER TABLE zabbix.item_rtdata CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;

Zabbix已成功启动,前端错误也已消除,升级成功完成。