为zabbix历史记录表瘦身

        随着线上zabbix系统运行的时间越长,zabbix的数据库也在逐渐增大,这时我们会发现,越到后面,备份数据库时间就花的越长.
        特别是上千台机器的情况,然而在大数据量的备份过程中,经常会出现检测数据延迟,导致检测出错,产生不必要的误报.为了
        不产生误报,只能停止 zabbix_server服务,进行备份.如果恰巧在这段时间,线上的应用服务器出现了故障,将不能及时发现
        与处理故障.如何才能实现快速的备份 zabbix数据库,而且可以在不停止服务的情况下完成备份呢?
        其实zabbix数据库里面最大的表,就是历史记录的表了, 这些表中的数据,全都存储着之前所检测到的历史数据.所以,现在
        就很清楚了,你可以选择清空这些表,这样做的话,所有客户端的历史检测数据,都会被清空, 空间自然就小了,如果你不想失
        去这些数据的话,那么也可以在备份数据库的时候,选择不备份这几张表.或是只备份这几张表的表结构,里面的数据不做备份.
        选择哪一种,可以根据实际情况而定.
        下面的操作是清空历史数据的表,主要就是以下这几张表,清空后,备份一下数据库,只要不到三分钟的时间,就可以搞定了.....
    
    use zabbix;
    truncate table history;
    optimize table history;
    truncate table history_str;
    optimize table history_str;
    truncate table history_uint;
    optimize table history_uint;
    truncate table trends;
    optimize table trends;
    truncate table trends_uint;
    optimize table trends_uint;
    truncate table events;
    optimize table events;



举例如下:
mysql> use zabbix;
Database changed
mysql> truncate table history;
Query OK, 60853 rows affected (0.09 sec)

mysql> optimize  table history;
+----------------+----------+----------+----------+
| Table          | Op       | Msg_type | Msg_text |
+----------------+----------+----------+----------+
| zabbix.history | optimize | status   | OK       |
+----------------+----------+----------+----------+
1 row in set (0.23 sec)

mysql> truncate table history_str;
Query OK, 1 row affected (0.04 sec)

mysql> optimize table history_str;
+--------------------+----------+----------+----------+
| Table              | Op       | Msg_type | Msg_text |
+--------------------+----------+----------+----------+
| zabbix.history_str | optimize | status   | OK       |
+--------------------+----------+----------+----------+
1 row in set (0.05 sec)

mysql> truncate table history_uint;
Query OK, 2077339 rows affected (0.05 sec)

mysql> optimize table history_uint;
+---------------------+----------+----------+----------+
| Table               | Op       | Msg_type | Msg_text |
+---------------------+----------+----------+----------+
| zabbix.history_uint | optimize | status   | OK       |
+---------------------+----------+----------+----------+
1 row in set (0.08 sec)

mysql> truncate table trends;
Query OK, 90671 rows affected (0.45 sec)

mysql> optimize table trends;
+---------------+----------+----------+----------+
| Table         | Op       | Msg_type | Msg_text |
+---------------+----------+----------+----------+
| zabbix.trends | optimize | status   | OK       |
+---------------+----------+----------+----------+
1 row in set (0.03 sec)

mysql> truncate table trends_uint;
Query OK, 2945582 rows affected (0.05 sec)

mysql> optimize table trends_uint;
+--------------------+----------+----------+----------+
| Table              | Op       | Msg_type | Msg_text |
+--------------------+----------+----------+----------+
| zabbix.trends_uint | optimize | status   | OK       |
+--------------------+----------+----------+----------+

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值