写在最前头,本文是个人通过测试和生产环境总结下来的文章,并作了小部分处理,文中可能会存在某些描述不准确或错误的地方,欢迎各位大佬评论指出,互相学习!
说明
以下内容涉及版本:
- Zabbix 3.0.4 --> 5.0.2
- MariaDB 5.5.65 && MySQL 5.7
- PHP 7.1 --> 7.4
- 升级后zabbix数据库要用utf8,utf8_bin !!
从Server端到Proxy端升级完成的这一段时间内监控数据可能会短暂缺失!!!!
Zabbix3.0
服务器:PHP-7.1 数据库(Mysql5.7) Web服务器(Nginx)
Zabbix5.0
- MySQL 5.5.62以上
- MariaDB 10.0.37以上
- PostgreSQL 9.2.24以上
基本要求:PHP-7.2以上
Myslq-5.5~8.0,需要InnoDB引擎
数据库用户权限(create table, drop table, create index, drop index)
Apache版本:1.3.12以上
PHP扩展
REDIS插件更新
Plugins.Redis.Password删除了 配置参数,现在添加了将密码作为关键参数传递的机会。有关详细信息,请参见Redis插件。
升级前准备
注意:升级的安装位置,以及某些获取数据的脚本
实验环境 Zabbix 3.0 ----> Zabbix 5.0 Mariadb 5.5 Nginx 1.18 PHP 7.1 —> PHP 7.4
Server依赖包
yum install pcre pcre-devel libevent libthread zlib libssh fping libcurl libxml2 net-snmp openssl
PHP要求
gd bcmath ctype libXML xmlreader xmlwriter session sockets mbstring gettext openssl mysqli ldap
先确定 Zabbix数据库密码、Zabbix-Server/Proxy 配置文件、PHP前端文件、二进制文件的位置
升级过程
Server
1、停止服务器
2、备份
2.1.备份Zabbix数据库
mysqldump -uroot -p******* --opt zabbix --set-gtid-purged=off > zabbix.sql.gz
#导入新库
重新新建zabbix数据库,直接导入备份的数据库
2.2备份Zabbix配置文件
#备份配置文件
mkdir -p /usr/local/zabbixupdate_backup/zabbix
cp -a /usr/local/zabbix/* /usr/local/zabbixupdate_backup/zabbix_server/
#备份Web端文件
mkdir -p /usr/local/zabbixupdate_backup/zabbix-web
cp -a /usr/local/nginx/html/zabbix/* /usr/local/zabbixupdate_backup/zabbix_web/
2.3备份php
which php
#备份php文件
mkdir -p /usr/local/zabbixupdate_backup/php
cp -a /usr/local/php/* /usr/local/zabbixupdate_backup/php
3、升级PHP
3.1.安装依赖以及扩展包
yum install libsqlite3x-devel libzip-devel libtool automake OpenIPMI-devel unixODBC-devel libssh2 -y
#安装oniguruma
wget https://github.com/kkos/oniguruma/archive/v6.9.5_rev1.tar.gz -O oniguruma-6.9.5_rev1.tar.gz
tar -zxvf oniguruma-6.9.5_rev1.tar.gz
cd
./autogen.sh
#编译
./configure --bindir=/usr/sbin/ \
--sbindir=/usr/sbin/ \
--libexecdir=/usr/libexec \
--sysconfdir=/etc/ \
--localstatedir=/var \
--libdir=/usr/lib64/ \
--includedir=/usr/include/ \
--datarootdir=/usr/share \
--infodir=/usr/share/info \
--localedir=/usr/share/locale \
--mandir=/usr/share/man/ \
--docdir=/usr/share/doc/onig
make && make install
#或rpm安装oniguruma
yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.5+rev1-2.el7.remi.x86_64.rpm
yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.5+rev1-2.el7.remi.x86_64.rpm
# 安装GD库以及其扩展,php7.4会对部分GD库的扩展不支持
wget https://github.com/libgd/libgd/releases/download/gd-2.3.0/libgd-2.3.0.tar.gz
tar -zxvf libgd-2.3.0.tar.gz
cd libgd-2.3.0
./configure --prefix=/usr/local/libgd/2_3_0
#提示 JPEG lib : yes
make && make install
export PKG_CONFIG_PATH=/usr/local/libgd/2_3_0/lib/pkgconfig
#ldap warning ,需要手动添加ldap到php.ini
cp -a /usr/lib64/libldap* /usr/lib/
find / -name ldap.so
#/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ldap.so 添加到php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/ldap.so
3.2查看旧版本php编译的参数
php -i | head
3.3.停止PHP-FPM服务
3.4.编译
注意(7.4.0) “gd改成 --enable-gd”
#旧参数
'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-mysqli' '--with-pdo-mysql' '--with-gd' '--with-png-dir=/usr/local/libpng' '--with-jpeg-dir=/usr/local/jpeg' '--with-freetype-dir=/usr/local/freetype' '--with-xpm-dir=/usr/' '--with-zlib-dir=/usr/local/zlib' '--with-iconv' '--enable-libxml' '--enable-xml' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--enable-opcache' '--enable-mbregex' '--enable-fpm' '--enable-mbstring' '--enable-ftp' '--enable-gd-native-ttf' '--with-openssl' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--without-pear' '--with-gettext' '--enable-session' '--with-mcrypt' '--with-curl' '--enable-ctype' '--enable-json'
#新参数
./configure --prefix=/usr/local/php --enable-opcache --with-config-file-path=/usr/local/php/etc --with-curl --enable-fpm --enable-gd --with-jpeg --with-png --with-freetype --with-iconv --enable-mbstring --with-mysqli=mysqlnd --with-openssl --enable-static --enable-sockets --enable-inline-optimization --with-zlib --disable-ipv6 --disable-fileinfo --disable-debug --enable-bcmath --enable-session --enable-xml --enable-mbstring --with-gettext --with-ldap=shared --with-libxml
make编译
make Install 安装
3.5.配置php-fpm
#具体情况根据php位置设置而定
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#www.conf的用户和组设为nginx的用户
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
3.6启动PHP-FPM
3.7.测试
<?php phpinfo(); ?>
4、升级Zabbix-server
编译位置:
源码包的位置:/usr/local/src/
确定编译的模块,去源码包中找到 config.log 查到旧参数
#旧参数
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-net-snmp --with-libcurl --with-gnutls --with-mysql=/usr/bin/mysql_config
#新参数
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-net-snmp --with-libcurl --with-libxml2 --enable-java --with-mysql=/usr/bin/mysql_config --with-unixodbc --with-ssh2 --with-openipmi --with-gnutls --with-ldap
Zabbix-web界面
#ui
cp -a /usr/local/src/zabbix-5.0.2/ui/* /usr/local/nginx/html/zabbix/
chown www:www /usr/local/nginx/html/zabbix -R
chmod 755 /usr/local/nginx/html/zabbix
到zabbix_server.conf注释此行
SenderFrequency #此参数取消,可以直接到页面设置,如下
打开Zabbix-Server日志随时观察变化
4.1.启动Server
4.2.Server启动日志报错
关于Zabbix升级过程某些问题会在官方文档记录,结合日志报错可以适当参考
官方文档 https://www.zabbix.com/documentation/5.0/manual/installation/upgrade_notes_500#configuration_parameters
1、only character set “utf8” and collation “utf8_bin” should be used in database
修改zabbix中表的字符集以及排序为utf8_bin
#先查出zabbix库下的表排序哪个不是utf8_bin
SHOW TABLE STATUS IN zabbix;
alter table `table_name` convert to character set utf8 COLLATE utf8_bin;
#查找出zabbix下所有表,改为utf8, utf8_bin
select
CONCAT('alter table ',a.table_name,' convert to character set utf8 collate utf8_bin;')
from (select table_name from information_schema.`TABLES` where TABLE_SCHEMA = 'zabbix') a;
2、database is not upgraded to use double precision values
Zabbix历史的数据和趋势数据的数值(浮点型)数据类型支持的精度更高,需要手动更新数据库补丁。
#进入zabbix库执行命令
ALTER TABLE trends
MODIFY value_min DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
MODIFY value_avg DOUBLE PRECISION DEFAULT '0.0000' NOT NULL,
MODIFY value_max DOUBLE PRECISION DEFAULT '0.0000' NOT NULL;
ALTER TABLE history MODIFY value DOUBLE PRECISION DEFAULT '0.0000' NOT NULL;
mysql命令位置 https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/database/mysql/double.sql
3、Zabbix supports only “utf8” character set. Database “zabbix” has default character set “latin1”
Zabbix supports only “utf8_bin” collation. Database “zabbix” has default collation “latin1_swedish_ci”
#查看database默认的字符集和排序是否为 utf-8
show variables like 'character_set_%';
show variables like 'collation_%';
ALTER DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
4、数据库报错汇总(注释为报错内容,其下为解决方法)
#[Z3005] query failed: [1091] Can't DROP 'c_dservices_2'; check that column/key exists [alter table dservices drop foreign key c_dservices_2]
ALTER TABLE dservices ADD CONSTRAINT c_dservices_2 FOREIGN KEY (dhostid) REFERENCES dservices (dserviceid) ON DELETE CASCADE;
#Can't DROP 'c_sessions_1'; check that column/key exists [alter table sessions drop foreign key c_sessions_1]
ALTER TABLE sessions ADD CONSTRAINT c_sessions_1 FOREIGN KEY (userid) REFERENCES users (userid) ON DELETE CASCADE;
#Can't DROP 'c_dchecks_1'; check that column/key exists [alter table dchecks drop foreign key c_dchecks_1]
ALTER TABLE `zabbix`.`dchecks` ADD CONSTRAINT `c_dchecks_1` FOREIGN KEY (`druleid`) REFERENCES `zabbix`.`drules` (`druleid`) ON DELETE CASCADE ON UPDATE RESTRICT;
#Can't DROP 'c_host_inventory_1'; check that column/key exists [alter table host_inventory drop foreign key c_host_inventory_1]
alter table host_inventory ADD CONSTRAINT `c_host_inventory_1` FOREIGN KEY (`hostid`) REFERENCES `hosts` (`hostid`) ON DELETE CASCADE
#an't DROP 'c_items_1'; check that column/key exists [alter table items drop foreign key c_items_1]
ALTER TABLE items ADD CONSTRAINT c_items_1 FOREIGN KEY (hostid) REFERENCES hosts (hostid) ON DELETE CASCADE;
Zabbix supports only "utf8_bin" collation. Database "zabbix" has default collation "utf8_general_ci"
4052:20201112:024704.441 character set name or collation name that is not supported by Zabbix found in 421 column(s) of database "zabbix"
4052:20201112:024704.441 only character set "utf8" and collation "utf8_bin" should be used in database
4052:20201112:024704.477 database is not upgraded to use double precision values
重启Server,查看日志没有报错即可
#当前版本=强制版本,Server即启动
12597:20201106:115142.228 current database version (mandatory/optional): 05000000/05000001
12597:20201106:115142.228 required mandatory version: 05000000
Proxy
#创建备份文件
mkdir -p /usr/local/zabbixupdate_backup/
1、停止Zabbix-proxy
2、备份数据库
mkdir -p /usr/local/zabbixupdate_backup/database/
mysqldump -uroot -p******** --opt zabbix_proxy --set-gtid-purged=off > zabbix_proxy.sql
3、备份proxy配置文件
#确定proxy配置文件位置
#备份到备份文件夹
cp -a /usr/local/zabbix/* /usr/local/zabbixupdate_backup/zabbix_proxy/
#编译
#旧参数
./configure --prefix=/usr/local/zabbix --enable-agent --enable-proxy --with-libcurl --with-mysql=/usr/bin/mysql_config --with-openssl
#新参数
./configure --prefix=/usr/local/zabbix --enable-proxy --enable-agent --with-mysql=/usr/bin/mysql_config --with-ssh2 --with-openssl --with-libcurl
make && make install
cp /usr/local/zabbixupdate_backup/zabbix_proxy/etc/zabbix_proxy.conf /usr/local/zabbix/etc/
打开proxy日志随时观察变化
4、启动proxy
启动proxy后zabbix会自动升级数据库,日志会记录数据库升级情况,升级完成有 “database upgrade fully completed”提示
5、脚本升级
脚本放在个人目录的【脚本】文件夹中。
退环境
如果有特殊情况需要退环境,Zabbix 3.0使用 PHP7.4会有部分问题,Web端红框会提示于以下内容,此问题在Zabbix 4.0.16版本修复,所以退环境意味着PHP也需要回退到7.1以下
Array and string offset access syntax with curly braces is deprecated [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_latest_issues() → CTag->setMenuPopup() → CTag->setAttribute() → CHtml::serialize() → CJs::encodeJson() → spl_autoload_call() → CAutoloader->loadClass() → require() in include/classes/core/CAutoloader.php:59]
1、导入备份数据库
因为升级到Zabbix 5.0后会自动更新数据库,退环境后的版本无法使用更新后的库,启动日志会提示“The server does not match Zabbix database. Current database version (mandatory/optional): 05000000/05000001”
#重新导入备份的数据库
MariaDB [(zabbix)]> source ***.sql
2、删除Zabbix 5.0 配置文件
3、重新编译Zabbix 3.0并启动 (注意:Zabbix 5.0前端文件跟以往版本不同,需要修改)
参考
可以适当参考其他升级步骤,但经过实践得出很多情况与实际不同
https://hqidi.com/150.html 升级php参考
https://www.jianshu.com/p/ca54caa2080b 升级php参考
https://www.zabbix.com/documentation/5.0/manual/installation/upgrade/sources Zabbix升级参考
https://blog.51cto.com/moerjinrong/2368709
https://support.zabbix.com/browse/ZBX-16751 Zabbix 3.0 Web页面PHP报错问题