環境
- Ubuntu server 16.04
- Elasticsearch 5.x
インストール
本家ドキュメント見ろって話ではあるが
そもそもElasticsearchにはJava 8の環境(JDK)が必要。UbuntuではOpen JDK(公式レポジトリで公開)とOracle JDK(PPA追加でインストール可)の2つがあり、今回は前者で入れる
apt install openjdk-8-jdk default-jdk
# JAVA_HOMEはupdate-alternatives --list javaで確認できる
echo JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 > /etc/profile.d/java.sh
これで再ログインするとjavaが使えるようになる
レポジトリの追加
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
apt update
apt install elasticsearch
必須ではないが、日本語を含めた検索にはkuromojiと呼ばれるプラグインが必要になるのでこの時点でインストールしておく
/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromoji
初期設定
インストール時点ではまだElasticsearchは起動していない。/etc/elasticsearch/elasticsearch.ymlを弄って最低限以下を修正する。
- cluster.name クラスタネーム 分かりやすい名前で
- node.name: ノードの名前 ホスト名と合わせると楽かも
- path.data: データの置く場所 /elasticsearchとか、どこでもいいが、パーミッションをelasticsearch:elasticsearchにする必要がある
- path.logs: ログの場所 /var/log/elasticsearchとか パーミッションをelasticsearch:elasticsearchにする必要がある
- network.host: 外部から参照する場合は
0.0.0.0
にする
後述するが、以下のオプションも追記しておくと吉
bootstrap.system_call_filter: false
http.cors.enabled: true
http.cors.allow-origin: "*"
起動
service elasticsearch start
node settings must not contain any index level settingsで起動できない
index系の設定をelasticsearch.ymlにかくと怒られる。Elasticsearch 2系の設定をそのまま流用しようとするとコケるので注意
java.lang.IllegalArgumentException: node settings must not contain any index level settings
node validation exceptionで起動できない
ログに以下のようなエラーが出て表示できない場合がある
[ERROR][o.e.b.Bootstrap ] [es1] node validation exception
c
max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
その時は /etc/security/limits.confに以下を追記
elasticsearch soft nproc 65536
elasticsearch hard nproc 65536
でさっきの/etc/elasticsearch/elasticsearch.ymlにbootstrap.system_call_filter: false
を追記したらいけた
head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
elasticsearch.ymlに以下を追記
http.cors.enabled: true
http.cors.allow-origin: *