现有环境:
- Debian 10(Buster)
- Zabbix 5.0LTS
系统相关信息
- IP:10.8.8.106
- Nginx:1.4.12
- Mariadb:10.3.31
目标
- 系统升级至11(Bullseye)
- Zabbix升级至6.0LTS
升级系统
更换源
mv /etc/apt/sources.list /etc/apt/sources.list.bak
nano /etc/apt/sources.list
添加以下内容
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
升级
apt update && apt full-upgrade -y
如果出现apt提示,按q
(无图)
如果出现此提示,选择yes
如果出现下图提示,这是由于更改了某些配置,现在默认N即可
保留当前版本ssh配置文件
等升级完成后,重启
清理残留
apt --purge autoremove
apt autoclean
至此,系统升级完毕
升级zabbix
停止zabbix
systemctl stop zabbix-server
备份zabbix文件
mkdir -p /opt/zabbix_backup/bin_files /opt/zabbix_backup/conf_files /opt/zabbix_backup/doc_files
mkdir -p /opt/zabbix_backup/web_files /opt/zabbix_backup/db_files
cp -rp /etc/zabbix/zabbix_server.conf /opt/zabbix_backup/conf_files
cp -rp /usr/sbin/zabbix_server /opt/zabbix_backup/bin_files
cp -rp /usr/share/doc/zabbix-* /opt/zabbix_backup/doc_files
cp -rp /etc/httpd/conf.d/zabbix.conf /opt/zabbix_backup/conf_files 2>/dev/null
cp -rp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix_backup/conf_files 2>/dev/null
cp -rp /etc/zabbix/php-fpm.conf /opt/zabbix_backup/conf_files 2>/dev/null
cp -rp /usr/share/zabbix/ /opt/zabbix_backup/web_files
备份数据库,提示输入数据库root账号密码
mysqldump -h localhost -u'root' -p --single-transaction 'zabbix' | gzip > /opt/zabbix_backup/db_files/zabbix_backup.sql.gz
清理zabbix源
dpkg --purge zabbix-release
安装zabbix 6.0源
wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-1+debian11_all.deb
dpkg -i zabbix-release_6.0-1+debian11_all.deb
apt update
apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
启动zabbix
systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm
等待并检查是否完成升级
cat /var/log/zabbix/zabbix_server.log | grep database
如果出现以下内容,则升级完成
567:20220316:134359.729 current database version (mandatory/optional): 05000000/05000005
2793:20220316:140131.257 current database version (mandatory/optional): 05000000/05000005
2793:20220316:140131.257 starting automatic database upgrade
2793:20220316:140131.261 completed 0% of database upgrade
2793:20220316:140131.265 completed 1% of database upgrade
2793:20220316:140131.274 completed 2% of database upgrade
2793:20220316:140131.282 completed 3% of database upgrade
2793:20220316:140131.290 completed 4% of database upgrade
2793:20220316:140131.299 completed 5% of database upgrade
*******
2793:20220316:140145.630 completed 85% of database upgrade
2793:20220316:140145.638 completed 86% of database upgrade
2793:20220316:140145.643 completed 87% of database upgrade
2793:20220316:140145.644 completed 88% of database upgrade
2793:20220316:140145.656 completed 89% of database upgrade
2793:20220316:140145.859 completed 90% of database upgrade
2793:20220316:140145.884 completed 91% of database upgrade
2793:20220316:140145.899 completed 92% of database upgrade
2793:20220316:140145.916 completed 93% of database upgrade
2793:20220316:140145.930 completed 94% of database upgrade
2793:20220316:140145.940 completed 95% of database upgrade
2793:20220316:140145.946 completed 96% of database upgrade
2793:20220316:140145.968 completed 97% of database upgrade
2793:20220316:140145.994 completed 98% of database upgrade
2793:20220316:140145.997 completed 99% of database upgrade
2793:20220316:140145.998 completed 100% of database upgrade
2793:20220316:140145.998 database upgrade fully completed
2793:20220316:140145.999 database could be upgraded to use primary keys in history tables
出现database upgrade fully completed即升级成功
清理数据库及升级主键
然后运行“history_pk_prepare.sql”脚本重命名旧的历史表,并使用新的主键及创建新的历史表,按照提示输入数据库zabbix用户的密码
mysql -uroot -p zabbix < /usr/share/doc/zabbix-sql-scripts/mysql/history_pk_prepare.sql
将数据从旧历史记录表迁移到新历史记录表
mkdir /var/lib/mysql-files && chmod 777 /var/lib/mysql-files
mysql zabbix
SET SESSION SQL_LOG_BIN=0;SET SESSION bulk_insert_buffer_size= 1024 * 1024 * 256;SET MAX_STATEMENT_TIME=0;
SELECT * INTO OUTFILE '/var/lib/mysql-files/history.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_old;
LOAD DATA INFILE '/var/lib/mysql-files/history.csv' IGNORE INTO TABLE history FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_uint.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_uint_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_uint.csv' IGNORE INTO TABLE history_uint FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_str.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_str_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_str.csv' IGNORE INTO TABLE history_str FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_log.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_log_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_log.csv' IGNORE INTO TABLE history_log FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
SELECT * INTO OUTFILE '/var/lib/mysql-files/history_text.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_text_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_text.csv' IGNORE INTO TABLE history_text FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
结束