Installing Elasticsearch in AWS

Installing Elasticsearch is very well documented in the elastic.co site. I installed it in a t2 micro instance for testing purpose. I used the below commands to install it in Ubuntu 20.04.

#download the latest deb file
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-amd64.deb

#download the published checksum
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-amd64.deb.sha512

#check the shasum
shasum -a 512 -c elasticsearch-7.9.1-amd64.deb.sha512

#install
sudo dpkg -i elasticsearch-7.9.1-amd64.deb

After installing we need to start it as it does not start automatically. So to configure Elasticsearch to start automatically we have to run the following commands:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
#start the service
sudo systemctl start elasticsearch.service

To check the status of the service

sudo systemctl status elasticsearch.service

To stop the service

sudo systemctl stop elasticsearch.service

Since I was using a t2 micro which has only 1 GB RAM so the Elasticsearch could not be started. To fix it I used Swap memory. It is not available by default and also not recommended in EBS as it is slow however we can use it for testing purpose. Below are the command to create swap space:

#allocates 2GB for swap file
sudo fallocate -l 2G /swapfile
#permission to be only accessible to root
sudo chmod 600 /swapfile
#mark file as swap space
sudo mkswap /swapfile
#enable the swap file to be used by the system
sudo swapon /swapfile
#check if swap is available
sudo swapon --show
#make the swap file permanent by adding it to /etc/fstab
/swapfile swap swap defaults 0 0

While we have installed the Elasticsearch but we need an interface to manage it and the best tool available is Kibana. Follow this article to install Kibana in AWS and access it publicly.