背景

Zabbix 6.0 在 2 月份正式release 了 , 一直想尝试新版本里面带来的提升, 所以准备将当前生产环境的Zabbix 5.0 升级到 6.0 , 所以在这里做一下记录 , 同时也供他人升级参考.

环境说明:

OS: debian10
Zabbix: 5.0
PHP: 7.3.31
mariadb :10.3.34

升级前准备

设置维护模式

为防止升级后有告警 , 这里先设置维护模式 , 我这里维护模式设置的时间是12小时.

停止Zabbix服务

systemctl stop zabbix-server zabbix-agent apache2

数据备份

原有配置备份

sudo su
mkdir /opt/zabbix_backup
cp  /etc/zabbix/zabbix_server.conf /opt/zabbix_backup/
cp  /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix_backup/
cp -R /usr/share/zabbix/ /opt/zabbix_backup/
cp -R /usr/share/doc/zabbix-* /opt/zabbix_backup/

数据库备份

单独备份zabbix数据库

cd /opt/zabbix_backup/
mysqldump -uroot -p zabbix --single-transaction > zabbix_backup.sql

数据库全量备份

这里需要再次对数据库做一个完整备份, 以免发生意外情况 , 事实是意外情况确实发生了, 有兴趣的可以继续往后看.

针对mariadb 官方有推荐的备份方式 ,具体使用请参照后面的refer部分.

安装备份工具

这里使用 mariadb-backup 进行全量备份 , 安装使用如下命令;

apt-get install mariadb-backup

执行全量备份

因为后面升级出问题 , 这里把备份恢复的命令一次贴出来,以备后用.

# 运行完整备份
mkdir /tmp/mariadb-backup
mariabackup --backup -user=root --target-dir=/opt/mariadb-backup

# 准备备份数据
mariabackup --prepare --target-dir=/opt/mariadb-backup

# 恢复数据库
mariabackup --copy-back --target-dir=/opt/mariadb-backup
chown -R mysql:mysql /var/lib/mysql

到此, 数据备份相关的工作准备完毕.

执行升级

数据库升级

删除数据库

# 停止服务
systemctl stop mariadb

# 删除 mariadb
apt-get remove "mariadb-*"

#删除依赖,10.3以前是galera-3 , 10.4以后是galera-4
apt-get remove galera-3

安装新版数据库

# 增加repo 、安装新版本 mariadb 并启动服务
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
echo "b9e90cde27affc2a44f9fc60e302ccfcacf71f4ae02071f30d570e6048c28597 mariadb_repo_setup" \
    | sha256sum -c -
chmod +x mariadb_repo_setup
./mariadb_repo_setup --mariadb-server-version="mariadb-10.5"
apt-get update
apt-get install -y mariadb-server mariadb-backup
systemctl start mariadb

执行数据目录升级

新版本附带的命令, 用于纠正、识别兼容性问题.

# mariadb-upgrade
This installation of MariaDB is already upgraded to 10.5.16-MariaDB.
There is no need to run mysql_upgrade again for 10.5.16-MariaDB.
You can use --force if you still want to run mysql_upgrade
# 这里提示加force参数进行升级.
#增加force参数升级过程如下
# mysql_upgrade --force
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.column_stats                                 OK
mysql.columns_priv                                 OK
mysql.db                                           OK
# 过程太长,部分过程省略
...
zabbix.valuemaps                                   OK
zabbix.widget                                      OK
zabbix.widget_field                                OK
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK
# 版本验证
# mariadb -V
mariadb  Ver 15.1 Distrib 10.5.16-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Zabbix 升级

删除zabbix 5.0 源

dpkg --purge zabbix-release

安装新源&版本升级

wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-1+debian10_all.deb
dpkg -i zabbix-release_6.0-1+debian10_all.deb
apt-get update
apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php zabbix-agent
# 升级过程中遇到回答问题的选项一律选 N 回车即可 
# 版本验证

# zabbix_server -V
zabbix_server (Zabbix) 6.0.5

# 设置自启动
# Start Zabbix 6.0
systemctl enable zabbix-server mariadb.service

异常问题处理

问题描述 ; 升级后出现数据库版本不match

在这里插入图片描述

解决方案;

停用zabbix相关服务

systemctl stop zabbix-server zabbix-agent apache2

停止 mariadb 服务

systemctl stop mariadb.service

移动原有数据库

mv -f /var/lib/mysql/* /var/lib/mysql-files/

恢复数据库(全量)

mariabackup --copy-back --target-dir=/opt/mariadb-backup
chown -R mysql:mysql /var/lib/mysql
mysql_upgrade --force

启动Zabbix 服务

systemctl stop zabbix-server zabbix-agent apache2

经过以上处理后 , 通过查看zabbix_server.log可以发现 ,

#省略上下文
...
1871:20220608:143935.311 optional patches were found
1871:20220608:143935.311 starting automatic database upgrade
1871:20220608:143935.315 completed 0% of database upgrade
1871:20220608:143935.319 completed 1% of database upgrade
1871:20220608:143935.332 completed 2% of database upgrade
1871:20220608:143935.343 completed 3% of database upgrade
1871:20220608:143935.353 completed 4% of database upgrade
...
1871:20220608:143951.503 completed 96% of database upgrade
1871:20220608:143951.563 completed 97% of database upgrade
1871:20220608:143951.571 completed 98% of database upgrade
1871:20220608:143951.576 completed 99% of database upgrade
1871:20220608:143951.581 completed 100% of database upgrade
1871:20220608:143951.581 database upgrade fully completed
1871:20220608:143951.584 database could be upgraded to use primary keys in history tables
2054:20220608:143951.594 starting HA manager
2054:20220608:143951.601 HA manager started in active mode
1871:20220608:143951.608 server #0 started [main process]
...

至此 , Zabbix 升级问题处理完成 , 在此以作记录供他人升级参考.

参考
MariaDB Backup:
https://mariadb.com/docs/reference/cs10.5/cli/mariadb-backup/

Logo

华为云1024程序员节送福利,参与活动赢单人4000元礼包,更有热门技术干货免费学习

更多推荐