:>/dev/null

ラガードエンジニアの不撓不屈の精神/unlearning/go beyond

MySQL+groonga+mroonga構築手順

オンプレ環境でMySQL+groonga+mroonga構成を検証する機会があり、Versionは古いが知見として作業記録メモを残す。
MySQLからgroongaをストレージエンジンとして利用する場合、mroonga plugin(MySQL組込)を使用するが直接利用するケースとの違いを参考資料として共有。

  • 以下構築要件
    • OS:CentOS6.9 x86_84
    • MySQL:5.1.60
    • groonga:2.1.0
    • mroonga:2.1.0

■ 前提

MYSQLからgroongaをストレージエンジンとして使用する場合、下記パターンがあります。

① MySQLからmroongaプラグイン経由(MySQL組込)で利用する場合  
INSTALL PLUGIN groonga SONAME 'ha_mroonga.so';
mysql> show engines; →「mroonga」が表示
テーブルスキーマで「ENGINE=mroonga」指定

② MySQLから直接groongaを利用する場合
INSTALL PLUGIN groonga SONAME 'ha_groonga.so';
mysql> show engines; →「groonga」が表示
テーブルスキーマで「ENGINE=groonga」指定

Mroonga(Groonga)ストレージエンジンでのバックアップに関して

Groonga族のMroongaでのバックアップは、それぞれのRDBMSの仕組みに乗るのがよい。それぞれトランザクションレプリケーションがある。
また、MySQLの場合、InnoDBレプリケーション先としてMroongaを選ぶことができる。こうすると、(データが守られやすい)InnoDBをマスターデータとして考えることができる。

上記記載からInnoDB同様の扱いで問題ないとの認識

ref)
https://diary.kitaitimakoto.net/2016/01/15.html

■ インストール&設定

● 必要な開発ツールインストール

# yum groupinstall "Development Tools"
# yum install openssl openssl-devel readline-devel zlib-devel curl-devel libyaml-devel flex libxml2-devel zlib-devel libpng-devel libjpeg-devel libXpm-devel freetype freetype-devel

MySQLのパッケージインストール

# wget https://downloads.mysql.com/archives/get/file/MySQL-client-5.1.60-1.glibc23.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/file/MySQL-devel-5.1.60-1.glibc23.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/file/MySQL-server-5.1.60-1.glibc23.x86_64.rpm
# wget https://downloads.mysql.com/archives/get/file/MySQL-shared-5.1.60-1.glibc23.x86_64.rpm
# rpm -ivh MySQL-*
# rpm -qa |grep mysql

※依存関係でエラーが発生した場合、既存のライブラリ削除

# yum remove mysql-libs

● groonga/mroonga インストール

# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.60.tar.gz
# tar zxvf mysql-5.1.60.tar.gz
# wget http://packages.groonga.org/source/groonga/groonga-2.1.0.tar.gz
# tar zxvf groonga-2.1.0.tar.gz
# cd groonga-2.1.0
# ./configure
# make
# make install
# groonga --version

# cd ..
# wget http://packages.groonga.org/source/mroonga/mroonga-2.10.tar.gz
# tar zxvf mroonga-2.10.tar.gz
# cd mroonga-2.10
# ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ --with-mysql-source=/usr/local/src/mysql-5.1.60 --with-mysql-config=/usr/bin/mysql_config
# make
# make install
# find / -name ha_mroonga.so

● /etc/my.cnf作成

# cp /usr/local/src/mysql-5.1.60/mysql-test/include/default_my.cnf /etc/my.cnf
# vi /etc/my.cnf
...任意内容にて作成...

# /etc/init.d/mysql restart

MySQLにpluginを組み込む

# mysql -uroot -p

mysql> INSTALL PLUGIN groonga SONAME 'ha_groonga.so';
mysql> INSTALL PLUGIN mroonga SONAME 'ha_mroonga.so';
mysql> SHOW engines; (Engineのリストに「mroonga」という項目が追加されていればインストール成功です。)

※UDF関数を登録します。
mysql> CREATE FUNCTION last_insert_grn_id RETURNS INTEGER SONAME 'ha_mroonga.so';
mysql> CREATE FUNCTION mroonga_snippet RETURNS STRING SONAME 'ha_mroonga.so';
mysql> CREATE FUNCTION mroonga_command RETURNS STRING SONAME 'ha_mroonga.so';

