Last active
April 7, 2018 10:06
-
-
Save AjeetK/3e2029abcf6ab2a68e4333e5f56245fa to your computer and use it in GitHub Desktop.
Running Elasticsearch in Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# This is the first part which can be used to prepare base-image | |
### | |
# output log of userdata to /var/log/user-data.log | |
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
# Install awscli | |
apt-get update | |
apt install awscli -y | |
# Set max_map_count | |
echo 262144 | sudo tee /proc/sys/vm/max_map_count | |
# Install docker | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
apt-get update | |
apt-cache policy docker-ce | |
apt-get install -y docker-ce | |
service docker restart | |
# Get official elasticsearch docker image | |
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.3 | |
# Create /etc/elasticsearch directory to hold elasticsearch config files like elasticsearch.yml and jvm.options | |
mkdir -p /etc/elasticsearch | |
### | |
# Second part of script downloads elasticsearch configuration files from S3 and run container | |
### | |
# Get elasticsearch config files from S3 | |
aws s3 cp s3://elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml --region ap-south-1 | |
aws s3 cp s3://elasticsearch/jvm.options /etc/elasticsearch/jvm.options --region ap-south-1 | |
# Replace nodename in elasticsearch.yml file with hostname | |
sed -i -e "s/nodename/${HOSTNAME}/g" /etc/elasticsearch/elasticsearch.yml | |
# Mount a secondary Volume for elasticsearch data directory | |
mkfs.xfs /dev/xvdb | |
mkdir -p /vol/es | |
mount /dev/xvdba /vol/es | |
# change ownership of data directory and config directory to user with 1000 id as in container elasticsearch runs with user 1000 | |
chown -R 1000:1000 /vol | |
chown -R 1000:1000 /etc/elasticsearch | |
# Make sure vm.max_map_count is 262144 | |
sysctl -w vm.max_map_count=262144 | |
#start docker container | |
docker run --net=host -d -p 9200:9200 -e "xpack.security.enabled=false" --restart unless-stopped -v /vol/es:/usr/share/elasticsearch/data -v /etc/elasticsearch/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /etc/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml --ulimit nofile=65536:65536 --ulimit memlock=-1:-1 docker.elastic.co/elasticsearch/elasticsearch:6.2.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment