zabbix升级2.2到3.0流程小记

最近处理了下线上的zabbix升级,难倒是不难,就是很多琐碎的工作需要考虑到,本文简单的记录zabbix 2.2升级到3.0的流程,以及遇到的问题。

一:准备工作

注意事项:

1.proxy和server必须保持一致,都为3.0;agent 可以为低版本1.x/2.x https://www.zabbix.com/documentation/3.0/manual/appendix/compatibility

2.升级时先升级server,然后stop;接着一台一台升级proxy,start;proxy都升级完成后,再启动server,这个时间段的数据server启动后,proxy会汇报给server。官方不建议升级server后,就启动server,然后导致旧版本的proxy向server汇报数据,导致不必要的风险

3.php版本,php version >= 5.4.0

4.curl >= 7.20(未证实,我没管curl版本,升级后也没发现问题)

二:升级过程

zabbix server升级:

1.关闭zabbix server,确保没有新数据写入

2.数据库备份,防止升级失败

3.备份配置文件,php代码文件、老的zabbix server相关文件

4.安装新版zabbix server,需要研究下相关编译参数(我使用的参数为./configure --prefix=/usr/local/zabbix-3.0.9 --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2)

5.zabbix server配置文件调整,参照老的配置文件,调整新的配置文件

6.启动zabbix server

启动:/usr/local/zabbix-3.0.9/sbin/zabbix_server -c /usr/local/zabbix-3.0.9/etc/zabbix_server.conf
这个时候留意看tail -f /tmp/zabbix_server.log日志,更改数据库的操作在这一步执行的,一般对数据库的更改成功,就没太大问题了

7.安装zabbix 新版 web