+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
...snip...
| groonga    | YES     | CJK-ready fulltext search, column store                        | NO           | NO   | NO         |
| mroonga    | YES     | CJK-ready fulltext search, column store                        | NO           | NO   | NO         |
...snip...
+------------+---------+----------------------------------------------------------------+--------------+------+------------+

※または下記で確認可能
# mroongaという行があれば期待通りです
$ mysql -uroot -p -e "SHOW PLUGINS"
+------------+----------+----------------+---------------+---------+
| Name       | Status   | Type           | Library       | License |
+------------+----------+----------------+---------------+---------+
...snip...
| mroonga    | ACTIVE   | STORAGE ENGINE | ha_mroonga.so | GPL     |
...snip...
+------------+----------+----------------+---------------+---------+

■ 障害対応

# /etc/init.d/mysql stop
Shutting down MySQL. ERROR! Manager of pid-file quit without updating file.

# 上記エラー発生しmysql停止が出来ない場合、groonga pluginが原因
$ mysql -uroot -p -e "SHOW PLUGINS"
+------------+----------+----------------+---------------+---------+
| Name       | Status   | Type           | Library       | License |
+------------+----------+----------------+---------------+---------+
...snip...
| groonga    | ACTIVE   | STORAGE ENGINE | ha_groonga.so | GPL     |
| mroonga    | ACTIVE   | STORAGE ENGINE | ha_mroonga.so | GPL     |
...snip...
+------------+----------+----------------+---------------+---------+

※不要なgroonga pluginを削減
mysql> UNINSTALL PLUGIN groonga;

これで起動/停止が正常稼働する。

参考)
stop時のエラーに関してはログ(***.err)に下記が記載される。

190708 12:14:43 [Note] Event Scheduler: Purging the queue. 0 events 190708 12:14:43 - mysqld got signal 11 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. We will try our best to scrape up some info that will hopefully help diagnose the problem, but since we have already crashed, something is definitely wrong and this may fail.

key_buffer_size=8384512 read_buffer_size=131072 max_used_connections=0 max_threads=151 threads_connected=0 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 338325 K bytes of memory Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... stack_bottom = (nil) thread_stack 0x40000 /usr/sbin/mysqld(my_print_stacktrace+0x2e)[0x852ebe] /usr/sbin/mysqld(handle_segfault+0x34c)[0x5c951c] /lib64/libpthread.so.0[0x374f00f7e0] /usr/local/lib/libgroonga.so.0(grn_io_segment_alloc+0x26)[0x7fd07bd1aa56] /usr/local/lib/libgroonga.so.0(grn_hash_get_value+0x20d)[0x7fd07bcea65d] /usr/local/lib/libgroonga.so.0(grn_plugin_close+0x35)[0x7fd07bd75dc5] /usr/local/lib/libgroonga.so.0(grn_obj_close+0x277)[0x7fd07bc5b0f7] /usr/local/lib/libgroonga.so.0(grn_db_close+0xe1)[0x7fd07bc5acc1] /usr/local/lib/libgroonga.so.0(grn_obj_close+0x19c)[0x7fd07bc5b01c] /usr/lib64/mysql/plugin/ha_groonga.so(+0x181de)[0x7fd0802b01de] /usr/sbin/mysqld(Z22ha_finalize_handlertonP13st_plugin_int+0x74)[0x6a0784] /usr/sbin/mysqld[0x71b482] /usr/sbin/mysqld[0x71cd5e] /usr/sbin/mysqld(Z15plugin_shutdownv+0x12a)[0x71d21a] /usr/sbin/mysqld[0x5c990c] /usr/sbin/mysqld(_Z10unireg_endv+0xe)[0x5c9b7e] /usr/sbin/mysqld(kill_server_thread+0x31d)[0x5cbc3d] /lib64/libpthread.so.0[0x374f007aa1] /lib64/libc.so.6(clone+0x6d)[0x374ece8bcd] The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash.

ref)
mroomga pluginに関して
http://y-ken.hatenablog.com/entry/mroonga-create-function