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;

更多关于云服务器域名注册虚拟主机的问题,请访问西部数码官网:www.west.cn

赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-62778877-8306;邮箱:fanjiao@west.cn。本站原创内容未经允许不得转载,或转载时需注明出处:西部数码知识库 » Zabbix 数据清理

登录

找回密码

注册