溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Zabbix 數據清理

發布時間:2020-07-15 17:54:36 來源:網絡 閱讀:450 作者: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

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女