groonga - オープンソースのカラムストア機能付き全文検索エンジン

8.1.4. groonga-httpd

8.1.4.1. 概要

groonga-httpdはgroongaサーバーとHTTPプロトコルで通信するプログラムです。 機能的には、 groonga HTTPサーバー と同じです。 groonga HTTPサーバー はHTTPサーバーとしては最小限の機能しか持ちませんが、groonga-httpdは nginx を組み込むことでnginxが準拠しているHTTPの仕様と機能をすべて利用できます。

groonga-httpdにはHTML + JavaScriptで実装された管理ツールが標準で付属しています。ウェブブラウザでhttp://hostname:port/にアクセスすると、管理ツールを利用できます。

8.1.4.2. 書式

groonga-httpd [nginx options]

8.1.4.3. 使い方

8.1.4.3.1. 設定をする

まずは、データベースを指定するためにgroonga-httpdの設定ファイルを編集する必要があります。次のように/etc/groonga/httpd/groonga-httpd.confを編集して groonga_database ディレクティブを有効にしてます。

# Match this to the file owner of groonga database files if groonga-httpd is
# run as root.
#user groonga;
...
http {
  ...
  # Don't change the location; currently only /d/ is supported.
  location /d/ {
    groonga on; # <= This means to turn on groonga-httpd.

    # Specify an actual database and enable this.
    groonga_database /var/lib/groonga/db/db;
  }
  ...
}

次に、groonga-httpdを実行してください。すぐにターミナルに制御が戻ってきます。これはgroonga-httpdはデフォルトでデーモンプロセスになるからです。

% groonga-httpd

8.1.4.3.2. クエリーを実行する

動作を確認するため、簡単なクエリー( status )をリクエストしてみます。

実行例:

% curl http://localhost:10041/d/status
[
  [
    0,
    1337566253.89858,
    0.000355720520019531
  ],
  {
    "uptime": 1,
    "max_command_version": 2,
    "n_queries": 0,
    "cache_hit_rate": 0.0,
    "version": "2.0.5",
    "alloc_count": 142,
    "command_version": 1,
    "starttime": 1343713471,
    "default_command_version": 1
  }
]

8.1.4.3.3. 管理ツールを使う

補足ですが、 http://localhost:10041/ にアクセスすると管理ツールを利用できます。

8.1.4.3.4. 終了する

最後に、次のコマンドで動作中のgroonga-httpdデーモンを終了できます。

% groonga-httpd -s stop

8.1.4.4. 設定ディレクティブ

このセクションでは重要なディレクティブのみ説明します。重要なディレクティブとはgroonga-http特有のディレクティブと性能に関するディレクティブです。

以下のディレクティブはgroonga-httpdの設定ファイル中で使用することができます。デフォルトでは、設定ファイルは/etc/groonga/httpd/groonga-httpd.confに置かれています。

8.1.4.4.1. groonga-httpd特有のディレクティブ

以下のディレクティブはnginxが提供しているものではなく、groonga-httpd関連の設定をするためにgroonga-httpdが提供しているディレクティブです。

8.1.4.4.1.1. groonga

書式:

groonga on | off;
Default
groonga off;
Context
location

この location ブロックでgroongaを使うかどうかを指定します。デフォルトは off です。groongaを使うためには on を指定してください。

例:

location /d/ {
  groonga on;  # Enables groonga under /d/... path
}

location /d/ {
  groonga off; # Disables groonga under /d/... path
}

8.1.4.4.1.2. groonga_database

書式:

groonga_database /path/to/groonga/database;
Default
groonga_database /usr/local/var/lib/groonga/db/db;
Context
http, server, location

groongaデータベースのパスを指定します。このディレクティブは必須です。

8.1.4.4.1.3. groonga_base_path

書式:

groonga_base_path /d/;
Default
location の名前と同じ値。
Context
location

URIのベースパスを指定します。groongaは command を実行するために /d/command?parameter1=value1&... というパスを使います。groonga-httpdでもこのパスの形式を使いますが、groonga-httpdは /other-prefix/command?parameter1=value1&... というように /d/ ではなく別のプレフィックスを使った形式もサポートしています。この別の形式もサポートするために、groonga-httpdはリクエストURIの先頭からベースパスを削除し、先頭に /d/ を追加します。このパスの変換をすることにより、ユーザーはプレフィックスをカスタムできるようになりますが、groongaは常に /d/command?parameter1=value1&... という形式で処理できます。

通常、このディレクティブを使う必要はありません。このディレクティブはコマンド毎に設定をしたい場合に使います。

以下は shutdown コマンドに認証をかける設定例です。:

groonga_database /var/lib/groonga/db/db;

location /d/shutdown {
  groonga on;
  # groonga_base_path is needed.
  # Because /d/shutdown is handled as the base path.
  # Without this configuration, /d/shutdown/shutdown path is required
  # to run shutdown command.
  groonga_base_path /d/;
  auth_basic           "manager is required!";
  auth_basic_user_file "/etc/managers.htpasswd";
}

location /d/ {
  groonga on;
  # groonga_base_path doesn't needed.
  # Because location name is the base path.
}

8.1.4.5. 利用可能なnginxモジュール

全てのHTTPの標準モジュールが利用可能です。PCRE(Perl Compatible Regular Expressions)がない場合はHttpRewriteModuleは無効になります。標準モジュールの一覧は、 http://wiki.nginx.org/Modules を参照してください。