How to install Elasticsearch on EC2 with Amazon Linux

This is largely a brain dump since I spent some time trying to get elasticsearch working for EC2.


Creating the Instance

  1. Create an IAM role with the needed credentials for the elasticsearch aws plugin. For now, I didn’t mess with setting up the fine grained policy and just opted for ‘power-user’. A good follow up would be to share a default policy that we can send as a pull-request to the plugin Github.
  2. Create a security group which has at least port 22, 80, 2003 and 2004 open. I’m not sure the complete difference between 2003 and 2004.
  3. Launch the instance!

Installing Elasticsearch

  1. I opt-ed to install Elasticsearch via the RPM because it includes a chkconfig script to start Elasticsearch as a service. You can download the rpm here. Do not turn it on yet!
  2. In the installed directory (/usr/share/elasticsearch for RPM) run the following command: bin/plugin -install elasticsearch/elasticsearch-cloud-aws/2.1.0

Configuring Elasticsaerch

Within the configuration file (/etc/elasticsearch/elasticsearch.yml) perform the following modifications:

  1. pick-a-cluster-name
  2. discovery.type: ec2
  3. discovery.ec2.host_type: public_ip
  4. discovery.ec2.groups:
  5. discovery.ec2.ping_timeout: 5m

The security group option is important otherwise the plugin will cause Elasticsearch to try and discover all hosts within that region and fail if they do not have elasticsearch. Limiting the search to only instances with the specified security group will fix that!


sudo service elasticsearch start

2 Replies to “How to install Elasticsearch on EC2 with Amazon Linux”

  1. It’s worth noting that, if you fololw their advice of rebooting your instances manually, the scheduled event icon doesn’t go away immediately. In fact, I’ve been waiting a few hours now and it’s still there on an instance I rebooted manually. AWS EC2 forums are awash with people waiting >24 hours for it the disappear, believing that it won’t and AWS will reboot it again. Which of course is annoying a few people who have to manually intervene with their instances when they don’t come back up on their own.

Leave a Reply

Your email address will not be published. Required fields are marked *