DEV Community

Cover image for Installing and configuring ElasticSearch on a VM
Kanisk
Kanisk

Posted on

Installing and configuring ElasticSearch on a VM

For this guide, we will setup a virtual Ubuntu Server environment in order to best simulate the conditions of working with ElasticSearch in the real world, which would be primarily a cloud or containerized environment.

We will utilize the terminal and I'll walk you through the steps and clarify as we go along!

Things you will need:

Setting up the VM

This part is fairly straightforward and visual in nature, and if not, there are plenty of Youtube videos and guides on how to create and setup your own VirtualBox VM. Regardless, I'll try to give you the core steps here so you don't have to navigate elsewhere as you follow through!

First, make sure you've downloaded all the above components, and installed VirtualBox. I'll be doing this on a Mac system, but the process should be fairly similar on any other OS.

Once that is done, create a new VM:
Screen Shot 2020-11-16 at 5.59.08 AM

  • Click on New and follow the instructions within the prompts, and feel free to customize the name and installation directory as necessary
  • From the drop-down, make sure to select Ubuntu (64 bit)
  • Allocate memory size close to half of your total current system
  • Create a virtual hard disk (VDI) and configure at least 20 GB of space

Once that's done, you will see the VM show up in the main screen, and you can simply select the VM, and click the green Start button to kick things off.

Screen Shot 2020-11-16 at 6.06.10 AM

Immediately after, you will be asked to Select a start-up disk. This is where you want to click the folder icon and navigate to where your Ubuntu Server .iso file is and confirm the prompt.

Instaling Ubuntu Server

This process is akin to sticking an installation disk/bootable USB to install any OS, so you'll have a nice guided prompt which will look something like this:

Screen Shot 2020-11-16 at 6.20.48 AM

I won't cover this in depth since this is also fairly straightforward, but will highlight specific things you will/won't need:

  • you won't need a proxy config (unless you're on your work machine which is behind a proxy)
  • Use the default mirror for ubuntu
  • Use the entire disk for the Filesystem setup and confirm the "destructive action" prompt (it's a VM so we're at no risk of messing up any of our local data)
  • Setup your profile with your name, server name etc.
  • When the prompt asks for SSH setup, make sure to check [x] Install Open SSH server
  • You won't need any featured server snaps since we're installing stuff manually

And that should be all for this step. Once the process is complete it'll ask for a reboot which will then bring you to your VM with Ubuntu Server starting up.

Installing ElasticSearch

First, we import the ElasticSearch GPG key since they sign all their packages with the following signing key (PGP key D88E42B4, available from https://pgp.mit.edu).

To do so, use

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode

Screen Shot 2020-11-16 at 6.36.36 AM

Next, we need to run

sudo apt-get install apt-transport-https
Enter fullscreen mode Exit fullscreen mode

in order to grab the apt-transport-https package for downloading content via the HTTP Secure protocol (HTTPS).

We then echo the repository definition which is piped and saved to /etc/apt/sources.list.d/elastic-7.x.list using a tee command:

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
Enter fullscreen mode Exit fullscreen mode

And finally, we update and grab the elasticsearch package

sudo apt-get update && sudo apt-get install elasticsearch
Enter fullscreen mode Exit fullscreen mode

Configuring our new Elastic installation

Once the installation is complete, we can quickly configure it by using vi

sudo vi /etc/elasticsearch/elasticsearch.yml
Enter fullscreen mode Exit fullscreen mode

This will open up the config file where we will change/uncomment the following params (make sure you're in insert mode in vi):

  • uncomment node.name and optionally edit the name
  • uncomment network.host and edit it to point to 0.0.0.0
  • uncomment discovery.seed_hosts and edit it to ["127.0.0.1"]
  • uncomment cluster.initial_master_nodes and edit it to match the same name as your node.name, e.g. if my node.name was the default node-1, then this field should have value ["node-1"]

Hit Esc to get out of insert mode and type :wq to save our changes and exit vi.

Screen Shot 2020-11-16 at 7.28.08 AM

Optionally (auto-run on system start)

We can set up a worker daemon to start up elasticsearch when our VM starts up using:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

Screen Shot 2020-11-16 at 7.31.39 AM

and finally starting the process using:

sudo /bin/systemctl start elasticsearch.service

Give it a minute or so to start up, and then we can send in the following cURL request to verify and see if our elasticsearch instance is up and running:

curl -XGET 127.0.0.1:9200

If all went well, you should see the following response with the default tagline "You Know, for Search".

Screen Shot 2020-11-16 at 7.34.12 AM

Now you have a proper working installation of Elasticsearch 7 configured on a VM!

In order to interface with the instance outside of the VM, we need to setup port-forwarding, which we can do by going into our VMs Settings>Networking>Advanced>Port Forwarding

Screen Shot 2020-11-16 at 1.49.40 PM

Screen Shot 2020-11-16 at 1.50.29 PM

then add new rules where you configure the host and guest ports as follows

Screen Shot 2020-11-16 at 2.01.49 PM

Now, as long as your VM is running, you can SSH into it from your host machine using PuTTY (if you're on Windows) or ssh your_vm_username@127.0.0.1 -p 2222 like below

Screen Shot 2020-11-16 at 2.07.52 PM

and then enter your password to login, and continue interfacing with your Elastic cluster from your host machine!

Top comments (1)

Collapse
 
rahym1234 profile image
Rahym1234

Please pinging_app amangeldijan0503@gmail.com