2012年6月7日木曜日

mroongaをインストール

どうも、俺@残業中です。
今日はMySQLの全文検索エンジンmroonga(v2.03)をインストールする方法をメモメモ。
超簡単です。
公式サイトはこちら

MySQL(v5.5.25)はインストール済みとします。(今度こっちのインストール方法もメモメモしとかな)

まずはgroongaインストール。(yumインストール)
# rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-0.noarch.rpm
# yum install groonga-devel

ちなみにgroongaをソースからインストールする場合は
# yum install mecab-devel
しておいて

# wget http://packages.groonga.org/source/groonga/groonga-2.0.3.tar.gz
# tar zxvf groonga-2.0.3.tar.gz
# cd groonga-2.0.3
# ./configure
# make -j$(grep '^processor' /proc/cpuinfo | wc -l)
# mak install
とします。
※未検証です。ここを参考にしてみてください。



次に辞書をインストール。(MeCabの辞書)ソースインストールした場合はmecab-develの中に入ってるかも?

# yum install mecab-ipadic

ここまででとりあえずgroongaはインストールされました。
/usr/lib以下にgroongaというディレクトリが出来てると思います。




いよいよmroongaインストール。

# wget 'https://github.com/downloads/mroonga/mroonga/mroonga-2.03.ta.gz'
# tar zxvf mroonga-2.03.ta.gz
# cd mroonga-2.03



configureしてmakeしてmake installします。

# ./configure --with-mysql-source=/path/to/mysql --with-mysql-config=/path/to/mysql/bin/mysql_config --with-default-parser=TokenMecab
# make
# make install
これでMySQLのプラグインディレクトリ以下にha_mroonga.soが生成されます。
例)/usr/local/mysql-5.5.25/lib/plugin/ha_groonga.so



mysqldを起動または再起動してmysqlにログインします。

# /path/to/mysql/bin/mysql
mysql> INSTALL PLUGIN mroonga SONAME 'ha_mroonga.so';
mysql> SHOW ENGINES;

+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| CSV                | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                         | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                      | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
| mroonga            | YES     | CJK-ready fulltext search, column store                    | NO           | NO   | NO         |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
7 rows in set (0.02 sec)
Yes!インストールでけた!


あとはCREATE TABLEする時に

 ENGINE=mroonga;
をつけてね!






以上でぇぇぇえぇす。

2012年6月3日日曜日

log4jsを使う

どうも、俺@自主勉中です。

今日はjavasscript(今回はNode.js利用)でシステム構築するときにとても便利なlog4jsの紹介です。

インストールはnpmで

$ npm -g install log4js

使い方は
var log4js = require(‘log4js’);
// 設定
log4js.configure({
  appenders: [
    { type: ‘console’, category: ‘console’ },
    { type: ‘file’, filename: ‘logs/access_log’, category: ‘access_log’, backups: 30, maxLogSize: 1024 * 1024 }
  ]
});

var consoleLog = log4js.getLogger(‘console’)
  ,accessLog = log4js.getLogger(‘access_log’);
consoleLog.info(’Server Start.');
accessLog.info(‘This is test(access_log)’);
こんな感じです。
configure()で指定した
backupsはファイルの世代数、maxLogSizeはファイルをローテートする時の最大ファイルサイズ(単位:byte)です。

ログの出力は
  1. trace()
  2. debug()
  3. info()
  4. warn()
  5. error()
  6. fatal()
とあります。
ログレベルは

var logger = log4js.getLogger(‘access_log’).setLevel(‘ERROR’);
のように指定することも可能です。

ちなみにNode.jsが標準出力するログは、上記の

{ type: ‘console’, category: ‘console’ }
で指定してあり、Node起動時に

$ node app.js >> logs/node.log
とかすれば良いです。
、、こうしないとNode.jsが吐き出すログをファイルに書き出せないです。

誰かその原因知っている人いたら教えて欲しいです。



以上でぇぇぇぇぇす。