程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 如何安裝TokuDB,安裝TokuDB

如何安裝TokuDB,安裝TokuDB

編輯:MySQL綜合教程

如何安裝TokuDB,安裝TokuDB


TokuDB是Tokutek公司開發的基於ft-index(Fractal Tree Index)鍵值對的存儲引擎。

它使用索引加快查詢速度,具有高擴展性,並支持hot scheme modification,具有以下特點:

1.插入性能快20~80倍;

2.壓縮數據減少存儲空間;

3.數據量可以擴展到幾個TB;

4.不會產生索引碎片;

5.支持hot column addition,hot indexing,mvcc

 

適用場景:

1. 如果你要存儲blob,不要使用TokuDB,因為它限制記錄不能太大;

2. 如果你的記錄數量過億,使用TokuDB;

3. 如果你注重update的性能,不要使用TokuDB,它沒有Innodb快;

4. 如果你要存儲舊的記錄,使用TokuDB;

5. 如果你想要縮小數據占用的存儲空間,使用TokuDB;

 

關於TokuDB和InnoDB性能壓測報告,可參考:

https://www.percona.com/blog/2016/02/01/innodb-and-tokudb-on-aws/

 

以下安裝基於Percona 5.6.31-77.0

 

安裝libjemalloc庫

該庫在EPEL中有提供

# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

# rpm -ivh epel-release-latest-6.noarch.rpm 

# yum install jemalloc -y

 

通過yum安裝,生成的庫文件為/usr/lib64/libjemalloc.so.1

[root@localhost ~]# rpm -qa |grep jemalloc
jemalloc-3.6.0-1.el6.x86_64
[root@localhost ~]# rpm -ql jemalloc-3.6.0-1.el6.x86_64
/usr/bin/jemalloc.sh
/usr/lib64/libjemalloc.so.1
/usr/share/doc/jemalloc-3.6.0
/usr/share/doc/jemalloc-3.6.0/COPYING
/usr/share/doc/jemalloc-3.6.0/README
/usr/share/doc/jemalloc-3.6.0/VERSION
/usr/share/doc/jemalloc-3.6.0/jemalloc.html

 

修改配置文件my.cnf

在[mysqld_safe]下設置malloc-lib變量

malloc-lib=/usr/lib64/libjemalloc.so.1

重啟mysqld_safe進程

啟動過程中,會輸出以下信息:

160810 20:11:46 mysqld_safe Adding '/usr/lib64/libjemalloc.so.1' to LD_PRELOAD for mysqld

 

如果不安裝該庫的話,則在加載TokuDB插件時會報如下錯誤:

mysql> INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';
2016-08-10 16:25:02 1861 [ERROR] TokuDB is not initialized because jemalloc is not loaded
2016-08-10 16:25:02 1861 [ERROR] Plugin 'TokuDB' init function returned error.
2016-08-10 16:25:02 1861 [ERROR] Plugin 'TokuDB' registration as a STORAGE ENGINE failed.
2016-08-10 16:25:02 1861 [Note] Shutting down plugin 'TokuDB'
ERROR 1123 (HY000): Can't initialize function 'tokudb'; Plugin initialization function failed.

 

禁用Transparent huge pages

查看當前內核是否已啟用Transparent huge pages

# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

always代表已啟用

 

如何禁用呢?

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

 

如果沒有禁用的話,在後續安裝插件的時候會報錯:

mysql> INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';
ERROR 1123 (HY000): Can't initialize function 'tokudb'; Plugin initialization function failed.

並且,錯誤日志中打印如下信息:

2016-08-10 20:47:51 4764 [ERROR] TokuDB: Huge pages are enabled, disable them before continuing

