【Elasticsearch】error='Cannot allocate memory'
概要
ローカルマシン上の仮想環境でElasticsearchを構築しようとしたら起動できず、以下のようなエラーに遭遇してしまいました。
# systemctl status elasticsearch -l arallel GC threads appropriately using -XX:ParallelGCThreads=N Jul 07 16:11:26 poc elasticsearch[1334]: OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
原因
Elasticsearchを使っている仮想環境のメモリが1GBだったので、
メモリ不足の問題で起動できない状態でした。
対応
使用する最低限のヒープサイズを設定するために
以下の設定を追加し、Elasticsearchを再起動したら解決しました。
- /etc/elasticsearch/elasticsearch.yml
メモリサイズの固定
# Lock the memory on startup: # bootstrap.memory_lock: true
- /etc/init.d/elasticsearch
固定されるヒープサイズの指定
# export unsupported variables so bin/elasticsearch can reject them and inform the user these are unsupported if test -n "$ES_MIN_MEM"; then export ES_MIN_MEM; fi if test -n "$ES_MAX_MEM"; then export ES_MAX_MEM; fi if test -n "$ES_HEAP_SIZE"; then export ES_HEAP_SIZE=512m; fi
# Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms512m -Xmx512m
参考サイト
http://knowledge.sakura.ad.jp/tech/2736/