zabbix2.4.5迁移到zabbix3.0

参考文档


起因

zabbix 2.4.5数据库mysql突然死掉了,查找mysql数据库日志发现保存数据磁盘读写错误,原来那是台r410的老机,后来索性换了1台R610的稍微好的机子,现在机器都换了打算zabbix版本也


一块儿换掉,开启zabbix3.0模式,下面是主要步骤,数据库这块儿是这次才发现有个简单方法的。


0,首先要有原来数据库备份

硬件服务器也升级了 ,只有最近一份数据库全部备份,发现数据太大,如果全部导入费时,查找各种资料发现没有导入时忽略某些表的方法,后来想到手动对sql数据表进行过滤。


grep -v  'INSERT INTO `history_uint` VALUES' zabbix.sql >zabbix.nohistory.sql
grep -v  'INSERT INTO `history` VALUES' zabbix.nohistory.sql >zabbix.nohistory0.sql

如果想导入历史趋势,后面两步可以不需要,我的需要保留
grep -v  'INSERT INTO `trends_uint` VALUES' zabbix.nohistory0.sql > zabbix.nohistory1.sql
grep -v  'INSERT INTO `trends` VALUES' zabbix.nohistory1.sql > zabbix.nohistory2.sql


后来我修改了备份方法,由原来的全部备份到备份时忽略历史数据。
mysqldump -uroot -p'pasword' zabbix  --ignore-table=zabbix.history_uint --ignore-table=zabbix.history  >zabbix.nohistory.sql


1,LAMP或者LNMP环境

网上方法很多,就是一点,mysql使用innodb引擎 ,版本5.6或以上,php版本5.6或以上,apache或者nginx根据个人爱好。我的都是用rpm包,数据用的mariadb。


mariadb源
cat /etc/yum.repos.d/mariadb.repo 
# http://mariadb.org/mariadb/repositories/  
[mariadb]  
name = MariaDB  
baseurl = http://yum.mariadb.org/5.5/centos6-amd64  
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB  
gpgcheck=1

安装

yum -y install MariaDB-client MariaDB-server MariaDB-devel


2,zabbix3.0源码包还是rpm也是根据个人爱好。

# 升级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 install zabbix-server-mysql zabbix-agent zabbix-get zabbix-sender zabbix-web zabbix-web-mysql zabbix-release

3,导入数据

mysql -u root password 'password'  < zabbix.nohistory0.sql


4,启动zabbix-server

service zabbix-server start

此时会自动更新zabbix数据库


5,设置web端

这里主要是有个字体,需要注意下,默认打开图形乱码,下载简体字。上传,修改代码。

vim /usr/share/zabbix/include/defines.inc.php 

:%s/graphfont/DejaVuSans/g   


另外注意下,3.0版本的zabbix-server配置文件和2.4.5的有些不一样,我这里参考3.0的默认修改,结果如下:

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=password
StartPollers=160
StartIPMIPollers=1
StartPollersUnreachable=80
StartTrappers=20
StartPingers=100
StartDiscoverers=120
StartHTTPPollers=2
StartSNMPTrapper=1
CacheSize=1024M
StartDBSyncers=16
TrendCacheSize=1024M
TrapperTimeout=30
FpingLocation=/usr/sbin/fping
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=10
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000





补充:

后来又升级一台,备份数据库时没有备份history,history_unit这两个数据库,也没先导入架构表,直接导入趋势数据,所有操作完后,查看zabbix-server.log发现数据不能插入历史数据表。后处理如下:

CREATE TABLE `history` (
        `itemid`                 bigint unsigned                           NOT NULL,
        `clock`                  integer         DEFAULT '0'               NOT NULL,
        `value`                  double(16,4)    DEFAULT '0.0000'          NOT NULL,
        `ns`                     integer         DEFAULT '0'               NOT NULL
) ENGINE=InnoDB;
CREATE INDEX `history_1` ON `history` (`itemid`,`clock`);
CREATE TABLE `history_uint` (
        `itemid`                 bigint unsigned                           NOT NULL,
        `clock`                  integer         DEFAULT '0'               NOT NULL,
        `value`                  bigint unsigned DEFAULT '0'               NOT NULL,
        `ns`                     integer         DEFAULT '0'               NOT NULL
) ENGINE=InnoDB;
CREATE INDEX `history_uint_1` ON `history_uint` (`itemid`,`clock`);


就是新建这两个表,这样就不需要再重新导入一次数据了。


转载于:https://blog.51cto.com/jerrymin/1757890