zabbix数据库分表

Zabbix 官网说明:https://www.zabbix.org/wiki/Docs/howto/mysql_partition
我的环境:

[11:26:34 root@localhost ~]#mysql -V
mysql  Ver 15.1 Distrib 10.3.27-MariaDB, for Linux (x86_64) using readline 5.1
[11:26:37 root@localhost ~]#zabbix_server -V
zabbix_server (Zabbix) 5.2.5
Revision 1afd0ded11 22 February 2021, compilation time: Feb 23 2021 11:39:25

Copyright (C) 2021 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later .
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.
[11:26:49 root@localhost ~]#apachectl -v
Server version: Apache/2.4.37 (centos)
Server built:   Nov  4 2020 03:20:37
[11:27:04 root@localhost ~]#php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[11:27:14 root@localhost ~]#cat /etc/redhat-release
CentOS Linux release 8.3.2011

准备知识:
1、针对zabbix数据库表要进行分区分表,如果表数据量大执行分区分表会非常慢,建议先清空history、trends表中的数据(注意:历史记录会全部被清空),再执行分区分表。
2、zabbix 数据库主要针对以下表(zabbix历史记录表和zabbix存储趋势表)进行分区分表:
history,history_uint,history_str,history_test,history_log,trends,trends_uint

history : 存储浮点数数据 比如ping丢包,CPU使用率等 00.00 类似的数据.
history_uint: 整数型数据 ,比如流量数据,状态码等等

趋势数据存储表:
trend: 与history类似,只不过是一个小时取一个点
trend_unit :与history——uint类似,只不过是一个小时取一个点
3、zabbix 数据库在没有使用分区分表功能,默认使用Housekeeping(管家功能)进行删除历史数据和趋势历史记录,如果zabbix数据库使用了分区分表功能需要把Housekeeping(管理功能)关闭。Housekeeping功能监控数据量少可以使用,但监控数据量多每次执行删除会降低MySQL数据库性能,并且还会产生很多空间碎片。(zabbix_server.conf配置文件两个参数进行历史记录数据删除:间隔多久删除一次,默认单位小时HousekeepingFrequency=1,一次删除多少数据,默认单位行MaxHousekeeperDelete=5000)

分表操作:
1、清空zabbix 数据库历史数据
步骤如下:

[11:27:28 root@localhost ~]#vim truncate.sql 

truncate table history;
optimize table history;
truncate table history_str;
optimize table history_str;
truncate table history_log;
optimize table history_log;
truncate table history_text;
optimize table history_text;
truncate table history_uint;
optimize table history_uint;
truncate table trends;
optimize table trends;
truncate table trends_uint;
optimize table trends_uint;

[11:27:28 root@localhost ~]#mysql -uroot -p zabbix
MariaDB [zabbix]>source /root/truncate.sql

2、zabbix 数据库导入存储过程
先编辑一个SQL脚本执行导入四个存储过程,此脚本复制zabbix官网提供的SQL脚本

[11:27:28 root@localhost ~]#vim par.sql
DELIMITER $$
CREATE PROCEDURE `partition_create`(SCHEMANAME varchar(64), TABLENAME varchar(64), PARTITIONNAME varchar(64), CLOCK int)
BEGIN
        /*
           SCHEMANAME = The DB schema in which to make changes
           TABLENAME = The table with partitions to potentially delete
           PARTITIONNAME = The name of the partition to create
        */
        /*
           Verify that the partition does not already exist
        */

        DECLARE RETROWS INT;
        SELECT COUNT(1) INTO RETROWS
        FROM information_schema.partitions
        WHERE table_schema = SCHEMANAME AND table_name = TABLENAME AND partition_description >= CLOCK;

        IF RETROWS = 0 THEN
        /*
           1. Print a message indicating that a partition was created.
           2. Create the SQL to create the partition.
           3. Execute the SQL from #2.
        */
        SELECT CONCAT( "partition_create(", SCHEMANAME, ",", TABLENAME, ",", PARTITIONNAME, ",", CLOCK, ")" ) AS msg;
        SET @sql = CONCAT( 'ALTER TABLE ', SCHEMANAME, '.', TABLENAME, ' ADD PARTITION (PARTITION ', PARTITIONNAME, ' VALUES LESS THAN (', CLOCK, '));' );
        PREPARE STMT FROM @sql;
        EXECUTE STMT;
        DEALLOCATE PREPARE STMT;
        END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE `partition_drop`(SCHEMANAME VARCHAR(64), TABLENAME VARCHAR(64), DELETE_BELOW_PARTITION_DATE BIGINT)
BEGIN
        /*
           SCHEMANAME = The DB schema in which to make changes
           TABLENAME = The table with partitions to potentially delete
           DELETE_BELOW_PARTITION_DATE = Delete any partitions with names that are dates older than this one (yyyy-mm-dd)
        */
        DECLARE done INT DEFAULT FALSE;
        DECLARE drop_part_name VARCHAR(16);

        /*
           Get a list of all the partitions that are older than the date
           in DELETE_BELOW_PARTITION_DATE.  All partitions are prefixed with
           a "p", so use SUBSTRING TO get rid of that character.
        */
        DECLARE myCursor CURSOR FOR
        SELECT partition_name
        FROM information_schema.partitions
        WHERE table_schema = SCHEMANAME AND table_name = TABLENAME AND CAST(SUBSTRING(partition_name FROM 2) AS UNSIGNED) < DELETE_BELOW_PARTITION_DATE;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

        /*
           Create the basics for when we need to drop the partition.  Also, create
           @drop_partitions to hold a comma-delimited list of all partitions that
           should be deleted.
        */
        SET @alter_header = CONCAT("ALTER TABLE ", SCHEMANAME, ".", TABLENAME, " DROP PARTITION ");
        SET @drop_partitions = "";

        /*
           Start looping through all the partitions that are too old.
        */
        OPEN myCursor;
        read_loop: LOOP
        FETCH myCursor INTO drop_part_name;
        IF done THEN
    LEAVE read_loop;
        END IF;
        SET @drop_partitions = IF(@drop_partitions = "", drop_part_name, CONCAT(@drop_partitions, ",", drop_part_name));
        END LOOP;
        IF @drop_partitions != "" THEN
        /*
           1. Build the SQL to drop all the necessary partitions.
           2. Run the SQL to drop the partitions.
           3. Print out the table partitions that were deleted.
        */
        SET @full_sql = CONCAT(@alter_header, @drop_partitions, ";");
        PREPARE STMT FROM @full_sql;
        EXECUTE STMT;
        DEALLOCATE PREPARE STMT;

        SELECT CONCAT(SCHEMANAME, ".", TABLENAME) AS `table`, @drop_partitions AS `partitions_deleted`;
        ELSE
        /*
           No partitions are being deleted, so print out "N/A" (Not applicable) to indicate
           that no changes were made.
        */
        SELECT CONCAT(SCHEMANAME, ".", TABLENAME) AS `table`, "N/A" AS `partitions_deleted`;
        END IF;
END$$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE `partition_maintenance`(SCHEMA_NAME VARCHAR(32), TABLE_NAME VARCHAR(32), KEEP_DATA_DAYS INT, HOURLY_INTERVAL INT, CREATE_NEXT_INTERVALS INT)
BEGIN
        DECLARE OLDER_THAN_PARTITION_DATE VARCHAR(16);
        DECLARE PARTITION_NAME VARCHAR(16);
        DECLARE OLD_PARTITION_NAME VARCHAR(16);
        DECLARE LESS_THAN_TIMESTAMP INT;
        DECLARE CUR_TIME INT;

        CALL partition_verify(SCHEMA_NAME, TABLE_NAME, HOURLY_INTERVAL);
        SET CUR_TIME = UNIX_TIMESTAMP(DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00'));

        SET @__interval = 1;
        create_loop: LOOP
        IF @__interval > CREATE_NEXT_INTERVALS THEN
    LEAVE create_loop;
        END IF;

        SET LESS_THAN_TIMESTAMP = CUR_TIME + (HOURLY_INTERVAL * @__interval * 3600);
        SET PARTITION_NAME = FROM_UNIXTIME(CUR_TIME + HOURLY_INTERVAL * (@__interval - 1) * 3600, 'p%Y%m%d%H00');
        IF(PARTITION_NAME != OLD_PARTITION_NAME) THEN
    CALL partition_create(SCHEMA_NAME, TABLE_NAME, PARTITION_NAME, LESS_THAN_TIMESTAMP);
        END IF;
        SET @__interval=@__interval+1;
        SET OLD_PARTITION_NAME = PARTITION_NAME;
        END LOOP;

        SET OLDER_THAN_PARTITION_DATE=DATE_FORMAT(DATE_SUB(NOW(), INTERVAL KEEP_DATA_DAYS DAY), '%Y%m%d0000');
        CALL partition_drop(SCHEMA_NAME, TABLE_NAME, OLDER_THAN_PARTITION_DATE);

END$$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE `partition_verify`(SCHEMANAME VARCHAR(64), TABLENAME VARCHAR(64), HOURLYINTERVAL INT(11))
BEGIN
        DECLARE PARTITION_NAME VARCHAR(16);
        DECLARE RETROWS INT(11);
        DECLARE FUTURE_TIMESTAMP TIMESTAMP;

        /*
         * Check if any partitions exist for the given SCHEMANAME.TABLENAME.
         */
        SELECT COUNT(1) INTO RETROWS
        FROM information_schema.partitions
        WHERE table_schema = SCHEMANAME AND table_name = TABLENAME AND partition_name IS NULL;

        /*
         * If partitions do not exist, go ahead and partition the table
         */
        IF RETROWS = 1 THEN
        /*
         * Take the current date at 00:00:00 and add HOURLYINTERVAL to it.  This is the timestamp below which we will store values.
         * We begin partitioning based on the beginning of a day.  This is because we don't want to generate a random partition
         * that won't necessarily fall in line with the desired partition naming (ie: if the hour interval is 24 hours, we could
         * end up creating a partition now named "p201403270600" when all other partitions will be like "p201403280000").
         */
        SET FUTURE_TIMESTAMP = TIMESTAMPADD(HOUR, HOURLYINTERVAL, CONCAT(CURDATE(), " ", '00:00:00'));
        SET PARTITION_NAME = DATE_FORMAT(CURDATE(), 'p%Y%m%d%H00');

        -- Create the partitioning query
        SET @__PARTITION_SQL = CONCAT("ALTER TABLE ", SCHEMANAME, ".", TABLENAME, " PARTITION BY RANGE(`clock`)");
        SET @__PARTITION_SQL = CONCAT(@__PARTITION_SQL, "(PARTITION ", PARTITION_NAME, " VALUES LESS THAN (", UNIX_TIMESTAMP(FUTURE_TIMESTAMP), "));");

        -- Run the partitioning query
        PREPARE STMT FROM @__PARTITION_SQL;
        EXECUTE STMT;
        DEALLOCATE PREPARE STMT;
        END IF;
END$$
DELIMITER ;

DELIMITER $$
CREATE PROCEDURE`partition_maintenance_all`(SCHEMA_NAME VARCHAR(32))
BEGIN
               CALL partition_maintenance(SCHEMA_NAME, 'history', 33, 24, 14);
               CALL partition_maintenance(SCHEMA_NAME, 'history_log', 33, 24, 14);
               CALL partition_maintenance(SCHEMA_NAME, 'history_str', 33, 24, 14);
               CALL partition_maintenance(SCHEMA_NAME, 'history_text', 33, 24, 14);
               CALL partition_maintenance(SCHEMA_NAME, 'history_uint', 367, 24, 14);
               CALL partition_maintenance(SCHEMA_NAME, 'trends', 368, 720, 12);
               CALL partition_maintenance(SCHEMA_NAME, 'trends_uint', 368, 168, 12);
END$$

其中需要修改的地方
CALL partition_maintenance(SCHEMA_NAME, 'history', 33, 24, 14);
CALL partition_maintenance(SCHEMA_NAME, 'history_log', 33, 24, 14);
CALL partition_maintenance(SCHEMA_NAME, 'history_str', 33, 24, 14);
CALL partition_maintenance(SCHEMA_NAME, 'history_text', 33, 24, 14);
CALL partition_maintenance(SCHEMA_NAME, 'history_uint', 367, 24, 14);
CALL partition_maintenance(SCHEMA_NAME, 'trends', 368, 720, 12);
CALL partition_maintenance(SCHEMA_NAME, 'trends_uint', 368, 168, 12);

举例:
('history', 33, 24, 14);
history :表名
33:历史数据保留时间 单位天
24:每多长时间分表 单位小时
14:每次运行脚本分多少张表 单位张

#导入存储过程到数据库
[11:27:28 root@localhost ~]#mysql -uzabbix -p zabbix < par.sql
#调用存储过程
[11:27:28 root@localhost ~]#mysql  -uzabbix -pPASSWORD zabbix -e"CALL partition_maintenance_all('zabbix')" &>/var/log/partition.log
#查看是否生成相关数据库表
[12:04:04 root@localhost ~]#ll -ah /var/lib/mysql/zabbix/trend*
-rw-rw---- 1 mysql mysql 2.0K Jul 21 10:48 /var/lib/mysql/zabbix/trends.frm
-rw-rw---- 1 mysql mysql  244 Jul 21 10:48 /var/lib/mysql/zabbix/trends.par
-rw-rw---- 1 mysql mysql 368K Jul 21 12:04 /var/lib/mysql/zabbix/trends#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202108200000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202109190000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202110190000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202111180000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202112180000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202201170000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202202160000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202203180000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202204170000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202205170000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends#P#p202206160000.ibd
-rw-rw---- 1 mysql mysql 2.0K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint.frm
-rw-rw---- 1 mysql mysql  244 Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint.par
-rw-rw---- 1 mysql mysql  15M Jul 21 12:04 /var/lib/mysql/zabbix/trends_uint#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202108040000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202108110000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202108180000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202108250000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202109010000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202109080000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202109150000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202109220000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202109290000.ibd
-rw-rw---- 1 mysql mysql  96K Jul 21 10:48 /var/lib/mysql/zabbix/trends_uint#P#p202110060000.ibd
[12:04:14 root@localhost ~]#ll -ah /var/lib/mysql/zabbix/history*
-rw-rw---- 1 mysql mysql 2.1K Jul 21 10:48 /var/lib/mysql/zabbix/history.frm
-rw-rw---- 1 mysql mysql 2.4K Jul 21 10:48 /var/lib/mysql/zabbix/history_log.frm
-rw-rw---- 1 mysql mysql  284 Jul 21 10:48 /var/lib/mysql/zabbix/history_log.par
-rw-rw---- 1 mysql mysql 352K Jul 21 12:04 /var/lib/mysql/zabbix/history_log#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107220000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107230000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107240000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107250000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107260000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107270000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107290000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107300000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202107310000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202108010000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202108020000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_log#P#p202108030000.ibd
-rw-rw---- 1 mysql mysql  284 Jul 21 10:48 /var/lib/mysql/zabbix/history.par
-rw-rw---- 1 mysql mysql  18M Jul 21 12:04 /var/lib/mysql/zabbix/history#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107220000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107230000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107240000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107250000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107260000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107270000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107290000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107300000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202107310000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202108010000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202108020000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history#P#p202108030000.ibd
-rw-rw---- 1 mysql mysql 2.8K Jul 21 10:48 /var/lib/mysql/zabbix/history_str.frm
-rw-rw---- 1 mysql mysql  284 Jul 21 10:48 /var/lib/mysql/zabbix/history_str.par
-rw-rw---- 1 mysql mysql 368K Jul 21 12:01 /var/lib/mysql/zabbix/history_str#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107220000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107230000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107240000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107250000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107260000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107270000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107290000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107300000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202107310000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202108010000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202108020000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_str#P#p202108030000.ibd
-rw-rw---- 1 mysql mysql 2.1K Jul 21 10:48 /var/lib/mysql/zabbix/history_text.frm
-rw-rw---- 1 mysql mysql  284 Jul 21 10:48 /var/lib/mysql/zabbix/history_text.par
-rw-rw---- 1 mysql mysql 224K Jul 21 12:04 /var/lib/mysql/zabbix/history_text#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107220000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107230000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107240000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107250000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107260000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107270000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107290000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107300000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202107310000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202108010000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202108020000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_text#P#p202108030000.ibd
-rw-rw---- 1 mysql mysql 2.1K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint.frm
-rw-rw---- 1 mysql mysql  284 Jul 21 10:48 /var/lib/mysql/zabbix/history_uint.par
-rw-rw---- 1 mysql mysql 144M Jul 21 12:04 /var/lib/mysql/zabbix/history_uint#P#p202107210000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107220000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107230000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107240000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107250000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107260000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107270000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107280000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107290000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107300000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202107310000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202108010000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202108020000.ibd
-rw-rw---- 1 mysql mysql 112K Jul 21 10:48 /var/lib/mysql/zabbix/history_uint#P#p202108030000.ibd

3、设置定时任务

[12:04:27 root@localhost ~]#crontab -e

01 01 * * *  /usr/bin/mysql -uzabbix -ppassword zabbix -e "CALL partition_maintenance_all('zabbix')" &>/var/log/partition.log

4、关闭zabbix 管家功能(housekeeping)


image.png

你可能感兴趣的:(zabbix数据库分表)