2018-01-25

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

aws, elasticsearch, troubleshooting

banner

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.

https://gist.github.com/dance2die/3dff7c0c45c8fb6e18f3b73a4dbcd316

But then the command returned the following error message.

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

What happened?

Diagnosis

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

https://gist.github.com/dance2die/b7e815a3a4e3be3f46dbc92299e7d1c7

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... 😞).

https://gist.github.com/dance2die/f54076253a6aa402d7fa2ebffa8d2d5d

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.

-Xms1g

-Xmx1g

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

Restart and Test

Restart Elasticsearch service,

https://gist.github.com/dance2die/3db44a114a46b8dfa252027f4e1f9a11

and run the cURL command again.

πŸŽ‰Tada πŸŽ‰, Elasticsearch is now running on AWS EC2 t.micro instance.