
背景
zabbix 数据库由阿里云 RDS 迁移至自建 DB,迁移过程中发现 RDS 为 tokudb 引擎
Prerequisites
libjemalloc library
1 | yum install jemalloc -y |
通过 yum 安装,生成的库文件为/usr/lib64/libjemalloc.so.1
1 | [root@yunwei /www/server/data]# rpm -qa |grep jemalloc |
Transparent huge pages
关闭内存大页
1 | echo never > /sys/kernel/mm/transparent_hugepage/enabled |
查看下
1 | root@ptest:~# cat /sys/kernel/mm/transparent_hugepage/enabled |
Installing Percona Server for MySQL from Percona yum repository
- Install the Percona repository
You can install Percona yum repository by running the following command as a root user or with sudo:
1 | $ yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm |
Output example
1 | Retrieving https://repo.percona.com/yum/percona-release-latest.noarch.rpm |
To install Percona Server for MySQL with SELinux policies, you also need the Percona-Server-selinux-*.noarch.rpm package:
1 | $ yum install http://repo.percona.com/centos/7/RPMS/x86_64/Percona-Server-selinux-56-5.6.42-rel84.2.el7.noarch.rpm |
- Testing the repository
Make sure packages are now available from the repository, by executing the following command:
1 | yum list | grep percona |
You should see output similar to the following:
1 | ... |
- Install the packages
You can now install Percona Server for MySQL by running:
1 | yum install Percona-Server-server-56 |
install
You can install the Percona Server for MySQL with TokuDB engine by using the apt/yum commands:
1 | [root@centos ~]# yum install Percona-Server-tokudb-56.x86_64 |
or
1 | root@wheezy:~# apt-get install percona-server-tokudb-5.6 |
Enabling the TokuDB Storage Engine
Once the TokuDB server package has been installed following output will be shown:
This release of Percona Server is distributed with TokuDB storage engine.
Run the following script to enable the TokuDB storage engine in Percona Server:
ps_tokudb_admin –enable -u
-p[mysql_admin_pass] [-S ] [-h -P ] See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html for more installation details
See http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_intro.html for an introduction to TokuDB
Percona Server for MySQL 5.6.22-72.0 has implemented ps_tokudb_admin script to make the enabling the TokuDB storage engine easier. This script will automatically disable Transparent huge pages, if they’re enabled, and install and enable the TokuDB storage engine with all the required plugins. You need to run this script as root or with sudo. After you run the script with required parameters:
1 | ps_tokudb_admin --enable -uroot -pPassw0rd |
Following output will be displayed:
1 | Checking if Percona server is running with jemalloc enabled... |
If the script returns no errors, TokuDB storage engine should be successfully enabled on your server. You can check it out by running:
1 | mysql> SHOW ENGINES; |
To check if all the TokuDB plugins have been installed correctly you should run:
1 | mysql> SHOW PLUGINS; |
TokuDB Version
TokuDB storage engine version can be checked with:
1 | mysql> SELECT @@tokudb_version; |
TokuDB storage engine has the same version as Percona Server for MySQL after 5.6.26-74.0
release.
my.cnf
1 | # Percona-5.6.17, TokuDB-7.1.6,用于Zabbix数据库参考配置 |
innobackupex 数据迁移
前提条件
- 部署 mysql
- 下载 RDS 物理备份文件
数据迁移
- 执行如下命令,解压已下载的数据备份文件。
说明
- 本文以自定义路径
/home/mysql/data
为例,您可以根据实际情况将其替换成实际路径。 innobackupex
解压命令需要安装qpress
,您可以使用命令yum install qpress -y
安装。
- 本文以自定义路径
- tar 压缩包 (.tar.gz 后缀)
- xbstream 压缩包 (.xb.gz 后缀)
- xbstream 文件包(_qp.xb 后缀)
说明
2019年2月20日后创建的
MySQL 5.6
实例,数据备份文件的格式为xbstream文件包(_qp.xb 后缀)。对于xbstream 压缩包 (.xb.gz 后缀),使用命令:1
tar -izxvf <数据备份文件名>.tar.gz -C /home/mysql/data
对于xbstream 文件包(_qp.xb 后缀),使用命令:1
gzip -d -c <数据备份文件名>.xb.gz | xbstream -x -v -C /home/mysql/data
1
2
3
4## 解包
cat <数据备份文件名>_qp.xb | xbstream -x -v -C /home/mysql/data
## 解压
innobackupex --decompress --remove-original /home/mysql/data说明
-C
:指定文件要解压到的目录。可选参数,若不指定就解压到当前目录。
为避免版本问题,需修改
backup-my.cnf
参数,具体操作步骤如下。- 执行如下命令,以文本方式编辑
backup-my.cnf
文件。1
vi /home/mysql/data/backup-my.cnf
- 自建数据库不支持如下参数,需要注释掉。
1
2
3
4
5
6
7
8#innodb_log_checksum_algorithm
#innodb_fast_checksum
#innodb_log_block_size
#innodb_doublewrite_file
#rds_encrypt_data
#innodb_encrypt_algorithm
#redo_log_version
#master_key_id- 如果自建数据库使用的是MyISAM引擎,和阿里云的InnoDB不兼容,需要多注释掉如下参数并增加skip-grant-tables参数:
1
2
3#innodb_log_checksum_algorithm=strict_crc32
#redo_log_version=1
skip-grant-tables - 如果自建数据库使用的是MyIAM引擎,且对系统表进行操作时报错(存储引擎相关),请按如下操作进行存储引擎的转换:
1
alter engine <表名> engine=myisam;
- 如果自建数据库使用的是MyISAM引擎,和阿里云的InnoDB不兼容,需要多注释掉如下参数并增加skip-grant-tables参数:
- 执行如下命令,以文本方式编辑
执行如下命令,恢复解压好的备份文件。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81[root@yunwei /www/server/data]# innobackupex --defaults-file=/www/server/data/backup-my.cnf --apply-log /www/server/data/
191226 13:42:51 innobackupex: Starting the apply-log operation
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
innobackupex version 2.3.10 based on MySQL server 5.6.24 Linux (x86_64) (revision id: bd0d4403f36)
xtrabackup: cd to /www/server/data/
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(276623660719)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:200M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:200M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 276623660719
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages
InnoDB: from the doublewrite buffer...
InnoDB: Doing recovery: scanned up to log sequence number 276625422981 (94%)
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percent: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: 128 rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6.24 started; log sequence number 276625422981
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 276625423497
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:200M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 1048576000
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Setting log file ./ib_logfile101 size to 1000 MB
InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000
InnoDB: Setting log file ./ib_logfile1 size to 1000 MB
InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=276625423497
InnoDB: Highest supported file format is Barracuda.
InnoDB: 128 rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6.24 started; log sequence number 276625423884
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 276625427858
191226 13:43:28 completed OK!说明 请确保您的Percona XtraBackup版本正确:
MySQL 5.6及之前的版本需要安装 Percona XtraBackup 2.3,安装指导请参见官方文档Percona XtraBackup 2.3。
MySQL 5.7版本需要安装 Percona XtraBackup 2.4,安装指导请参见官方文档Percona XtraBackup 2.4。
MySQL 8.0版本需要安装 Percona XtraBackup 8.0,安装指导请参见官方文档Percona XtraBackup 8.0。
参考
- TokuDB Installation
- Installing Percona Server for MySQL on Red Hat Enterprise Linux and CentOS
- 自建Percona5.7.23同步阿里云RDS(MySQL5.6)TokuDB数据库
- RDS MySQL 物理备份文件恢复到自建数据库
写在最后
关于RDS迁移后自动备份,请参考使用python实现innobackup自动化备份、清理、通知