一 、背景介绍
近年来,TokuDB作为MySQL的大数据(Big Data)存储引擎受到人们的普遍关注。其架构的核心基于一种新的叫做分形树(Fractal Trees)的索引数据结构,该结构是缓存无关的,即使索引数据大小超过内存性能也不会下降,也即没有内存生命周期和碎片的问题。特别引人注意的是,TokuDB拥有很高的压缩比(官方称最大可达25倍),可以在很大的数据上创建大量的索引,并保持性能不下降。同时,TokuDB支持ACID和MVCC,还有在线修改表结构(Live Schema Modification)以及增加的复制性能等特性,使其在某些特定的应用领域(如日志存储与分析)有着独特的优势。
在TokuDB的应用场景中,通常是数据库插入操作的量远远大于读取的量,因而本此本测试是在公司生产库上增加一个从库,来体验下TokuDB的高压缩比和低存储占用率,而且在相同数据的情况下io使用率更优秀。
本测试是在生产环境中增加一个从库,来验证ToKuDB在大频率写入,小频率读的场景验证。
链接:https://pan.baidu.com/s/1hs8IOao 密码:nrxh Centos7
链接:https://pan.baidu.com/s/1c2dIPZM 密码:opmx Centos6
Github地址:https://github.com/XeLabs/tokudb.git
安利下这是我参加的全宇宙最牛逼的MySQL培训班知数堂MySQL tokudb分支版本,学最专业的MySQL,请来知数堂找我们吴老师,删库跑路跑的快的叶老师
http://www.3wedu.net/
一、首先我们导出生产环境主库的表结构跟数据。
1、导出主库表结构(为脱敏处理把库名更改为test)
shell>
mysqldump -p --no-data --databases test >test_table.sql
2、导出数据
shell>
mysqldump -p -t --master-data=2 test >test_data.sql
3、处理表结构语句
把所有innodb存储引擎为表改为tokudb
shell>
sed -i 's@InnoDB@TokuDB@g' test_table.sql
4、拷贝数据到需要建立的TokuDB从库服务器上
二、创建percona TokuDB版本从库
下载相应的二进制包
下载地址
1、优化系统参数,是系统可以满足TokuBD的安装要求
关闭系统透明大页
shell>
echo never > /sys/kernel/mm/transparent_hugepage/enabled
shell>
echo never > /sys/kernel/mm/transparent_hugepage/defrag
2、创建mysql用户增加数据目录
shell>
groupadd mysql
shell>
useradd -r -g mysql -s /sbin/nologin mysql
shell>
cd /opt
shell>
tar -xf XeLabs-TokuDB-5.7.19-Centos6-r1.X86_64.tar.gz
shell>
ln -s /opt/XeLabs-TokuDB-5.7.19-Centos6-r1.X86_64 /usr/local/mysql
shell>
mkdir /data/mysql/mysql3306/{data,logs,tmp} -p
shell>
chown mysql.mysql /usr/local/mysql/ /usr/local/mysql /data/mysql -R
[root@smsdb1 ~]#cat /etc/my.cnf
[client] port = 3306 socket = /tmp/mysql3306.sock default-character-set=utf8mb4 [mysql] prompt="\\u@\\h [\\d]>" #pager="less -i -n -S" #tee=/opt/mysql/query.log no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data port = 3306 socket = /tmp/mysql3306.sock event_scheduler = 0 default-storage-engine=tokudb skip-name-resolve tmpdir = /data/mysql/mysql3306/tmp #timeout interactive_timeout = 2880000 wait_timeout = 2880000 #character set character-set-server = utf8mb4 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 lower_case_table_names =1 # explicit_defaults_for_timestamp=1 #symi replication #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=1 #logs log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log pid-file = mysql.pid long_query_time = 1 log_error_verbosity=1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #binlog #binlog_format = STATEMENT binlog_format = row server-id = 43306 log-bin = /data/mysql/mysql3306/logs/mysql-bin binlog_cache_size = 1M max_binlog_size = 256M max_binlog_cache_size = 4M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 # gtid-mode = on enforce-gtid-consistency=1 #relay log skip_slave_start = 1 max_relay_log_size = 128M relay_log_purge = 1 relay_log_recovery = 1 relay-log=relay-bin relay-log-index=/data/mysql/mysql3306/logs/relay-bin.index log_slave_updates #slave-skip-errors=1032,1053,1062 #skip-grant-tables #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 200 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 100M innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:100M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT loose_tokudb_cache_size=4G loose_tokudb_directio=ON loose_tokudb_fsync_log_period=1000 tokudb_commit_sync=0
初始化无密码的数据库
shell>
cd /usr/local/mysql/bin/ && ./mysqld --initialize-insecure
启动MySQL数据库
shell>
cp support-files/mysql.server /etc/init.d/mysqld
shell>
/etc/init.d/mysqld start
增加MySQL环境变量
shell>
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
shell>
source /etc/profile
导入表结构
shell>
mysql -p test<test_table.sql
清理GTID信息
shell>
mysql -e 'reset master'
导入数据
shell>
mysql -p test <test_data.sql
执行change master 操作
mysql>
change master to master_host='192.168.1.10',master_port='3306',master_user='repl',master_password='repl',master_auto_position=1;
mysql>
start slave;
mysql>
show slave status\G
root@localhost [(none)]>show slave status\G
* 1. row *
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.10
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000029
Read_Master_Log_Pos: 900797194
Relay_Log_File: relay-bin.000028
Relay_Log_Pos: 68956928
Relay_Master_Log_File: mysql-bin.000029
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 900797194
Relay_Log_Space: 203175161
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1303306
Master_UUID: d54f3590-7760-11e7-9f22-fa163e3dde13
Master_Info_File: /data/mysql/mysql3306/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: d54f3590-7760-11e7-9f22-fa163e3dde13:31849593-32456621
Executed_Gtid_Set: 05c9edae-dee5-11e7-91fb-fa163ecf7778:1-2,
d54f3590-7760-11e7-9f22-fa163e3dde13:1-32456621
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
root@localhost [(none)]>
至此主从环境搭建完毕。
对比下主库InnoDB存贮引擎数据与从库TokuDB存储引擎的数据大小对比
InnoDB存储引擎在实例数据6G,
TokuDB 存储引擎存储的数据不到1G
在3.6G 大小sql语句下插入 innodb存储引擎与tokudb存储引擎磁盘iO对比
由此可见tokudb在磁盘节约和io使用上在写场景比较多的业务中相当给力的。