2016-08-10 20:47:51 4764 [ERROR] ************************************************************
2016-08-10 20:47:51 4764 [ERROR]                                                             
2016-08-10 20:47:51 4764 [ERROR]                         @@@@@@@@@@@                         
2016-08-10 20:47:51 4764 [ERROR]                       @@'         '@@                       
2016-08-10 20:47:51 4764 [ERROR]                      @@    _     _  @@                      
2016-08-10 20:47:51 4764 [ERROR]                      |    (.)   (.)  |                      
2016-08-10 20:47:51 4764 [ERROR]                      |    (.)   (.)  |                      
2016-08-10 20:47:51 4764 [ERROR]                      |             ` |                      
2016-08-10 20:47:51 4764 [ERROR]                      |        >    ' |                      
2016-08-10 20:47:51 4764 [ERROR]                      |     .----.    |                      
2016-08-10 20:47:51 4764 [ERROR]                      ..   |.----.|  ..                      
2016-08-10 20:47:51 4764 [ERROR]                       ..  '      ' ..                       
2016-08-10 20:47:51 4764 [ERROR]                         .._______,.                         
2016-08-10 20:47:51 4764 [ERROR]                                                             
2016-08-10 20:47:51 4764 [ERROR] TokuDB will not run with transparent huge pages enabled.        
2016-08-10 20:47:51 4764 [ERROR] Please disable them to continue.                            
2016-08-10 20:47:51 4764 [ERROR] (echo never > /sys/kernel/mm/transparent_hugepage/enabled)  
2016-08-10 20:47:51 4764 [ERROR]                                                             
2016-08-10 20:47:51 4764 [ERROR] ************************************************************
2016-08-10 20:47:51 4764 [ERROR] Plugin 'TokuDB' init function returned error.
2016-08-10 20:47:51 4764 [ERROR] Plugin 'TokuDB' registration as a STORAGE ENGINE failed.
2016-08-10 20:47:51 4764 [Note] Shutting down plugin 'TokuDB'

 

啟用TokuDB

Percona是5.6.17-66.0將TokuDB插件引入到自己的二進制版本中,5.6.19-67.0起才能作為GA版本使用。5.6.22-72.0起開發了一個腳本ps_tokudb_admin來簡化TokuDB的安裝工作。

 

首先,來看看TokuDB如何手動安裝

主要是加載插件,TokuDB插件名為ha_tokudb.so,默認放到plugin_dir下。

登錄mysql客戶端,執行如下命令

INSTALL PLUGIN tokudb SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_file_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_info SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_fractal_tree_block_map SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_trx SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_locks SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_lock_waits SONAME 'ha_tokudb.so';
INSTALL PLUGIN tokudb_background_job_status SONAME 'ha_tokudb.so';

 

查看插件是否加載成功

mysql> show engines;

| TokuDB             | YES     | Percona TokuDB Storage Engine with Fractal Tree(tm) Technology             | YES          | YES  | YES        |

mysql> show plugins;

| TokuDB                        | ACTIVE   | STORAGE ENGINE     | ha_tokudb.so | GPL     |
| TokuDB_file_map               | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_fractal_tree_info      | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_fractal_tree_block_map | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_trx                    | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_locks                  | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_lock_waits             | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |
| TokuDB_background_job_status  | ACTIVE   | INFORMATION SCHEMA | ha_tokudb.so | GPL     |

 

創建一張表,測試一下

mysql> create table test.test(id int) engine=tokudb;
Query OK, 0 rows affected (0.23 sec)

至此,TokuDB手動安裝完畢~

 

腳本安裝

其實,Percona官方在5.6.22-72.0版本中提供了一個腳本,可用於自動安裝TokuDB插件,涉及的操作包括禁用透明大頁,加載插件。

該腳本在二進制包的bin目錄下。

[root@localhost bin]# ./ps_tokudb_admin --help
This script is used for installing and uninstalling TokuDB plugin for Percona Server 5.6.
It can also be used to install or uninstall the Percona TokuBackup plugin (requires mysql server restart).
If transparent huge pages are enabled on the system it adds thp-setting=never option to my.cnf
to disable it on runtime.

Valid options are:
  --user=user_name, -u user_name     mysql admin username
  --password[=password], -p[password]     mysql admin password (on empty will prompt to enter)
  --socket=path, -S path         the socket file to use for connection
  --host=host_name, -h host_name     connect to given host
  --port=port_num, -P port_num         port number to use for connection
  --defaults-file=file          specify defaults file instead of guessing
  --enable, -e                 enable TokuDB plugin and disable transparent huge pages in my.cnf
  --enable-backup, -b             enable Percona TokuBackup and add preload-hotbackup option to my.cnf
                     (this option includes --enable option)
  --disable, d                 disable TokuDB plugin and remove thp-setting=never option in my.cnf
                     (this option includes --disable-backup option)
  --disable-backup, r             disable Percona TokuBackup and remove preload-hotbackup option in my.cnf
  --help                 show this help

For TokuDB requirements and manual steps for installation please visit this webpage:
http://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_installation.html

該腳本是用shell寫的,參數也比較簡單,其中,--enable-backup還包括安裝TokuDB在線熱備插件。

 

腳本安裝過程如下

 ./ps_tokudb_admin --enable --host=127.0.0.1 --port=3307 --user=root -p
Enter password:
Continuing without password...


Checking SELinux status...
INFO: SELinux is disabled.

Checking if Percona Server is running with jemalloc enabled...
INFO: Percona Server is running with jemalloc enabled.

Checking transparent huge pages status on the system...
INFO: Transparent huge pages are currently disabled on the system.

Checking if thp-setting=never option is already set in config file...
INFO: Option thp-setting=never is set in the config file.

Checking TokuDB engine plugin status...
INFO: TokuDB engine plugin is installed.

 

總結

TokuDB最新版本是7.5.7,實際上現在是以插件的形式包含在Percona二進制發行版中。但該插件並不能直接在MySQL社區版中使用。

TokuDB基於MySQL 5.5.30源碼,重新打包了個二進制版本,mysql-5.5.30-tokudb-7.1.0-linux-x86_64.tar.gz,基於TokuDB 7.1.0。

但也僅限如此,MySQL 5.6和5.7的社區版中並不能直接使用TokuDB插件。

以後若要使用較新版本的MySQL和TokuDB,只能使用Percona版本的。

下面是官檔中的說明

Please note that Tokutek made some changes to the MySQL source that are required to either fix bugs or aid in performance, so if you are compiling from source you must use the Tokutek version of MySQL that is based on the MySQL 5.5.30 source.

 

參考

1. https://www.percona.com/blog/2013/07/02/tokumx-fractal-treer-indexes-what-are-they/

2. http://dbaplus.cn/news-21-418-1.html

3. https://www.izhangheng.com/highly-scalable-storage-engine-tokudb

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved