Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps to configure Elasticsearch snapshots #55

Open
derekenos opened this issue Sep 18, 2020 · 1 comment
Open

Steps to configure Elasticsearch snapshots #55

derekenos opened this issue Sep 18, 2020 · 1 comment

Comments

@derekenos
Copy link
Collaborator

derekenos commented Sep 18, 2020

I'm writing down the steps that I take to configure ES snapshots for later inclusion in the disk image and documentation.

  1. Install the S3 repository plugin (es docs)
./usr/share/elasticsearch/bin/elasticsearch-plugin install repository-s3

That's ^ supposed to work but it just hangs after:

-> Installing repository-s3
-> Downloading repository-s3 from elastic
[=================================================] 100%   

Manually installing repository-s3-7.7.0.zip like this worked:

./usr/share/elasticsearch/bin/elasticsearch-plugin install file:///tmp/repository-s3-7.7.0.zip
  1. Configure S3 plugin endpoint
    Add this line to /etc/elasticsearch/elasticsearch.yml:
s3.client.default.endpoint: sfo2.digitaloceanspaces.com

^ replacing sfo2.digitaloceanspaces.com with whatever's appropriate for your DO Space.

  1. Create DO Space credentials for the ES snapshots

  2. Add the DO Space credentials to the ES keystore:
    Set the access_key:

/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.access_key
{ enter the access key + hit ENTER}

Set the secret_key:

/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.secret_key
{ enter the secret key + hit ENTER }

Note that the default in these key names corresponds to the name of the Elasticsearch S3 repository that we have yet to create.

  1. Restart ES:
systemctl restart elasticsearch
@derekenos
Copy link
Collaborator Author

derekenos commented Sep 21, 2020

Bundled up the server-side stuff in a bash script:

#!/bin/bash

CONFIG_PATH=/etc/elasticsearch/elasticsearch.yml

# Define a helper function that will prompt for confirmation to continue.
function prompt_for_confirmation () {
  msg=$1
  echo -n "$msg (Y/n)? "
  read response
  # Use wierd ${<var-name>,,} syntax to downcase the response.
  response="${response,,}"
  if [[ "$response" != "y" && "$response" != "" ]]
    then
      echo "Aborting"
      exit 1
  fi
}

# Check whether elasticsearch.yml already defines an s3.client endpoint.
res=`grep ^s3\.client $CONFIG_PATH`

# Abort if a value is already defined.
if [ "$?" -eq 0 ]
  then
    echo "S3 client already configured in $CONFIG_PATH: \"$res\""
    exit 1
fi

# Install the repository-s3 plugin if necessary.
echo -n "Checking whether S3 snapshot repository plugin is installed - "
res=`/usr/share/elasticsearch/bin/elasticsearch-plugin list | grep repository-s3`
if [ "$?" -eq 0 ]
then
  echo "installed"
else
  echo "not installed"
  echo "Installing S3 snapshot repository plugin..."
  ES_VERSION=`/usr/share/elasticsearch/bin/elasticsearch --version | grep -o -P '^Version:\s[^,]+' | cut -d' ' -f2`
  PLUGIN_FILENAME="repository-s3-$ES_VERSION.zip"
  curl --silent https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-s3/$PLUGIN_FILENAME -O
  /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch --silent file://`pwd`/$PLUGIN_FILENAME
  rm $PLUGIN_FILENAME
fi


SETTING_KEY="s3.client.default.endpoint"

# Prompt user for endpoint.
echo -n "Enter your S3-compatible endpoint value: "
read endpoint
prompt_for_confirmation "Set \"$SETTING_KEY\" to \"$endpoint\""

# Append the setting to elasticsearch.yml
echo "$SETTING_KEY: $endpoint" >> $CONFIG_PATH

# Add the access key to the keystore.
echo "Preparing to configure S3 credentials..."
/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.access_key
/usr/share/elasticsearch/bin/elasticsearch-keystore add s3.client.default.secret_key

# Restart Elasticsearch
prompt_for_confirmation "Restart Elasticsearch now"
systemctl restart elasticsearch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant