Elasticsearch installation issue on a free tier (t2.micro) AWS EC2 instance

aws, elasticsearch, troubleshooting


title: Elasticsearch installation issue on a free tier (t2.micro) AWS EC2 instance date: "2018-01-25" banner: ./images/featured-image-2.jpg published_at: "2018-01-26T02:31:29.000Z" tags: "aws, elasticsearch, troubleshooting" author: Sung M. Kim

I installed Elasticsearch 6.x on a free tier AWS EC2 instance type, t2.micro by following installation instruction (for Elasticsearch 5) by Adnan Sabanovic on medium.

Adnan used a cURL command to check if Elasticsearch is running or not.

curl –XGET "http://localhost:9200"
view raw curl.sh hosted with ❤ by GitHub

But then the command returned the following error message.

curl: (7) Failed to connect to localhost port 9200: Connection refused

What happened?


Let's see the status of Elasticsearch by running systemctl comamnd.

root@ip-xxx:/etc/elasticsearch# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2018-01-26 01:25:00 UTC; 7s ago
Docs: http://www.elastic.co
Process: 11163 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=1/FA Main PID: 11163 (code=exited, status=1/FAILURE)
Jan 26 01:24:59 ip-xxx systemd[1]: Started Elasticsearch.
Jan 26 01:25:00 ip-xxx elasticsearch[11163]: OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 98Jan 26 01:25:00 ip-xxx elasticsearch[11163]: #
Jan 26 01:25:00 ip-xxx systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Jan 26 01:25:00 ip-xxx systemd[1]: elasticsearch.service: Unit entered failed state.
Jan 26 01:25:00 ip-xxx systemd[1]: elasticsearch.service: Failed with result 'exit-code'.

On line #9, you can see the warning "OpenJDK 64-Bit Server VM warning" and the line #10 shows that the Elasticsearch service main process has existed right away.

Updating Elasticsearch 6.x JVM Heap Size

By default Elasticsearch 6.x JVM Heap size set to use minimum 1Gig of memory.

t2.micro has 1Gig of memory

but Elasticsearch documentation recommends to set it to 50% of physical memory for kernel file system caches.

We know the problem, so let's change the Elasticsearch JVM heap size.

Open /etc/elasticsearch/jvm.option using an editor of your choice (I promise that I will learn either vi or emacs... 😞).

sudo nano /etc/elasticsearch/jvm.options
view raw sudo nano.sh hosted with ❤ by GitHub

When you read the comment in jvm.options, you should set the minimum and maximum to the same value.

And you can see that the min and max JVM heap sizes are set to 1g on the bottom of above image.



Now update the min and max values to 512m, save the file and exit.

Restart and Test

Restart Elasticsearch service,

sudo /etc/init.d/elasticsearch restart
view raw gistfile1.txt hosted with ❤ by GitHub

and run the cURL command again.

🎉Tada 🎉, Elasticsearch is now running on AWS EC2 t.micro instance.