zabbix监控项太多80K+,每天接近3G
查看数据大小
[root@HD-DB01 zabbix]# ls -lSh |head
total 385G
-rw-rw---- 1 mysql mysql 212G May 5 15:57 history_uint.ibd
-rw-rw---- 1 mysql mysql 107G May 5 15:58 history.ibd
-rw-rw---- 1 mysql mysql 30G May 5 15:57 events.ibd
-rw-rw---- 1 mysql mysql 14G May 5 15:56 event_recovery.ibd
-rw-rw---- 1 mysql mysql 11G May 5 15:56 trends.ibd
-rw-rw---- 1 mysql mysql 5.7G May 5 15:57 problem.ibd
-rw-rw---- 1 mysql mysql 5.2G May 5 15:56 trends_uint.ibd
-rw-rw---- 1 mysql mysql 1.7G May 5 15:56 history_text.ibd
-rw-rw---- 1 mysql mysql 280M May 5 15:58 sessions.ibd
创建硬链接删除大文件
创建一个硬链接的好处就是:
硬链接就是增加了对文件的引用,只有对磁盘上文件的引用完全没有了的话,这个文件才能是删除的。
我们对t2.ibd 建立硬链接后,当我们执行drop table t2; 的时候,实际上只是删除了对t2.ibd的一个文件引用,我们t2.ibd_hdlk对物理文件的引用还是存在的,就不会执行OS级别的删除操作,就不会大量的IO操作。这种对线上mysql的影响降到很低。
ln history_uint.ibd history_uint.ibd.bak
TRUNCATE=/usr/bin/truncate
for i in `seq 212 -10 10 `;
do
sleep 2
$TRUNCATE -s ${i}G /opt/mysqldata53306/zabbix/history_uint.ibd.bak
done
rm -rf /opt/mysqldata53306/zabbix/history_uint.ibd.bak;
###
ln history.ibd history.ibd.bak
TRUNCATE=/usr/bin/truncate
for i in `seq 107 -10 10 `;
do
sleep 2
$TRUNCATE -s ${i}G /opt/mysqldata53306/zabbix/history.ibd.bak
done
rm -rf /opt/mysqldata53306/zabbix/history.ibd.bak;
重新创建数据表
CREATE TABLE `history` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` double(16,4) NOT NULL DEFAULT '0.0000',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `history_uint` (
`itemid` bigint(20) unsigned NOT NULL,
`clock` int(11) NOT NULL DEFAULT '0',
`value` bigint(20) unsigned NOT NULL DEFAULT '0',
`ns` int(11) NOT NULL DEFAULT '0',
KEY `history_uint_1` (`itemid`,`clock`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
可选
truncate table history;
truncate table history_uint;
truncate table history_str;
truncate table history_text;