Debian Squeeze 安裝 MySQL HandlerSocket Plugin

去年 10 月 20 YOSHINORI MATSUNOBU 寫了 Using MySQL as a NoSQL – A story for exceeding 750,000 qps on a commodity server 這篇文章,裡面介紹了 DeNA Co.,Ltd. 發表的 HandlerSocket-Plugin-for-MySQL,好處在原網站有講到很多,最大的優勢是速度比傳統的用 SQL 查詢 MySQL 還要快了七倍之多 (MySQL via SQL = 105,000 qps, MySQL via HandlerSocket = 750,000 qps).

以下簡單講一下在 Debian Squeeze 安裝 MySQL HandlerSocket Plugin 的方法。

記得用 root 執行以下指令

sudo su

切到放原始碼的目錄下

cd /usr/src/

先取回 MySQL Server 原始碼

apt-get source mysql-server-5.1

目前版本是 5.1-5.1.49

cd mysql-5.1-5.1.49/

將所有 patch 加入

dpatch apply-all

回到原本目錄

cd -

拿回 HandlerSocket 原始碼,如果沒有 get 可以先安裝 apt-get install git-core

git clone https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL.git handlersocket

產生 Makefile

cd handlersocket/
sh autogen.sh
./configure --with-mysql-source=../mysql-5.1-5.1.49/ --with-mysql-bindir=/usr/bin/ --with-mysql-plugindir=/usr/lib/mysql/plugin/

安裝到系統中 (/usr/lib/mysql/plugin/)

make
make install

到 MySQL 中安裝 handlersocket.so

mysql -u root -p -h localhost

mysql> install plugin handlersocket soname 'handlersocket.so';
Query OK, 0 rows affected (0.02 sec)

接著建立 MySQL 的設定檔

touch /etc/mysql/conf.d/handlersocket.cnf

設定檔內容

[mysqld]
loose_handlersocket_port = 9998
# the port number to bind to (for read requests)
loose_handlersocket_port_wr = 9999
# the port number to bind to (for write requests)
loose_handlersocket_threads = 16
# the number of worker threads (for read requests)
loose_handlersocket_threads_wr = 1
# the number of worker threads (for write requests)
open_files_limit = 65535
# to allow handlersocket accept many concurrent
# connections, make open_files_limit as large as
# possible.

修改 services

vi /etc/services

加入兩個服務

mysql-hsr 9998/tcp # the port number to bind to (for read requests)
mysql-hsw 9999/tcp # the port number to bind to (for write requests)

然後重新啟動 MySQL ,到這邊 Server 的 Plugin 就安裝完成了

/etc/init.d/mysql restart

接著安裝 Client 端程式,這邊以 PHP 為例,安裝 php-handlersocket

下載 tarball

wget http://php-handlersocket.googlecode.com/files/php-handlersocket-0.0.7.tar.gz

解開,並且安裝

tar -zxvf php-handlersocket-0.0.7.tar.gz
cd php-handlersocket/
phpize
./configure
make
make install

然後新增設定檔加入模組

touch /etc/php5/conf.d/handlersocket.ini

裡面加入

;php-handlersocket
extension=handlersocket.so

這樣就差不多完成了,下一篇文章會簡介使用方法。

Posted in DB
0 comments on “Debian Squeeze 安裝 MySQL HandlerSocket Plugin
1 Pings/Trackbacks for "Debian Squeeze 安裝 MySQL HandlerSocket Plugin"
  1. […] HandlerSocket 存取 MySQL ,必須先安裝好 php-handlersocket 這個 PHP Extension ,在 Debian Squeeze 安裝 MySQL HandlerSocket Plugin […]

Leave a Reply

Your email address will not be published.