×
新网 > 虚机资讯 > 正文

Zabbix 数据清理

  • 作者:zccc
  • 来源:网络
  • 2020-07-15 18:03:38

系统运维 Zabbix 数据清理 在服务器上操作数据库是挺危险的事情,这里一定要慎重操作,清理数据有两种方法: 1. 更改zabbix 上历史数据、趋

系统运维 Zabbix 数据清理


在服务器上操作数据库是挺危险的事情,这里一定要慎重操作,清理数据有两种方法:

1. 更改zabbix 上历史数据、趋势保存时间
2. 通过对zabbxi mysql 数据库进行操作清理
 这里笔者比较怂,妥妥使用的第二种,保留30d数据,还有就是在操作的时候一定要注意:关闭报警---->报警媒介,今天备份数据的时候造成误报,短信大量发送,一定要记住惨痛经历,不然就要走人啦!

使用表清理数据基本操作语句如下:

Zabbix 数据库查询大小
MariaDB [(none)]> select table_schema, concat(truncate(sum(data_length)/1024/1024,2),\' mb\') as data_size,concat(truncate(sum(index_length)/1024/1024,2),\'mb\') as index_size from information_schema.tables group by table_schema order by data_size desc;
+--------------------+-------------+------------+
| table_schema       | data_size   | index_size |
+--------------------+-------------+------------+
| zabbix             | 63447.98 mb | 74299.04mb |
| information_schema | 0.08 mb     | 0.08mb     |
+--------------------+-------------+——————+
数据大小: 61G
索引大小:  37G

查询Zabbix数据库里所有表大小
MariaDB [(none)]> select table_name, (data_length+index_length)/1024/1024 as total_mb,table_rows from information_schema.tables where table_schema=\'zabbix\' order by total_mb desc;

执行sql查看指定日期之前的数据大小
SELECT table_schema as `Database`,table_name AS `Table`,round(((data_length + index_length)), 2) `Size in MB`FROM information_schema.TABLES where CREATE_TIME < \'2019-09-01 00:00:00\' and table_name=\'history.ibd\';

查看当前目录大与50M 的文件
# find ./ -size +50M  | xargs ls -Slh
删除2019年11月22日11点以前的数据
[root@128lastsummer ~]# date +%s -d Nov 22, 2019 11:00:00
1574391600
MariaDB [zabbix]> delete from history where clock < 1574391600;
MariaDB [zabbix]> delete from history_uint where clock < 1574391600;
MariaDB [zabbix]> optimize table history;
MariaDB [zabbix]> optimize table history_unit;

备份与恢复zabbix history 的表
[root@128lastsummer ~]# Mysqldump -uzabbix -p zabbix history > /tmp/zabbix_history.sql
MariaDB [zabbix]> source /tmp/zabbix_history.sql;

查询数据库每个表有多少条数据
select table_name,table_rows from information_schema.tables where TABLE_SCHEMA = \'数据库的名称\' order by table_rows desc;

新网虚拟主机

  • 相关专题

免责声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,也不承认相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,请发送邮件至:operations@xinnet.com进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

免费咨询获取折扣

Loading