Zabbix 5.2 更新 5.4

未分類

最近在做系統更新要把 Zabbix 更新所以紀錄一下升級過程,過程其實不太順利發生了很多問題,所以就紀錄了一下更新方法如果遇到問題的可以依照我的方法解決升級問題,我目前跑系統都正常

建立備份

$ mkdir /opt/zabbix_backup/

$ cp /etc/zabbix/zabbix_server.conf /opt/zabbix_backup/
$ cp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix_backup/

備份資料庫

$ mysqldump -h localhost -u'root' -p --single-transaction 'zabbix' | gzip > /opt/zabbix_backup/db_files/zabbix_backup.sql.gz

還原資料庫

mysql -u'root' -p -e "drop database zabbix"
mysql -u'root' -p -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -u'root' -p -e "grant all privileges on zabbix.* to [email protected] identified by 'zabbixDBpass';"

mysql -u'root' -p zabbix -e "set global innodb_strict_mode='OFF';"
zcat /opt/zabbix_backup/db_files/zabbix_backup.sql.gz | mysql -h localhost -u'root' -p'rootDBpass' 'zabbix'
mysql -u'root' -p zabbix -e "set global innodb_strict_mode='ON';"

查詢更新進度

$ cat /var/log/zabbix/zabbix_server.log | grep database

更新資料庫發生錯誤

更新過程發現會卡在 68% 就不會跑了,測試幾次問題都是一樣的

 31884:20210605:080454.284 completed 50% of database upgrade
 31884:20210605:080454.314 completed 51% of database upgrade
 31884:20210605:080454.317 completed 52% of database upgrade
 31884:20210605:080454.328 completed 53% of database upgrade
 31884:20210605:080454.331 completed 54% of database upgrade
 31884:20210605:080454.334 completed 55% of database upgrade
 31884:20210605:080454.370 completed 56% of database upgrade
 31884:20210605:080454.441 completed 57% of database upgrade
 31884:20210605:080454.502 completed 58% of database upgrade
 31884:20210605:080454.530 completed 59% of database upgrade
 31884:20210605:080454.542 completed 60% of database upgrade
 31884:20210605:080454.621 completed 61% of database upgrade
 31884:20210605:080454.632 completed 62% of database upgrade
 31884:20210605:080454.699 completed 63% of database upgrade
 31884:20210605:080454.811 completed 64% of database upgrade
 31884:20210605:080454.831 completed 65% of database upgrade
 31884:20210605:080454.842 completed 66% of database upgrade
 31884:20210605:080454.944 completed 67% of database upgrade
 31884:20210605:080455.014 completed 68% of database upgrade
 31884:20210605:080455.017 database upgrade failed
 31928:20210605:080505.223 current database version (mandatory/optional): 05030161/05030161
 31928:20210605:080505.223 starting automatic database upgrade

查詢系統 Log

所以就去查了一下開啟系統時發生的問題

$ cat /var/log/zabbix/zabbix_server.log
 29816:20210605:074358.214 Starting Zabbix Server. Zabbix 5.4.0 (revision 5059e20a75).
 29816:20210605:074358.214 ****** Enabled features ******
 29816:20210605:074358.214 SNMP monitoring:           YES
 29816:20210605:074358.214 IPMI monitoring:           YES
 29816:20210605:074358.214 Web monitoring:            YES
 29816:20210605:074358.214 VMware monitoring:         YES
 29816:20210605:074358.214 SMTP authentication:       YES
 29816:20210605:074358.214 ODBC:                      YES
 29816:20210605:074358.214 SSH support:               YES
 29816:20210605:074358.214 IPv6 support:              YES
 29816:20210605:074358.214 TLS support:               YES
 29816:20210605:074358.214 ******************************
 29816:20210605:074358.214 using configuration file: /etc/zabbix/zabbix_server.conf
 29816:20210605:074358.221 Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037
 29816:20210605:074358.222 current database version (mandatory/optional): 05030069/05030069
 29816:20210605:074358.222 required mandatory version: 05040000
 29816:20210605:074358.222 starting automatic database upgrade
 29816:20210605:074358.223 [Z3005] query failed: [1832] Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]
 29816:20210605:074358.223 database upgrade failed

