zabbix2.4.5遷移到zabbix3.0
參考文檔
http://qicheng0211.blog.51cto.com/3958621/1744603
起因
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`);
就是新建這兩個表,這樣就不需要再重新導入一次數據了。