mroonga - MySQLで高速に全文検索するためのオープンソースのストレージエンジン

2. インストールガイド

バイナリパッケージを使用したインストールではgroonga関連パッケージと共にMySQL関連のパッケージもインストールされます。

32-bit用と64-bit用のパッケージを配布していますが、サーバ用途には64-bitパッケージを利用することをオススメします。32-bit用パッケージはテスト用か開発用にだけ使って下さい。32-bit用パッケージを使った場合は、中程度のサイズのデータでもメモリ不足エラーになることがあります。

それぞれの環境毎にインストール方法を説明します。

2.1. Debian GNU/Linux squeeze

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/debian/ squeeze main
deb-src http://packages.groonga.org/debian/ squeeze main

インストール:

% sudo aptitude update
% sudo aptitude -V -D -y --allow-untrusted install groonga-keyring
% sudo aptitude update
% sudo aptitude -V -D -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo aptitude -V -D -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo aptitude -V -D -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.2. Debian GNU/Linux wheezy

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/debian/ wheezy main
deb-src http://packages.groonga.org/debian/ wheezy main

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.3. Debian GNU/Linux sid

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/debian/ unstable main
deb-src http://packages.groonga.org/debian/ unstable main

インストール:

% sudo aptitude update
% sudo aptitude -V -D -y --allow-untrusted install groonga-keyring
% sudo aptitude update
% sudo aptitude -V -D -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo aptitude -V -D -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo aptitude -V -D -y install groonga-normalizer-mysql

ノート

'utf8_unicode_ci'や'utf8mb4_unicode_ci'は今後のリリースでサポート予定です。

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.4. Ubuntu 10.04 LTS Lucid Lynx

ノート

Ubuntu本家のuniverseセクションもインストール対象としておくこと

ノート

セキュリティアップデートリポジトリもインストール対象としておくこと

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/ubuntu/ lucid universe
deb-src http://packages.groonga.org/ubuntu/ lucid universe

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.5. Ubuntu 11.10 Oneiric Ocelot

ノート

Ubuntu本家のuniverseセクションもインストール対象としておくこと

ノート

セキュリティアップデートリポジトリもインストール対象としておくこと

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/ubuntu/ oneiric universe
deb-src http://packages.groonga.org/ubuntu/ oneiric universe

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.6. Ubuntu 12.04 Precise Pangolin

ノート

Ubuntu本家のuniverseセクションもインストール対象としておくこと

ノート

セキュリティアップデートリポジトリもインストール対象としておくこと

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/ubuntu/ precise universe
deb-src http://packages.groonga.org/ubuntu/ precise universe

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.7. Ubuntu 12.10 Quantal Quetzal

ノート

Ubuntu本家のuniverseセクションもインストール対象としておくこと

ノート

セキュリティアップデートリポジトリもインストール対象としておくこと

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/ubuntu/ quantal universe
deb-src http://packages.groonga.org/ubuntu/ quantal universe

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.8. Ubuntu 13.04 Raring Ringtail

ノート

Ubuntu本家のuniverseセクションもインストール対象としておくこと

ノート

セキュリティアップデートリポジトリもインストール対象としておくこと

/etc/apt/sources.list.d/groonga.list:

deb http://packages.groonga.org/ubuntu/ raring universe
deb-src http://packages.groonga.org/ubuntu/ raring universe

インストール:

% sudo apt-get update
% sudo apt-get -y --allow-unauthenticated install groonga-keyring
% sudo apt-get update
% sudo apt-get -y install mysql-server-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo apt-get -y install groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo apt-get -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.9. CentOS 5

既にディストリビューション由来のMySQLパッケージがインストール済みの場合には事前に削除する必要があります。

既存のMySQLパッケージを削除:

% sudo yum remove 'mysql*'

インストール:

% sudo rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-1.noarch.rpm
% sudo yum makecache
% sudo yum install -y MySQL-server
% sudo service mysql start
% sudo yum install -y mysql-mroonga
(% /usr/bin/mysqladmin -u root password 'new-password')

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo yum install -y groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo yum install -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.10. CentOS 6

