如何快速清理zabbix历史数据表
zabbix监控运行一段时间以后,会留下大量的历史监控数据, history_uint有63G,尝试用delete from history_uint where clock 来删除 ,服务器I/O耗时时间长,最后选择脚本来操作。
# 注意:脚本会把zabbix所有的监控数据清空,操作前注意备份数据库
[root@zabbix ~]# cat clearzabbix_log.sh
#!/bin/bash
User="zabbix"
Passwd="zabbix69"
systemctl stop zabbix-server
systemctl stop zabbix-agent
mysql -u${User} -p${Passwd} -e "
SET foreign_key_checks=0;
use zabbix;
truncate table history;
optimize table history;
truncate table history_uint;
optimize table history_uint;
truncate table history_str;
optimize table history_str;
truncate table history_text;
optimize table history_text;
truncate table history_log;
optimize table history_log;
truncate table trends;
optimize table trends;
truncate table trends_uint;
optimize table trends_uint;
truncate table events;
optimize table events;
truncate table event_recovery;
optimize table event_recovery;
SET foreign_key_checks=1;
"
mysqldump -u${User} -p${Passwd} --quick --single-transaction zabbix|gzip >/data/mysqlbackup/`date +%F_%H%M%S`_zabbix.sql.gz
systemctl start zabbix-server
systemctl start zabbix-agent
----------------------end---------------------
推荐阅读:
1、
2、
3、
5
7
8
9
10