温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Zabbix 数据清理

发布时间:2020-07-15 17:54:36 来源:网络 阅读:386 作者:Innocence_caosm 栏目:系统运维

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;
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI