1.zabbix mysql 目录清单
--basedir=/usr/local/web/mysql--datadir=/data/mysql--log-error=/data/mysql/syscent.bc.com.err--pid-file=/data/mysql/syscent.bc.com.pid--socket=/dev/shm/mysql.sock --port=3306Zabbix 数据文件目录/data/mysql/zabbix
Source server:192.168.1.2 3306Target server:192.168.1.4 3306
2.关闭zabbix
/usr/local/zabbix/sbin/zabbix_server stop
3. zabbix配置文件修改
/usr/local/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=DBPort=3306ListenIP=192.168.1.4
4.关闭mysql
Service mysqld stop
5. 数据文件拷贝
Scp /data/mysql/* xxx.xxx.xxx.xxx:/Mysql数据文件目录
或者使用
Innobackupex迁移
6. 启动Mysql
配置文件修改:
innodb_flush_log_at_trx_commit=0 or 2建议0
Sync_binlog=1000Mysqld_safe--defaults-file=/usr/local/mysql/my3306.cnf &
7. Mysql数据表导出
mysqldump -uroot -p -P3306 -h127.0.0.1 --databases zabbix --tables history>history.sql
mysqldump-uroot -p -P3306 -h127.0.0.1 --databases zabbix --tables history_str>history_str.sql
mysqldump-uroot -p -P3306 -h127.0.0.1 --databases zabbix --tables history_text>history_text.sql
mysqldump-uroot -p -P3306 -h127.0.0.1 --databases zabbix --tables history_uint>history_uint.sql
8.Mysql创建分区表
History
History_str
History_uint
History_text
改成月分区表
CREATE TABLE history_uint(
itemid bigint(20) unsigned NOT NULL,
clock int(11) NOT NULL DEFAULT '0',
value bigint(20) unsigned NOT NULL DEFAULT '0',
Ns int(11) NOT NULL DEFAULT '0',
KEY history_uint_1 (itemid,clock)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
PARTITION BY RANGE(clock)
(
PARTITION p201708 VALUES LESS THAN (1504195200)
ENGINE=INNODB,
PARTITION p201709 VALUES LESS THAN (1506787200)
ENGINE=INNODB,
PARTITION p201710 VALUES LESS THAN (1509465600)
ENGINE=INNODB);
DATA DIRECTORY 根据请况是否添加
分区可以创建到2020,暂时不添加maxvalue
定时任务添加分区
History
History_str
History_uint
History_text
分区操作同上
9.导入分区表
将history.sql,history_str.sql,history_text.sql,history_uint.sql drop table语句,以及create table 语句删除
然后执行语句,导入数据库
10.启动zabbix
/usr/local/zabbix/sbin/zabbix_server start
11.定时任务删除历史数据
每月3号删除上上月分区,zabbix最大为2月历史数据
10月3号,删除8月分区,增加11月分区#!/bin/bash#add by sk
User="zabbix"Passwd="zabbix"
#zabbix保留1月数据
Date=`date -d "-2 months" +%Y%m`#添加分区使用
Date_a=`date -d "2 months" +%Y%m`
Date_b=`date -d "1 months" +%Y%m`
Date_t=`date -d "2 months" +%Y-%m`-01v_time=`date +%s -d $Date_t`
$(which mysql)-u${User} -p${Passwd} -Dzabbix -e "ALTER TABLE history DROP PARTITION p$Date;
ALTER TABLE history_str DROP PARTITION p$Date;
ALTER TABLE history_text DROP PARTITION p$Date;
ALTER TABLE history_uint DROP PARTITION p$Date;#添加分区如下:
alter table history add partition (partition p$Date_b VALUES LESS THAN ($v_time) ENGINE =INNODB);
alter table history_str add partition (partition p$Date_b VALUES LESS THAN ($v_time) ENGINE=INNODB);
alter table history_text add partition (partition p$Date_b VALUES LESS THAN ($v_time) ENGINE=INNODB);
alter table history_uint add partition (partition p$Date_b VALUES LESS THAN ($v_time) ENGINE=INNODB);"脚本参考MYSQL操作语句:
ALTER TABLE history_uint DROP PARTITION p201709;
alter table history_uint add partition (partition p201712 VALUES LESS THAN (1514736000) ENGINE = INNODB);
12.改成分区表原因
历史表数据删除耗费时间
Deletefrom history_uint where clock
History_uint delete+optimize 保守3小时
删除分区时间较快