Zabbix的history相关数据表数据太大,执行表分区操作过程

一、查询zabbix数据库大小

mysql> 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             | 8326.06 mb | 3031.85mb  |
| jumpserver         | 26.57 mb   | 8.21mb     |
| mysql              | 2.49 mb    | 0.21mb     |
| information_schema | 0.15 mb    | 0.00mb     |
| sys                | 0.01 mb    | 0.00mb     |
| performance_schema | 0.00 mb    | 0.00mb     |
+--------------------+------------+------------+
6 rows in set (0.40 sec)

发现Zabbix数据占用了8G空间

二、查询Zabbix数据库里所有表大小

mysql> 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;
+----------------------------+---------------+------------+
| table_name                 | total_mb      | table_rows |
+----------------------------+---------------+------------+
| history_uint               | 5487.29687500 |   56075683 |
| history                    | 4843.39062500 |   51787332 |
| trends_uint                |  526.92187500 |    7440029 |
| history_str                |  251.39062500 |    2393973 |
| trends                     |  215.87500000 |    2978883 |
| items                      |    6.21875000 |      10033 |
| events                     |    4.93750000 |       7922 |
| alerts                     |    4.67187500 |       5030 |
| items_applications         |    2.35937500 |      11510 |
| triggers                   |    1.89062500 |       4359 |
| auditlog                   |    1.85937500 |       6803 |
| images                     |    1.53125000 |        138 |
| functions                  |    0.67187500 |       4746 |
| item_discovery             |    0.57812500 |       3921 |
| graphs_items               |    0.51562500 |       3773 |
| graphs                     |    0.50000000 |       1561 |
| auditlog_details           |    0.42187500 |       2620 |
| event_recovery             |    0.32812500 |       2936 |
| applications               |    0.29687500 |       2345 |
| item_preproc               |    0.29687500 |       3668 |
| application_template       |    0.28125000 |       1989 |
| sessions                   |    0.23437500 |       1064 |
| hosts                      |    0.17187500 |        167 |
| profiles                   |    0.15625000 |        564 |
| sysmaps_elements           |    0.15625000 |         95 |
| mappings                   |    0.12500000 |        820 |
| widget_field               |    0.10937500 |        170 |
| graph_discovery            |    0.10937500 |        887 |
| problem                    |    0.09375000 |        104 |
| item_condition             |    0.07812500 |        446 |
| sysmaps                    |    0.07812500 |         13 |
| trigger_depends            |    0.07812500 |        401 |
| httptest                   |    0.07812500 |         41 |
| event_suppress             |    0.06250000 |          0 |
| escalations                |    0.06250000 |          8 |
| sysmaps_links              |    0.06250000 |          0 |
| scripts                    |    0.06250000 |          3 |
| trigger_discovery          |    0.06250000 |        648 |
| hostmacro                  |    0.06250000 |        297 |
| group_prototype            |    0.06250000 |          7 |
| acknowledges               |    0.06250000 |        207 |
| slides                     |    0.04687500 |          0 |
| rights                     |    0.04687500 |          4 |
| maintenances_groups        |    0.04687500 |          0 |
| host_discovery             |    0.04687500 |          2 |
| httpstepitem               |    0.04687500 |        123 |
| item_application_prototype |    0.04687500 |         23 |
| autoreg_host               |    0.04687500 |          0 |
| task                       |    0.04687500 |          0 |
| maintenances               |    0.04687500 |          0 |
| dservices                  |    0.04687500 |         30 |
| sysmap_element_trigger     |    0.04687500 |          0 |
| tag_filter                 |    0.04687500 |          0 |
| drules                     |    0.04687500 |          8 |
| slideshows                 |    0.04687500 |          0 |
| users_groups               |    0.04687500 |          5 |
| services_links             |    0.04687500 |          0 |
| opcommand_hst              |    0.04687500 |          0 |
| optemplate                 |    0.04687500 |          0 |
| interface                  |    0.04687500 |         82 |
| slideshow_usrgrp           |    0.04687500 |          0 |
| opcommand_grp              |    0.04687500 |          0 |
| opmessage_usr              |    0.04687500 |         22 |
| sysmaps_link_triggers      |    0.04687500 |          0 |
| service_alarms             |    0.04687500 |          0 |
| opmessage_grp              |    0.04687500 |          4 |
| hosts_templates            |    0.04687500 |        263 |
| icon_mapping               |    0.04687500 |          0 |
| application_prototype      |    0.04687500 |         23 |
| dashboard_usrgrp           |    0.04687500 |          0 |
| media                      |    0.04687500 |          9 |
| hosts_groups               |    0.04687500 |        211 |
| icon_map                   |    0.04687500 |          0 |
| application_discovery      |    0.04687500 |          8 |
| sysmap_usrgrp              |    0.04687500 |          0 |
| dashboard_user             |    0.04687500 |          0 |
| opgroup                    |    0.04687500 |          0 |
| httptestitem               |    0.04687500 |        123 |
| sysmap_user                |    0.04687500 |          0 |
| screens                    |    0.04687500 |         12 |
| actions                    |    0.04687500 |         16 |
| screen_usrgrp              |    0.04687500 |          0 |
| maintenances_windows       |    0.04687500 |          0 |
| correlation                |    0.04687500 |          0 |
| slideshow_user             |    0.04687500 |          0 |
| config                     |    0.04687500 |          0 |
| screen_user                |    0.04687500 |          0 |
| maintenances_hosts         |    0.04687500 |          0 |
| group_discovery            |    0.03125000 |          0 |
| conditions                 |    0.03125000 |         30 |
| sysmap_element_url         |    0.03125000 |          0 |
| problem_tag                |    0.03125000 |          0 |
| regexps                    |    0.03125000 |          5 |
| httpstep_field             |    0.03125000 |         26 |
| interface_discovery        |    0.03125000 |          0 |
| services_times             |    0.03125000 |          0 |
| maintenance_tag            |    0.03125000 |          0 |
| history_text               |    0.03125000 |         22 |
| graph_theme                |    0.03125000 |          4 |
| httpstep                   |    0.03125000 |         41 |
| dhosts                     |    0.03125000 |         31 |
| widget                     |    0.03125000 |         23 |
| users                      |    0.03125000 |          3 |
| services                   |    0.03125000 |          0 |
| hstgrp                     |    0.03125000 |         27 |
| history_log                |    0.03125000 |          0 |
| dchecks                    |    0.03125000 |          8 |
| valuemaps                  |    0.03125000 |         75 |
| opcommand                  |    0.03125000 |          0 |
| usrgrp                     |    0.03125000 |          8 |
| media_type                 |    0.03125000 |         11 |
| opmessage                  |    0.03125000 |         30 |
| globalmacro                |    0.03125000 |          0 |
| trigger_tag                |    0.03125000 |          0 |
| screens_items              |    0.03125000 |         51 |
| proxy_history              |    0.03125000 |          0 |
| corr_condition_group       |    0.03125000 |          0 |
| expressions                |    0.03125000 |         10 |
| dashboard                  |    0.03125000 |          3 |
| proxy_dhistory             |    0.03125000 |          0 |
| corr_condition             |    0.03125000 |          0 |
| operations                 |    0.03125000 |         32 |
| httptest_field             |    0.03125000 |          0 |
| sysmap_url                 |    0.03125000 |          0 |
| proxy_autoreg_host         |    0.03125000 |          0 |
| sysmap_shape               |    0.03125000 |          0 |
| opconditions               |    0.03125000 |          0 |
| event_tag                  |    0.03125000 |          0 |
| corr_operation             |    0.03125000 |          0 |
| timeperiods                |    0.01562500 |          0 |
| corr_condition_tagvalue    |    0.01562500 |          0 |
| task_remote_command_result |    0.01562500 |          0 |
| corr_condition_tagpair     |    0.01562500 |          0 |
| task_remote_command        |    0.01562500 |          0 |
| corr_condition_tag         |    0.01562500 |          0 |
| task_close_problem         |    0.01562500 |          0 |
| task_check_now             |    0.01562500 |          0 |
| housekeeper                |    0.01562500 |          0 |
| ids                        |    0.01562500 |         52 |
| globalvars                 |    0.01562500 |          0 |
| dbversion                  |    0.01562500 |          0 |
| task_acknowledge           |    0.01562500 |          0 |
| opinventory                |    0.01562500 |          0 |
| host_inventory             |    0.01562500 |         20 |
+----------------------------+---------------+------------+
144 rows in set (0.02 sec)