解決方法

查了一下解決方法發現需要更新 MariaDB

https://www.zabbix.com/forum/zabbix-troubleshooting-and-problems/424860-ubuntu-18-04-zabbix-5-0-5-to-5-4-upgrade-database-failed-error

更新 MariaDB

因為我的系統是 Ubuntu 18.04 LTS 沒辦法直接更新到 MariaDB Community Server 10.5,所以查了一下文件發現需要手動更新

https://mariadb.com/docs/deploy/upgrade-community-server-cs105-ubuntu18/

sudo apt install  apt-transport-https
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
echo "417ea3052a78a11f022c596e29360cd0568161e0ffb17067589421883c34bc99 mariadb_repo_setup" | sha256sum -c -
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup --mariadb-server-version="mariadb-10.5"
sudo apt install mariadb-server

更新後系統會自動重跑資料庫更新

打開看 Log 還是有點問題,這邊因為 MariaDB 10.2.2 開始設定 immodb 為嚴格模式

 32233:20210605:080657.963 Starting Zabbix Server. Zabbix 5.4.0 (revision 5059e20a75).
 32233:20210605:080657.963 ****** Enabled features ******
 32233:20210605:080657.963 SNMP monitoring:           YES
 32233:20210605:080657.963 IPMI monitoring:           YES
 32233:20210605:080657.963 Web monitoring:            YES
 32233:20210605:080657.963 VMware monitoring:         YES
 32233:20210605:080657.963 SMTP authentication:       YES
 32233:20210605:080657.963 ODBC:                      YES
 32233:20210605:080657.963 SSH support:               YES
 32233:20210605:080657.963 IPv6 support:              YES
 32233:20210605:080657.963 TLS support:               YES
 32233:20210605:080657.963 ******************************
 32233:20210605:080657.963 using configuration file: /etc/zabbix/zabbix_server.conf
 32233:20210605:080657.972 Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037
 32233:20210605:080657.973 current database version (mandatory/optional): 05030161/05030161
 32233:20210605:080657.973 required mandatory version: 05040000
 32233:20210605:080657.973 starting automatic database upgrade
 32233:20210605:080657.976 [Z3005] query failed: [1118] Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs [alter table `config` add `url` varchar(255) default '' not null]
 32233:20210605:080657.976 database upgrade failed

這邊變更一下模式把它關掉就可以解決這個問題設定檔在 “/etc/my.conf” 或 “/etc/my.cnf.d/server.cnf” 找到 [mysqld] 在下方加入

innodb_strict_mode=0

Database history tables upgraded 修正

修正後完成就可以打開網頁了,不過還是看到上面出現 “Database history tables upgraded” 的問題,這邊需要手動修改資料庫才可以升級成功,這升級的路上真是辛苦。

手動登入 zabbix 的資料庫查詢欄位

mysql -u'zabbix' -p'zabbixDBpass' zabbix -e "show create table history;"

| history | CREATE TABLE history (
itemid bigint(20) unsigned NOT NULL,
clock int(11) NOT NULL DEFAULT '0',
value double(16,4) NOT NULL DEFAULT '0.0000',
ns int(11) NOT NULL DEFAULT '0',
KEY history_1 (itemid,clock)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |

檢查是不是 0.0000

下載修正檔後更新到資料庫

wget https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/database/mysql/double.sql
mysql -u'zabbix' -p zabbix < double.sql

再次確認

$ mysql -u'zabbix' -p'zabbixDBpass' zabbix -e "show create table history;"

history | CREATE TABLE history (
itemid bigint(20) unsigned NOT NULL,
clock int(11) NOT NULL DEFAULT '0',
value double NOT NULL DEFAULT '0',
ns int(11) NOT NULL DEFAULT '0',
KEY history_1 (itemid,clock)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |

設定 /etc/zabbix/web/zabbix.conf.php 加入以下

$DB['DOUBLE_IEEE754'] = 'true';

完成!

參考資料