Wednesday, October 26, 2016

Elasticsearch automatic configure listening address on Oracle Cloud

In an earlier post we showed how we can install Elasticsearch on Oracle Linux within the Oracle Cloud for testing purposes. In this post we showed that using a default installation will make it so that your Elasticsearch node will listen to the IPv4 and IPv6 for your localhost. Even though this is fine for a single test system where you like to explore locally some of the options of Elasticsearch it is not making much sense if you want to integrate this with other systems. In this case you will have to ensure that you are able to access Elasticsearch  from external.

As we are running our Elasticsearch node on Oracle Linux on the Oracle Public IaaS cloud we can use the meta-data API as one of the options to retrieve the address we want use as the listening address and configure this in Elasticsearch.

To ensure Elasticsearch is listening on another address than the localhost address we have to make sure the network.host configuration value in /etc/elasticsearch/elasticsearch.yml is set to the address we want it to listen on. The below script is an example of a script snippet you can use in a wider deployment script:

#!/bin/bash
#
# NAME:
#  config_elasticsearchNetHost.sh 
#
# DESC:
#  This is script is used to configure the network.host settings for 
#  elasticsearch to ensure it is listening to the IP set for local-ipv4
#  in the Oracle public IaaS cloud on Oracle Linux. We will retrieve
#  the local IPV4 adress and add it to the elasticsearch configuration 
#  file /etc/elasticsearch/elasticsearch.yml after which we restart
#  elasticsearch to ensure the setting new setting is active. This will
#  ensure that elasticsearch is now accessible outside localhost

echo "network.host: $(curl -s http://192.0.0.192/1.0/meta-data/local-ipv4)" >> /etc/elasticsearch/elasticsearch.yml
service elasticsearch restart

For example, you can add this to the script used to install Elasticsearch on Oracle Linux. This script can also be found on github. As is the case for the above snippet which is available on Github on this location

No comments: