表題の通り。Elasticsearchはまだほとんど触った事がないが、構築する必要があったのでAmazonLinux上に稼働させた。
■ 環境
- AmazonLinux
- Elasticsearch 1.4.4
- OracleJDK 1.7.0
■ はじめに
AmazonLinuxにはOpenJDKがインストールされているが、今回はそれを使用せずにOracleJDKを別途インストールしている環境で行う。OpenJDKは削除はしていないが、削除してしまう可能性もあるのでElasticsearchはRPMでインストールせずにバイナリ(tar.gz)をダウンロードして展開したものを使用することにした。
■ インストール
展開と配置だけである。
$ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.tar.gz
$ tar zxf elasticsearch-1.4.4.tar.gz
配置は”/opt”配下にしている。以前は”/usr/local”直下に配置していたのだが、FHS的にはどうやら”/opt”配下に配置するのが正しいようなので、そうするようにしている。結果、下記のような配置に。
$ cd /opt
$ ls -l
:
lrwxrwxrwx 1 root root 19 4月 4 19:27 elasticsearch -> elasticsearch-1.4.4
drwxrwxr-x 6 withsin withsin 4096 4月 4 19:24 elasticsearch-1.4.4
:
$
また、OracleJDK配下のbinディレクトリにはpathを通してある。”JAVA_HOME”も設定済みだ。
■ 設定ファイル
“/opt/elasticsearch/config/elasticsearch.yml”の内容は、MacにHomebrewでインストールした時の設定ファイルを参考にして編集した。今回はクラスタを組まずに1台だけで稼働させている。
$ vi /opt/elasticsearch/config/elasticsearch.yml
:
32 cluster.name: elasticsearch
:
163 path.logs: /opt/elasticsearch/logs
:
167 path.plugins: /opt/elasticsearch/plugins
:
203 network.bind_host: 0.0.0.0
:
208 network.publish_host: 192.168.30.10
:
$
編集した項目は上記の通り。設定したディレクトリは事前に作成しておく事にした。”bind_host”は、外部のどこからでも接続可能なように”0.0.0.0″としている。絞るのはEC2のSecurityGroupやELBで設定する。
■ 起動
RPMでインストールすれば起動スクリプトもインストールしてくれるだろうが、バイナリ配布のものにはなかったので、コマンドで起動する。
$ /opt/elasticsearch/bin/elasticsearch -d
デーモンとして起動させたかったので”-d”オプションを付けている。ログは下記に出力される。
$ /opt/elasticsearch/logs/elasticsearch.log
■ 稼働確認
プロセスを確認。
$ jps
21010 Elasticsearch
31762 Jps
$
ポートが開いているかを確認。
$ ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
:
LISTEN 0 50 :::9200 :::*
LISTEN 0 50 :::9300 :::*
:
$
curlでクラスタの情報を取得。
$ curl 'localhost:9200/_cat/nodes?v'
host ip heap.percent ram.percent load node.role master name
ip-192-168-30-10 192.168.30.10 3 21 0.00 d * Man Mountain Marko
$
稼働しているようである。
以上。
■ 関連
- Elasticsearch: RESTful, Distributed Search & Analytics | Elastic (公式)
- Getting Started > Exploring Your Cluster > Cluster Health