调整配置lnmp环境
cp -aR zabbix-3.0.9/frontends/php/* /data0/www/zabbix-3.0.9/web/
[root@ctc ~]# cat /usr/local/nginx/conf/vhosts/zabbix3.conf
#zabbix3.0.9

server {
    listen       80;
    server_name  zabbix3.com;
    access_log   /tmp/a.log;
    error_log   /tmp/b.log;
    #access_log   /dev/null;

    location / {
    root /data0/www/zabbix-3.0.9/web/;
    index  index.html index.htm index.php;
    }

    location ~ \.php$ {
    root /data0/www/zabbix-3.0.9/web/;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_index  index.php;
    include        fastcgi_params;
    }
}

升级的时候zabbix会自动更新数据库,确保对zabbix数据库有create、drop、alert权限

proxy升级(恩,我这里实际上是不管旧的proxy,重新安装了一个新的proxy):

1.关闭proxy服务

2.备份配置文件,备份zabbix proxy的配置文件跟源文件

3.编译安装新版本的zabbix proxy,我这里使用的参数为(./configure --prefix=/usr/local/zabbix_proxy_v3.0.9 --enable-proxy --enable-agent --with-mysql )

4.修改新的zabbix proxy配置文件,zabbix 3.0的配置文件与2.4的配置文件略有不同,新增了一些参数,按照老的做相应调整生成新的配置文件

5.重新建立zabbix proxy 需要的数据库

create database zabbix_proxy3 default charset utf8;
grant all privileges on zabbix_proxy3.* to zabbix_proxy3@'localhost' identified by 'zabbix_proxy3';
grant all privileges on zabbix_proxy3.* to zabbix_proxy3@'127.0.0.1' identified by 'zabbix_proxy3';
flush privileges;
use zabbix_proxy3;
source /data0/peiqiang/zabbix-3.0.9/database/mysql/schema.sql;

6.启动zabbix proxy

启动zabbix proxy服务,查看日志是否有报错
/usr/local/zabbix-proxy-3.0.9/sbin/zabbix_proxy -c /usr/local/zabbix-proxy-3.0.9/etc/zabbix_proxy.conf

agent 升级:

zabbix server 3.0任然兼容老版本agent,不强制升级,暂时也未打算升级

三:升级中遇到的问题

1.数据库报错Cannot add or update a child row: a foreign key constraint fails,参见https://zabbix.com/forum/showthread.php?p=188794

[Z3005] query failed: [1452] Cannot add or update a child row: a foreign key constraint fails (`zabbix`.`trigger_discovery`, CONSTRAINT `c_trigger_discovery_1` FOREIGN KEY (`triggerid`) REFERENCES `triggers` (`triggerid`) ON DELETE CASCADE) [insert into trigger_discovery (select triggerid,parent_triggerid from trigger_discovery_tmp)]

删除trigger_discovery表的外键约束
alter table trigger_discovery drop foreign key c_trigger_discovery_1;
alter table trigger_discovery drop foreign key c_trigger_discovery_2;

[Z3005] query failed: [1452] Cannot add or update a child row: a foreign key constraint fails (`zabbix`.`graph_discovery`, CONSTRAINT `c_graph_discovery_1` FOREIGN KEY (`graphid`) REFERENCES `graphs` (`graphid`) ON DELETE CASCADE) [insert into graph_discovery (select graphid,parent_graphid from graph_discovery_tmp)]

删除graph_discovery表的外键约束
alter table graph_discovery drop foreign key c_graph_discovery_1;
alter table graph_discovery drop foreign key c_graph_discovery_2;

先关闭外键检查,加完索引后再开(http://stackoverflow.com/questions/5005388/cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails):
SET FOREIGN_KEY_CHECKS=0;

升级完后重新添加外键约束
ALTER TABLE `trigger_discovery` ADD CONSTRAINT `c_trigger_discovery_1` FOREIGN KEY (`triggerid`) REFERENCES `triggers` (`triggerid`) ON DELETE CASCADE;
ALTER TABLE `trigger_discovery` ADD CONSTRAINT `c_trigger_discovery_2` FOREIGN KEY (`parent_triggerid`) REFERENCES `triggers` (`triggerid`);

ALTER TABLE `graph_discovery` ADD CONSTRAINT `c_graph_discovery_1` FOREIGN KEY (`graphid`) REFERENCES `graphs` (`graphid`) ON DELETE CASCADE;
ALTER TABLE `graph_discovery` ADD CONSTRAINT `c_graph_discovery_2` FOREIGN KEY (`parent_graphid`) REFERENCES `graphs` (`graphid`);

SET FOREIGN_KEY_CHECKS=1;

2.升级后图形中文乱码

Zabbix3.0 图像中文显示乱码之解决方案:<http://gaowenlong.blog.51cto.com/451336/1846810>
zabbix图形显示中文乱码:<http://coolnull.com/3395.html>

四:升级后的工作

1.如果需要打成rpm包,可以使用fpm来处理

打rpm包:
fpm -s dir -t rpm -n new_zabbix_proxy -v 3.0.9 -f /usr/local/zabbix_proxy_v3.0.9/

[root@mysql peiqiang]# fpm -s dir -t rpm -n new_zabbix_proxy -v 3.0.9 -f /usr/local/zabbix_proxy_v3.0.9/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created package {:path=>"new_zabbix_proxy-3.0.9-1.x86_64.rpm”}

参考资料:

1.history/trends有分区表是否影响:https://www.zabbix.com/forum/showthread.php?t=52464

2.Upgrade Zabbix 3.0 LTS from 2.4 (Network Monitoring Tool) on Linux:http://www.2daygeek.com/zabbix-upgrade-from-2-4-x-to-3-0-network-monitoring-tool-on-centos-rhel-debian-mint-ubuntu/#

3.What’s new in Zabbix 3.0.0:https://www.zabbix.com/documentation/3.0/manual/introduction/whatsnew300

4.Upgrade procedure using sources:https://www.zabbix.com/documentation/3.0/manual/installation/upgrade

5.Upgrade notes for 3.0.0:https://www.zabbix.com/documentation/3.0/manual/installation/upgrade_notes_300

6.Installation from sources:https://www.zabbix.com/documentation/3.0/manual/installation/install

7.Zabbix-Update:https://github.com/OneOaaS/Zabbix-Update

8.zabbix2.2升级3.0:http://www.51centos.com/?p=194

9.zabbix 2.4升级到3.0:http://www.loxia.cc/2016/06/08/zabbix_2.4升级到3.0/

10.zabbix从2.2.3升级到最新稳定版3.2.1:http://sfzhang88.blog.51cto.com/4995876/1877197

11.Zabbix2.4 升级到3.0:http://mengsir.blog.51cto.com/2992083/1856014

12.zabbix3.0安装部署文档:http://www.cnblogs.com/mrwang1101/p/5513158.html

13.zabbix 3.0.2 zabbix-proxy安装:http://xiao987334176.blog.51cto.com/2202382/1770428

14.Zabbix 配置 Proxy 代理监控:http://jaminzhang.github.io/monitoring/Zabbix-Proxy-Config/

15.解答zabbix在configure时候遇到的问题(CentOS):http://os.51cto.com/art/201104/252989.htm

16.构建 CentOS RPM 包:http://jaminzhang.github.io/linux/build-CentOS-RPM-package/

17.自动化部署必备技能—定制化RPM包:http://www.zyops.com/autodeploy-rpm

18.fpm - packaging made simple:https://fpm.readthedocs.io/en/latest/installing.html#installing-fpm

19.MYSQL添加约束,删除约束添加列,修改列,删除列:http://www.2cto.com/database/201305/211365.html