mysql> 

发现history和trends相关表数据量很大,一个是历史数据,一个是趋势数据

需要对这些表进行分区操作,提高效率

三、下载分区脚本

drwxr-xr-x. 4 root root  4096 12月 26 2018 share
[root@zabbix_server zabbix-4.0.3]# wget https://dl.cactifans.com/zabbix/partitiontables_gt_zbx34.sh
--2019-06-28 11:20:28--  https://dl.cactifans.com/zabbix/partitiontables_gt_zbx34.sh
正在解析主机 dl.cactifans.com... 222.186.135.67
正在连接 dl.cactifans.com|222.186.135.67|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:15458 (15K) [application/octet-stream]
正在保存至: “partitiontables_gt_zbx34.sh.1100%[===========================================================================================>] 15,458      --.-K/s   in 0s      

2019-06-28 11:20:28 (428 MB/s) - 已保存 “partitiontables_gt_zbx34.sh.1” [15458/15458])

[root@zabbix_server zabbix-4.0.3]# 

四、编辑脚本相关参数

脚本默认详情数据保留30天,趋势数据保留12个月,如需修改,请修改以下内容:

daily_history_min=30
monthly_history_min=12
 
脚本默认连接数据库信息,更改成你的:
DBHOST=localhost
DBUSER=zabbix
DBPASS=zabbix
[root@zabbix_server zabbix-4.0.3]# chmod +x partitiontables_gt_zbx34.sh

五、执行分区脚本

猜你喜欢

转载自www.cnblogs.com/sky-cheng/p/11101745.html