CentOS 6用のパッケージはCentOS 5用のパッケージと違い、ディストリビューション由来のMySQLパッケージ(MySQL 5.1系)を利用します。そのため、ディストリビューション由来のMySQLを削除する必要はありません。

インストール:

% sudo rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-1.noarch.rpm
% sudo yum makecache
% sudo yum install -y mysql-server
% sudo service mysqld start
% sudo yum install -y mysql-mroonga
(% /usr/bin/mysqladmin -u root password 'new-password')

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo yum install -y groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo yum install -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.11. Fedora 18

インストール:

% sudo rpm -ivh http://packages.groonga.org/fedora/groonga-release-1.1.0-1.noarch.rpm
% sudo yum makecache
% sudo yum install -y mysql-mroonga

トークナイザーとして MeCab を利用したい場合はgroonga-tokenizer-mecabをインストールしてください。

groonga-tokenizer-mecabをインストール:

% sudo yum install -y groonga-tokenizer-mecab

groonga-tokenizer-mecabをインストール:

% sudo yum install -y groonga-tokenizer-mecab

If you want to use MySQL compatible COLLATION such as 'utf8_general_ci', 'utf8mb4_general_ci', 'utf8_unicode_ci' or 'utf8mb4_unicode_ci', please install groonga-normalizer-mysql package.

groonga-normalizer-mysqlをインストール:

% sudo yum install -y install groonga-normalizer-mysql

ノート

If you specified neither 'utf8_general_ci' nor 'utf8mb4_general_ci', nor 'utf8_unicode_ci', nor 'utf8mb4_unicode_ci', mroonga uses MySQL incompatible COLLATION which is implemented in groonga.

2.12. Mac OS X

インストール:

% brew install https://raw.github.com/mroonga/homebrew/master/mroonga.rb --use-homebrew-mysql

2.13. ソースコードからのインストール

ソースコードからインストールする方法を説明します。パッケージがない環境ではソースコードからインストールすることになります。

2.13.1. 形態素解析(MeCab)について

形態素単位でトークナイズした全文検索索引を使用したい場合は、groongaのインストール前に MeCab をインストールしてください。

2.13.2. ダウンロード

リリース版のソースコードを利用する場合は packages.groonga.org からtarballをダウンロードしてください。

最新のソースコードを利用する場合は GitHub からcloneして ./autogen.sh を実行してください。(GNU Autotoolsが必要です。)この方法は開発に慣れた方向けなので、そうでない方はtarballを使うことをお勧めします。:

% git clone https://github.com/mroonga/mroonga.git
% cd mroonga
% ./autogen.sh

2.13.3. 前提条件

MySQLおよびgroongaが既にインストールされている必要があります。

またmroongaをビルドするためにはMySQLのソースコードも必要です。

2.13.4. MySQLのインストール

MySQL 5.5最新版のソースコードをダウンロードし、ビルド&インストールして下さい。

http://dev.mysql.com/downloads/mysql/

mysql-5.5.22を使用し、以下にソースディレクトリが展開されているものと仮定します。

/usr/local/src/mysql-5.5.22

MySQLのバイナリが以下にインストールされているものと仮定します。

/usr/local/mysql

2.13.5. groongaのインストール

groongaの最新版をビルド&インストールして下さい。

http://groonga.org/ja/docs/

ここでは/usr/libなどの標準パスにlibgroongaがインストールされているものと仮定します。

2.13.6. mroongaのビルド

以下のように --with-mysql-source でMySQLソースコードディレクトリ、 --with-mysql-config でmysql_configコマンドのパスを指定してconfigureを実行します。

./configure \
  --with-mysql-source=/usr/local/src/mysql-5.5.22 \
  --with-mysql-config=/usr/local/mysql/bin/mysql_config

groongaを/usr/libなど標準のパス以外にインストールした場合はPKG_CONFIG_PATHを指定する必要があります。例えば、ーーprefix=$HOME/localでgroongaをインストールした場合は以下のようにします。:

./configure \
  PKG_CONFIG_PATH=$HOME/local/lib/pkgconfig \
  --with-mysql-source=/usr/local/src/mysql-5.5.22 \
  --with-mysql-config=/usr/local/mysql/bin/mysql_config

その後、"make"を実行します。

make

2.13.7. mroongaのインストール

"make install"を実行するとMySQLのプラグイン用ディレクトリにha_mroonga.soが配置されます。

make install

その後、mysqldを起動し、mysqlクライアントで接続して"INSTALL PLUGIN"コマンドでインストールします。

mysql> INSTALL PLUGIN mroonga SONAME 'ha_mroonga.so';

以下のように"SHOW ENGINES"コマンドで"mroonga"が表示されればmroongaのインストールは完了です。

mysql> SHOW ENGINES;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| mroonga    | YES     | Fulltext search, column base                               | NO           | NO   | NO         |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
6 rows in set (0.00 sec)

続いてUDF(ユーザ定義関数)をインストールします。

INSERTを行った際にgroongaにより割当てられるレコードIDを取得するためのlast_insert_grn_id関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME 'ha_mroonga.so';

スニペット(キーワード周辺のテキスト)を取得するために、mroonga_snippet関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION mroonga_snippet RETURNS STRING SONAME 'ha_mroonga.so';

mroongaからgroongaのクエリを実行するために、mroonga_command関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION mroonga_command RETURNS STRING SONAME 'ha_mroonga.so';

2.14. MariaDBにバンドルしたソースコードからのインストール

MariaDBにバンドルしてソースコードからインストールする方法を説明します。パッケージがない環境ではソースコードからインストールすることになります。

2.14.1. 形態素解析(MeCab)について

形態素単位でトークナイズした全文検索索引を使用したい場合は、groongaのインストール前に MeCab をインストールしてください。

2.14.2. ダウンロード

packages.groonga.org から、mroongaのtarballをダウンロードしてください。

downloads.mariadb.org から、MariaDBのtarballをダウンロードしてください。

2.14.3. 前提条件

groongaが既にインストールされている必要があります。

2.14.4. groongaのインストール

groongaの最新版をビルド&インストールして下さい。

http://groonga.org/ja/docs/

ここでは/usr/libなどの標準パスにlibgroongaがインストールされているものと仮定します。

2.14.5. MariaDBとmroongaのビルド

MariaDBのtarballの解凍。

tar xvfz ./mariadb-10.0.1.tar.gz

mroongaのtarballの解凍後、storageディレクトリへ移動。

tar xvfz ./mroonga-3.02.tar.gz
mv ./mroonga-3.02 ./mariadb-10.0.1/storage/

"cmake"を実行します。

cd mariadb-10.0.1
cmake .

その後、"make"を実行します。

make

2.14.6. MariDBとmroongaのインストール

"make install"を実行すると"usr/local/mysql"ディレクトリにMariaDBとmroongaが配置されます。

make install

その後、mysqldを起動し、MariaDBクライアントで接続して"INSTALL PLUGIN"コマンドでインストールします。

mysql> INSTALL PLUGIN mroonga SONAME 'ha_mroonga.so';

以下のように"SHOW ENGINES"コマンドで"mroonga"が表示されればmroongaのインストールは完了です。

mysql> SHOW ENGINES;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                         | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
| MyISAM             | DEFAULT | MyISAM storage engine                                      | NO           | NO   | NO         |
| MRG_MyISAM         | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| InnoDB             | NO      | Supports transactions, row-level locking, and foreign keys | NULL         | NULL | NULL       |
| mroonga            | YES     | CJK-ready fulltext search, column store                    | NO           | NO   | NO         |
| Aria               | YES     | Crash-safe tables with MyISAM heritage                     | NO           | NO   | NO         |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
8 rows in set (0.01 sec)

続いてUDF(ユーザ定義関数)をインストールします。

INSERTを行った際にgroongaにより割当てられるレコードIDを取得するためのlast_insert_grn_id関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME 'ha_mroonga.so';

スニペット(キーワード周辺のテキスト)を取得するために、mroonga_snippet関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION mroonga_snippet RETURNS STRING SONAME 'ha_mroonga.so';

mroongaからgroongaのクエリを実行するために、mroonga_command関数をインストールします。

以下のようにCREATE FUNCTIONを実行します。

mysql> CREATE FUNCTION mroonga_command RETURNS STRING SONAME 'ha_mroonga.so';