本文适用于在CentOS6下zabbix2.2及以上版本升级到zabbix3.0。

    zabbix3.0的环境要求:

Software Version Comments
MySQL 5.0.3 or later
Apache 1.3.12 or later
PHP 5.4.0 or later PHP v7 is not supported yet.
libcurl  For SMTP authentication, version 7.20.0 or higher is required.

    由于CentOS6默认的php和libcurl版本均不满足要求,所以需要使用第三方yum源升级。

升级前的版本:

  • PHP 5.3.3

  • curl 7.19.7

  • Zabbix server v2.2.10

  • Zabbix Agent (daemon) v2.2.10

升级后的版本:

  • PHP 5.6.18

  • curl 7.47.1

  • zabbix_server (Zabbix) 3.0.0

  • zabbix_agentd (daemon) (Zabbix) 3.0.0

0.升级前的准备

1)安装yum多线程下载插件axelget,提升下载速度

    下载地址:http://down.51cto.com/data/2183091

1
2
3
rpm -ivh http: //pkgs .repoforge.org /axel/axel-2 .4-1.el6.rf.x86_64.rpm
cp  axelget.conf  /etc/yum/pluginconf .d/
cp  axelget.py  /usr/lib/yum-plugins/

    网络质量对yum的影响较大,如果yum执行过程中网络超时,可以多尝试几次。

2)停止服务

1
2
3
4
5
6
7
8
# 停止zabbix server和agent 
service zabbix-server stop
service zabbix-agent stop
# 停止Nginx和php-fpm(LNMP)
service nginx stop
service php-fpm stop
# 停止Apache(LAMP)
service httpd stop

3)备份zabbix数据库

1
2
3
4
5
6
7
8
9
# 数据库zabbix,用户名zabbix
mysqldump --opt -R -uzabbix -p zabbix \
--ignore-table=zabbix. history  \
--ignore-table=zabbix.history_log \
--ignore-table=zabbix.history_str \
--ignore-table=zabbix.history_text \
--ignore-table=zabbix.history_uint \
--ignore-table=zabbix.trends \
--ignore-table=zabbix.trends_uint |  gzip  > zabbix_` date  + '%Y%m%d%H%M%S' `.sql.gz

    上述备份命令忽略了history相关表和trends相关表,备份文件使用gzip压缩。 

wKiom1bNIcrg7PAFAABFpicr1qs094.png

1.升级php到5.6

1
2
3
4
5
6
7
# 安装epel yum源
rpm -Uvh https: //dl .fedoraproject.org /pub/epel/epel-release-latest-6 .noarch.rpm
# 安装php5.6 yum源
rpm -Uvh https: //mirror .webtatic.com /yum/el6/latest .rpm
# 升级php版本到5.6
yum  install  yum-plugin-replace -y
yum replace php-common --replace-with=php56w-common -y

wKiom1bNI5CSx6iHAACf3Iscc5A950.png

1
2
3
# 验证php版本
php - v
php-fpm - v

wKioL1bNJCSQ2Ox2AAAqTwpUDMA407.png

    zabbix官方文档要求:如果php版本>=5.6.0要设置php.ini里always_populate_raw_post_data = -1

2.升级libcurl到7.47

1
2
3
4
5
6
# 安装新版libcurl的yum源
rpm -ivh http: //mirror .city-fan.org /ftp/contrib/yum-repo/city-fan .org-release-1-13.rhel6.noarch.rpm
# 升级libcurl到7.47
yum upgrade libcurl
# 升级完成后可以卸载此yum源
rpm -e city-fan.org-release

wKiom1bNJnXTx9ZTAABPKPL3VQY898.png

1
2
# 验证curl版本
curl -V

wKioL1bNJPOSxY-SAAArKGFXcMM192.png

3.升级Zabbix server到3.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 升级centos6的zabbix官方yum源(官方yum源没有提供CentOS6版本的zabbix3.0 server)
rpm -Uvh  http: //repo .zabbix.com /zabbix/3 .0 /rhel/6/x86_64/zabbix-release-3 .0-1.el6.noarch.rpm
# 下载itnihao打包好的CentOS6版本的zabbix3.0 rpm包,感谢itnihao奉献
mkdir  /data
cd  /data
yum  install  git createrepo -y
git clone https: //github .com /zabbixcn/zabbix3 .0-rpm.git
# 创建zabbix3.0本地yum源
createrepo  /data/zabbix3 .0-rpm /RPMS
cat  /etc/yum .repos.d /zabbix3 .0.repo <<  'EOF'
[zabbix3.0]
name=zabbix3.0 itnihao
baseurl= file : ///data/zabbix3 .0-rpm /RPMS
enabled=0
gpgcheck=0
EOF
# 重建yum缓存
yum clean all
yum makecache
# yum升级zabbix3.0相关服务(注意:要禁止epel源)
yum --disablerepo=epel --enablerepo=zabbix3.0 upgrade zabbix-server-mysql zabbix-agent zabbix-get zabbix-sender

wKioL1bNKRODJkpOAABQO1TJ7tk702.png

1
2
3
# 升级完成后检查zabbix server和agent版本
zabbix_server_mysql -V
zabbix_agentd -V

wKioL1bNKWGCH8PEAABJiwdAkGU714.png

1
2
3
4
5
6
# 启动zabbix-server和zabbix-agent
service zabbix-server start 
service zabbix-agent start
# 加入开机启动
chkconfig zabbix-server on
chkconfig zabbix-agent on

    zabbix2.2及以上版本升级到zabbix3.0不需要额外执行数据库升级脚本。3.0版zabbix-server启动后会自动升级数据库,到日志里查看升级进度:

1
2
# zabbix-server启动后,观察zabbix-server的日志
tailf -100  /var/log/zabbix/zabbix_server .log

4.升级zabbix web

    下面分别讲下nginx和Apache的web升级:

1)Nginx

1
2
3
4
5
6
7
8
9
10
11
12
# 下载zabbix 3.0源码包
wget http: //jaist .dl.sourceforge.net /project/zabbix/ZABBIX %20Latest%20Stable /3 .0.0 /zabbix-3 .0.0. tar .gz -O zabbix-3.0.0. tar .gz
# 解压后提取php源文件到zabbix web目录/data/www/zabbix3.0
tar  xvzf zabbix-3.0.0. tar .gz 
mkdir  -p  /data/www/zabbix3 .0
\ cp  -r zabbix-3.0.0 /frontends/php/ /data/www/zabbix3 .0
# 设置web目录的权限(我的nginx的启动用户是nginx)
chown  -R nginx.  /data/www
chmod  755  /data
# 修改php-fpm的用户也是nginx
sed  -i  '/^user =/c\user = nginx'  /etc/php-fpm .d /www .conf
sed  -i  '/^group = =/c\group = nginx'  /etc/php-fpm .d /www .conf

    更新Nginx配置文件里的zabbix web根目录:

wKiom1bNOOaB_IxPAAA85kUyLz8956.png

1
2
3
4
5
6
7
# 启动php-fpm
service php-fpm start
# 启动nginx
nginx -t && service nginx start
# 加入开机启动
chkconfig php-fpm on
chkconfig nginx on

    最后访问zabbix web进行配置即可,配置流程简单就不细说了。 

wKioL1bNOgXD6zUFAABfHh4zH4g140.png

    点击下一步“Next step”没有反应的解决方法如下:

1
2
# 如果你的nginx和php-fpm启动用户为nginx,则运行下面的命令修改php session文件目录的权限:
setfacl -R -m u:nginx:rwx  /var/lib/php

2)Apache

1
2
3
4
5
6
7
# yum更新zabbix web(按照下面的命令升级)
yum --disablerepo=epel --enablerepo=zabbix3.0  install  httpd php56w zabbix-web-mysql-3.0.0-1.el6.noarch zabbix-web-3.0.0-1.el6.noarch
sed  -i  "s@# php_value date.timezone Europe/Riga@php_value date.timezone Asia/Shanghai@g"  /etc/httpd/conf .d /zabbix .conf
# 启动Apache
/etc/init .d /httpd  restart
# 加入开机启动
chkconfig httpd on

    至此全部升级结束了。