Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconauto-discovery
file-type-iconbeats-iam-policies
file-type-iconelastalert-iam-policies
file-type-iconelastalert-security-group-rules
file-type-iconelastalert
file-type-iconelasticsearch-cluster-backup
file-type-iconelasticsearch-cluster-restore
file-type-iconelasticsearch-cluster
file-type-iconelasticsearch-iam-policies
file-type-iconelasticsearch-security-group-rules
file-type-iconinstall-collectd
file-type-iconinstall-elastalert
file-type-iconinstall-elasticsearch
file-type-iconinstall-filebeat
file-type-iconinstall-kibana
file-type-iconinstall-logstash
file-type-iconkibana-cluster
file-type-iconkibana-security-group-rules
file-type-iconload-balancer-alb-target-group
file-type-iconlogstash-cluster
file-type-iconlogstash-iam-policies
file-type-iconlogstash-security-group-rules
file-type-iconrun-collectd
file-type-iconrun-elastalert
file-type-iconrun-elasticsearch
file-type-iconbin
file-type-iconREADME.md
file-type-iconinstall.sh
file-type-iconrun-filebeat
file-type-iconrun-kibana
file-type-iconrun-logstash
file-type-icontest
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.md
file-type-iconREADME.md

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconauto-discovery
file-type-iconbeats-iam-policies
file-type-iconelastalert-iam-policies
file-type-iconelastalert-security-group-rules
file-type-iconelastalert
file-type-iconelasticsearch-cluster-backup
file-type-iconelasticsearch-cluster-restore
file-type-iconelasticsearch-cluster
file-type-iconelasticsearch-iam-policies
file-type-iconelasticsearch-security-group-rules
file-type-iconinstall-collectd
file-type-iconinstall-elastalert
file-type-iconinstall-elasticsearch
file-type-iconinstall-filebeat
file-type-iconinstall-kibana
file-type-iconinstall-logstash
file-type-iconkibana-cluster
file-type-iconkibana-security-group-rules
file-type-iconload-balancer-alb-target-group
file-type-iconlogstash-cluster
file-type-iconlogstash-iam-policies
file-type-iconlogstash-security-group-rules
file-type-iconrun-collectd
file-type-iconrun-elastalert
file-type-iconrun-elasticsearch
file-type-iconbin
file-type-iconREADME.md
file-type-iconinstall.sh
file-type-iconrun-filebeat
file-type-iconrun-kibana
file-type-iconrun-logstash
file-type-icontest
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE.md
file-type-iconREADME.md
Elasticsearch (self-hosted)

Elasticsearch (self-hosted)

Deploy a self-hosted Elasticsearch cluster. Supports automatic bootstrap, zero-downtime rolling deployment, auto healing, backup, and recovery.

Code Preview

Preview the Code

mobile file icon

README.md

down

Run Elasticsearch Script

This folder contains a script for configuring and running Elasticsearch

This script has been tested on the following operating systems:

  • Ubuntu 16.04
  • Ubuntu 18.04
  • Amazon Linux 2
  • CentOS 7

Quick start

This module depends on bash-commons, so you must install that project first as documented in its README.

The easiest way to use this module is with the Gruntwork Installer:

gruntwork-install \
  --module-name "run-elasticsearch" \
  --repo "https://github.com/gruntwork-io/package-elk" \
  --tag "<VERSION>"

Checkout the releases to find the latest version.

Command line Arguments

Run run-elasticsearch --help to see all available arguments.

  Usage: run-elasticsearch [OPTIONS]

  This script can be used to configure and run Elasticsearch.
  
  Optional arguments:
  
    --auto-fill-endpoint    VALUE should be aws_region. Value will be converted to aws_endpoint. KEY in Elasticsearch config file will be replaced with aws_endpoint. Only needed if running with ec2 discovery plugin.
    --auto-fill KEY=VALUE   Search the Elasticsearch config file for KEY and replace it with VALUE. May be repeated.
    --auto-fill-jvm KEY=VALUE   Search the Elasticsearch JVM config file for KEY and replace it with VALUE. May be repeated.
  
  Example:
  
    install.sh
      --auto-fill "<__CLUSTER_NAME__>=the-cluster-name" --auto-fill-jvm "<__XMS__>=4g"

How it works

The run-elasticsearch script:

  • Replace <__KEY_NAME__> with VALUE that you specify as part of your --auto-fill arguments in the Elasticsearch config file located in: /etc/elasticsearch/elasticsearch.yml
  • Replace <__KEY_NAME__> with VALUE that you specify as part of your --auto-fill-jvm arguments in the JVM config file located in: /etc/elasticsearch/jvm.options

Enabling SSL

In order to use Elasticsearch with SSL we use the ReadonlyREST plugin. A complete setup will require the following steps:

  1. Generating Java Keystore
  2. Create a readonlyrest.yml config file
  3. Create an Elasticsearch AMI with ReadonlyREST plugin installed

Generating Java Key Store

We use the generate-key-stores script in order to create the Java Keystore that ReadonlyREST will use to store certificates.

Under the hood, we are using keytool to create the Key Store and Trust Store and openssl to sign the certificate.

Note: It is important to generate the Java Key Store first because we will then include this keystore in the AMI/Docker Image that we create in the next step. See this Packer Template for a concrete example of how we are including the Java Key Store in the AMI/Docker Image.

Create ReadonlyREST config file

You will need to create a file called readonlyrest.yml. It should look something like this:

readonlyrest:
    ssl:
      # put the keystore in the same dir with elasticsearch.yml
      keystore_file: "elasticsearch.server.keystore.jks"
      keystore_pass: <__KEYSTORE_PASS__>
      key_pass: <__KEY_PASS__>
      key_alias: localhost

See this Packer Template for a concrete example of where we create this file and how we then make sure this file is included in the AMI/Docker Image we create.

Note: You should not hard code Java Key Store passwords or key passwords in this (or any) config file! Instead, encrypt the password using something like KMS or Vault and at run time (e.g., in User Data) decrypt it and use the --auto-fill-ror param of run-elasticsearch script to fill it into this file, which can only be accessed by the root or the elasticsearch user.

Complete documentation for the readonlyrest.yml can be found here

Creating Elasticsearch AMI with ReadonlyREST plugin

The first thing we will need to do is build an AMI that has Elasticsearch installed and also has the ReadonlyREST plugin installed. See this example that goes through generating either an Elasticsearch docker image or AMI with ReadonlyREST plugin installed.

Note: There's currently no way to easily download the plugin from https://readonlyrest.com as the site requires you to submit your email in order to get a custom download link. We are currently hosting one particular version of the plugin that we are using in our examples. If you need a different/new version then you will have to download it and host it locally/provide it to the elasticsearch-install module.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?