zabbix清理历史数据
zabbix清理历史数据
·
#停止zabbix-server服务是停止向数据库写入数据,因为在数据清理优化过程中,mysql会锁表。
systemctl stop zabbix-server
1. 时间戳转换
#取60天之前的时间戳
$ date -d $(date -d "-60 day" +%Y%m%d) +%s
1592150400
2. 数据清理
$mysql -uzabbix -p
use zabbix;
delete from history_uint where clock < 1592150400;
alter table history_uint ENGINE = 'InnoDB';
delete from history where clock < 1592150400;
alter table history ENGINE = 'InnoDB';
#注意:在alter table用来优化并释放表空间。
#但要注意的是,它在运行过程中,MySQL会锁定表,所以应该考虑使用一些运维手段避免现网的服务受到影响。
3. 重启zabbix和nginx服务
systemc restart mysqld
systemctl restart zabbix-server
systemctl restart nginx
错误处理
-
Error 1206 The total number of locks exceeds the lock table size.
-
解决方案:
show variables like "%_buffer%";
vim /etc/my.cnf
#默认8MB,改为2GB(太小了还是会报错)
[mysqld]
innodb_buffer_pool_size=2048MB
清空(删除)所有的历史告警
一、登陆mysql数据库
[root@whzabbix ~]# mysql -u root -p
Enter password:
1
2
二、进入需要使用的数据库
mysql> use zabbix;
1
三、修改“外键约束”
mysql> SET foreign_key_checks = 0;
1
四、清空“events”表
mysql> truncate table events;
1
五、清空“trigger”表
mysql> truncate table problem;
1
六、改回“外键约束”
mysql> SET foreign_key_checks = 1;
1
七、完成
完成后看首页,所有告警全部消失

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)