<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>4.2. リモートアクセス — groonga v3.0.5ドキュメント</title> <link rel="stylesheet" href="../_static/groonga.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '3.0.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/translations.js"></script> <link rel="shortcut icon" href="../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5ドキュメント" href="../index.html" /> <link rel="up" title="4. チュートリアル" href="../tutorial.html" /> <link rel="next" title="4.3. いろいろなデータの保存" href="data.html" /> <link rel="prev" title="4.1. 基本的な操作" href="introduction.html" /> </head> <body> <div class="header"> <h1 class="title"> <a id="top-link" href="../index.html"> <span class="project">groonga</span> <span class="separator">-</span> <span class="description">オープンソースのカラムストア機能付き全文検索エンジン</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../en/html/tutorial/network.html"><img src="../_static/us.png" alt="English">English page</a></li> </ul> </div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" accesskey="I">索引</a></li> <li class="right" > <a href="data.html" title="4.3. いろいろなデータの保存" accesskey="N">次へ</a> |</li> <li class="right" > <a href="introduction.html" title="4.1. 基本的な操作" accesskey="P">前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../tutorial.html" accesskey="U">4. チュートリアル</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="remote-access"> <h1>4.2. リモートアクセス<a class="headerlink" href="#remote-access" title="このヘッドラインへのパーマリンク">¶</a></h1> <p>groongaをサーバとして起動することにより、ネットワークを介してデータベースにアクセスできるようになります。groongaがサポートしているプロトコルは、groongaの専用プロトコルであるgqtp、memcachedバイナリプロトコル、HTTPの三種類です。</p> <div class="section" id="groonga-query-transfer-protocol-gqtp"> <h2>4.2.1. groonga専用プロトコル(gqtp)<a class="headerlink" href="#groonga-query-transfer-protocol-gqtp" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="how-to-run-a-gqtp-server"> <h3>4.2.1.1. gqtpサーバの起動<a class="headerlink" href="#how-to-run-a-gqtp-server" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>groongaには、専用のプロトコルであるgqtpが存在します。gqtpを用いることにより、データベースへとリモートアクセスすることができます。以下の書式はgqtpサーバの起動方法を示しています。</p> <p>書式:</p> <div class="highlight-none"><div class="highlight"><pre>groonga [-p PORT_NUMBER] -s DB_PATH </pre></div> </div> <p><cite>-s</cite> オプションはgroongaをサーバとして起動するためのオプションです。DB_PATHには既存のデータベースのパスを指定します。 <cite>-p</cite> オプションとその引数により、サーバのポート番号を指定することができます。ポート番号を省略した場合は10041が使用されます。</p> <p>以下のコマンドにより、デフォルトのポート番号で待ち受けるサーバを起動することができます。サーバは指定されたデータベースへの操作を受け付けます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>% groonga -s /tmp/groonga-databases/introduction.db Ctrl-c % </pre></div> </div> </div> <div class="section" id="how-to-run-a-gqtp-daemon"> <h3>4.2.1.2. gqtpデーモンの起動<a class="headerlink" href="#how-to-run-a-gqtp-daemon" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>gqtpサーバはデーモンとして起動することができます。オプションとして、 <cite>-s</cite> の代わりに <cite>-d</cite> を与えてください。</p> <p>書式:</p> <div class="highlight-none"><div class="highlight"><pre>groonga [-p PORT_NUMBER] -d DB_PATH </pre></div> </div> <p>groongaをデーモンとして起動したときは、デーモンのプロセスIDが表示されます。以下の例では、12345というプロセスIDが表示されています。サーバとして起動した場合と同様に、指定されたデータベースへの操作を受け付けます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>% groonga -d /tmp/groonga-databases/introduction.db 12345 % </pre></div> </div> </div> <div class="section" id="how-to-run-a-gqtp-client"> <h3>4.2.1.3. gqtpサーバへの接続<a class="headerlink" href="#how-to-run-a-gqtp-client" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>gqtpサーバに接続するクライアントは、以下のように起動します。</p> <p>書式:</p> <div class="highlight-none"><div class="highlight"><pre>groonga [-p PORT_NUMBER] -c [HOST_NAME_OR_IP_ADDRESS] </pre></div> </div> <p>上記のコマンドによって起動されたクライアントは、サーバとの接続に成功すると対話モードに入ります。HOST_NAME_OR_IP_ADDRESSにはサーバのホスト名もしくはIPアドレスを指定します。HOST_NAME_OR_IP_ADDRESSが省略されたときは"localhost"をサーバのホスト名として採用します。また、 <cite>-p</cite> オプションとその引数により、サーバのポート番号を指定することができます。ポート番号を省略した場合は10041が使用されます。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>% groonga -c status # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # { # "uptime": 0, # "max_command_version": 2, # "n_queries": 0, # "cache_hit_rate": 0.0, # "version": "3.0.5", # "alloc_count": 136, # "command_version": 1, # "starttime": 1372040831, # "default_command_version": 1 # } # ] > ctrl-d % </pre></div> </div> <p>対話モードでは、標準入力からコマンドを読み込んで順次実行します。</p> </div> <div class="section" id="how-to-terminate-a-gqtp-server"> <h3>4.2.1.4. gqtpサーバの終了<a class="headerlink" href="#how-to-terminate-a-gqtp-server" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>gqtpサーバを終了する安全は方法は、クライアントを起動して <a class="reference internal" href="../reference/commands/shutdown.html"><em>shutdown</em></a> を発行することです。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>% groonga -c > shutdown % </pre></div> </div> </div> </div> <div class="section" id="memcached-binary-protocol"> <h2>4.2.2. memcachedバイナリプロトコル<a class="headerlink" href="#memcached-binary-protocol" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaはmemcachedバイナリプロトコルをサポートしています。以下の書式はmemcachedバイナリプロトコルのサーバをデーモンとして起動する方法を示しています。</p> <p>書式:</p> <div class="highlight-none"><div class="highlight"><pre>groonga [-p PORT_NUMBER] -d --protocol memcached DB_PATH </pre></div> </div> <p><cite>--protocol</cite> オプションとその引数により、サーバのプロトコルを指定することができます。"memcached"はmemcachedバイナリプロトコルを示しています。</p> </div> <div class="section" id="hypertext-transfer-protocol-http"> <h2>4.2.3. HTTP<a class="headerlink" href="#hypertext-transfer-protocol-http" title="このヘッドラインへのパーマリンク">¶</a></h2> <div class="section" id="how-to-run-an-http-server"> <h3>4.2.3.1. HTTPサーバの起動<a class="headerlink" href="#how-to-run-an-http-server" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>groongaはHTTPをサポートしています。以下の書式はHTTPサーバをデーモンとして起動する方法を示しています。</p> <p>書式:</p> <div class="highlight-none"><div class="highlight"><pre>groonga [-p PORT_NUMBER] -d --protocol http DB_PATH </pre></div> </div> <p><cite>--protocol</cite> オプションとその引数により、サーバのプロトコルを指定することができます。"http"はHTTPサーバの起動を指示しています。</p> <p>以下のコマンドは、ポート番号80で待ち受けるHTTPサーバをデーモンとして起動します。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>% sudo groonga -p 80 -d --protocol http /tmp/groonga-databases/introduction.db % </pre></div> </div> <div class="admonition note"> <p class="first admonition-title">ノート</p> <p class="last">80番ポートで待ち受けるにはroot権限が必須です。1024番以降のポート番号にはそのような制限はありません。</p> </div> </div> <div class="section" id="how-to-send-a-command-to-an-http-server"> <h3>4.2.3.2. HTTPサーバへのコマンド送信<a class="headerlink" href="#how-to-send-a-command-to-an-http-server" title="このヘッドラインへのパーマリンク">¶</a></h3> <p>groongaがHTTPサーバとして起動されているときは、/d/COMMAND_NAME というURLにアクセスすることにより、コマンドを実行することができます。コマンドの引数は、HTTPのGETパラメータとして渡します。引数の書式は "?NAME_1=VALUE_1&NAME_2=VALUE_2&..." となります。</p> <p>以下の例は、HTTPサーバに対するコマンドの送り方を示しています。</p> <p>実行例:</p> <div class="highlight-none"><div class="highlight"><pre>http://HOST_NAME_OR_IP_ADDRESS[:PORT_NUMBER]/d/status Executed command: status # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # { # "uptime": 0, # "max_command_version": 2, # "n_queries": 0, # "cache_hit_rate": 0.0, # "version": "3.0.5", # "alloc_count": 137, # "command_version": 1, # "starttime": 1372040831, # "default_command_version": 1 # } # ] http://HOST_NAME_OR_IP_ADDRESS[:PORT_NUMBER]/d/select?table=Site&query=title:@this Executed command: select --table Site --query title:@this # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "_id", # "UInt32" # ], # [ # "_key", # "ShortText" # ], # [ # "country", # "SiteCountry" # ], # [ # "domain", # "SiteDomain" # ], # [ # "link", # "Site" # ], # [ # "links", # "Site" # ], # [ # "location", # "WGS84GeoPoint" # ], # [ # "title", # "ShortText" # ] # ], # [ # 1, # "http://example.org/", # "japan", # ".org", # "http://example.net/", # [ # "http://example.net/", # "http://example.org/", # "http://example.com/" # ], # "128452975x503157902", # "This is test record 1!" # ] # ] # ] # ] </pre></div> </div> </div> </div> <div class="section" id="administration-tool-http"> <h2>4.2.4. ブラウザベースの管理ツール<a class="headerlink" href="#administration-tool-http" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaをHTTPサーバとして起動しているときは、ブラウザベースの管理ツールを使うことにより、データベースを簡単に管理することができます。管理ツールを使いたいときは、ブラウザを使って <a class="reference external" href="http://HOST_NAME_OR_IP_ADDRESS[:PORT_NUMBER]/">http://HOST_NAME_OR_IP_ADDRESS[:PORT_NUMBER]/</a> へとアクセスしてください。管理ツールの使用には、JavaScriptの実行が有効になっている必要があります。</p> </div> <div class="section" id="security-issues"> <h2>4.2.5. セキュリティ<a class="headerlink" href="#security-issues" title="このヘッドラインへのパーマリンク">¶</a></h2> <p>groongaのサーバには認証機能がありません。誰でもデータベースの内容を閲覧・修正することができます。iptablesなどを用いてアクセス元IPアドレスを制限することを推奨します。</p> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">目次</a></h3> <ul> <li><a class="reference internal" href="#">4.2. リモートアクセス</a><ul> <li><a class="reference internal" href="#groonga-query-transfer-protocol-gqtp">4.2.1. groonga専用プロトコル(gqtp)</a><ul> <li><a class="reference internal" href="#how-to-run-a-gqtp-server">4.2.1.1. gqtpサーバの起動</a></li> <li><a class="reference internal" href="#how-to-run-a-gqtp-daemon">4.2.1.2. gqtpデーモンの起動</a></li> <li><a class="reference internal" href="#how-to-run-a-gqtp-client">4.2.1.3. gqtpサーバへの接続</a></li> <li><a class="reference internal" href="#how-to-terminate-a-gqtp-server">4.2.1.4. gqtpサーバの終了</a></li> </ul> </li> <li><a class="reference internal" href="#memcached-binary-protocol">4.2.2. memcachedバイナリプロトコル</a></li> <li><a class="reference internal" href="#hypertext-transfer-protocol-http">4.2.3. HTTP</a><ul> <li><a class="reference internal" href="#how-to-run-an-http-server">4.2.3.1. HTTPサーバの起動</a></li> <li><a class="reference internal" href="#how-to-send-a-command-to-an-http-server">4.2.3.2. HTTPサーバへのコマンド送信</a></li> </ul> </li> <li><a class="reference internal" href="#administration-tool-http">4.2.4. ブラウザベースの管理ツール</a></li> <li><a class="reference internal" href="#security-issues">4.2.5. セキュリティ</a></li> </ul> </li> </ul> <h4>前のトピックへ</h4> <p class="topless"><a href="introduction.html" title="前の章へ">4.1. 基本的な操作</a></p> <h4>次のトピックへ</h4> <p class="topless"><a href="data.html" title="次の章へ">4.3. いろいろなデータの保存</a></p> <h3>このページ</h3> <ul class="this-page-menu"> <li><a href="../_sources/tutorial/network.txt" rel="nofollow">ソースコードを表示</a></li> </ul> <div id="searchbox" style="display: none"> <h3>クイック検索</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="検索" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> モジュール、クラス、または関数名を入力してください </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>ナビゲーション</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="総合索引" >索引</a></li> <li class="right" > <a href="data.html" title="4.3. いろいろなデータの保存" >次へ</a> |</li> <li class="right" > <a href="introduction.html" title="4.1. 基本的な操作" >前へ</a> |</li> <li><a href="../index.html">groonga v3.0.5ドキュメント</a> »</li> <li><a href="../tutorial.html" >4. チュートリアル</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>