Last active
June 7, 2020 02:33
-
-
Save mocobeta/e966a08c5604bacaced645f616da4bd7 to your computer and use it in GitHub Desktop.
Configuring Es 7 cluster on containers on GCE VMs (https://medium.com/@mocobeta/elasticsearch-7-%E3%82%AF%E3%83%A9%E3%82%B9%E3%82%BF%E3%82%92-containers-on-gce-%E3%81%A7%E7%AB%8B%E3%81%A1%E4%B8%8A%E3%81%92%E3%82%8B-a048c518aebb)
This file contains 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
# | |
# variables | |
# | |
export PROJECT=$(gcloud config get-value project) | |
export REGISTRY_HOST=asia.gcr.io | |
export CONTAINER_IMAGE=my-es-7 | |
export ZONE_1=asia-northeast1-a | |
export ZONE_2=asia-northeast1-b | |
export ZONE_3=asia-northeast1-c | |
export INSTANCE_NAME_1=es-vm-1 | |
export INSTANCE_NAME_2=es-vm-2 | |
export INSTANCE_NAME_3=es-vm-3 | |
export DATA_DISK_SIZE=50 | |
export DATA_DISK_TYPE=pd-ssd | |
export DATA_DISK_1=es-data-disk-1 | |
export DATA_DISK_2=es-data-disk-2 | |
export DATA_DISK_3=es-data-disk-3 | |
export ES_CLUSTER=my-es-cluster | |
export ES_NODE_1=es-node-1 | |
export ES_NODE_2=es-node-2 | |
export ES_NODE_3=es-node-3 | |
export SEED_HOSTS=${INSTANCE_NAME_1}.${ZONE_1}.c.${PROJECT}.internal,${INSTANCE_NAME_2}.${ZONE_2}.c.${PROJECT}.internal,${INSTANCE_NAME_3}.${ZONE_3}.c.${PROJECT}.internal | |
export INITIAL_MASTER_NODES=${ES_NODE_1},${ES_NODE_2},${ES_NODE_3} | |
# | |
# building image | |
# | |
chmod 755 entrypoint.sh | |
docker build -q --tag ${CONTAINER_IMAGE}:latest --no-cache . | |
docker tag ${CONTAINER_IMAGE}:latest ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE}:latest | |
docker push ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE} | |
gcloud container images list --repository ${REGISTRY_HOST}/${PROJECT} | |
# | |
# startup instances with containers | |
# | |
gcloud compute instances create-with-container ${INSTANCE_NAME_1} \ | |
--zone ${ZONE_1} \ | |
--metadata VmDnsSetting=ZonalPreferred \ | |
--metadata-from-file startup-script=instance-setup.sh \ | |
--create-disk name=${DATA_DISK_1},device-name=${DATA_DISK_1},auto-delete=yes,size=${DATA_DISK_SIZE},type=${DATA_DISK_TYPE} \ | |
--container-mount-disk name=${DATA_DISK_1},mount-path=/usr/share/elasticsearch/data \ | |
--container-privileged \ | |
--container-image ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE} \ | |
--container-env "^:^cluster.name=${ES_CLUSTER}:node.name=${ES_NODE_1}:node.master=true:node.data=true:discovery.seed_hosts=${SEED_HOSTS}:cluster.initial_master_nodes=${INITIAL_MASTER_NODES}" | |
gcloud compute instances create-with-container ${INSTANCE_NAME_2} \ | |
--zone ${ZONE_2} \ | |
--metadata VmDnsSetting=ZonalPreferred \ | |
--metadata-from-file startup-script=instance-setup.sh \ | |
--create-disk name=${DATA_DISK_2},device-name=${DATA_DISK_2},auto-delete=yes,size=${DATA_DISK_SIZE},type=${DATA_DISK_TYPE} \ | |
--container-mount-disk name=${DATA_DISK_2},mount-path=/usr/share/elasticsearch/data \ | |
--container-privileged \ | |
--container-image ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE} \ | |
--container-env "^:^cluster.name=${ES_CLUSTER}:node.name=${ES_NODE_2}:node.master=true:node.data=true:discovery.seed_hosts=${SEED_HOSTS}:cluster.initial_master_nodes=${INITIAL_MASTER_NODES}" | |
gcloud compute instances create-with-container ${INSTANCE_NAME_3} \ | |
--zone ${ZONE_3} \ | |
--metadata VmDnsSetting=ZonalPreferred \ | |
--metadata-from-file startup-script=instance-setup.sh \ | |
--create-disk name=${DATA_DISK_3},device-name=${DATA_DISK_3},auto-delete=yes,size=${DATA_DISK_SIZE},type=${DATA_DISK_TYPE} \ | |
--container-mount-disk name=${DATA_DISK_3},mount-path=/usr/share/elasticsearch/data \ | |
--container-privileged \ | |
--container-image ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE} \ | |
--container-env "^:^cluster.name=${ES_CLUSTER}:node.name=${ES_NODE_3}:node.master=true:node.data=true:discovery.seed_hosts=${SEED_HOSTS}:cluster.initial_master_nodes=${INITIAL_MASTER_NODES}" | |
# | |
# update containers | |
# | |
gcloud compute instances update-container ${INSTANCE_NAME_1} \ | |
--zone ${ZONE_1} \ | |
--container-privileged \ | |
--container-image ${REGISTRY_HOST}/${PROJECT}/${CONTAINER_IMAGE} | |
# | |
# delete instances | |
# | |
gcloud compute instances delete --quiet --zone ${ZONE_1} ${INSTANCE_NAME_1} | |
gcloud compute instances delete --quiet --zone ${ZONE_2} ${INSTANCE_NAME_2} | |
gcloud compute instances delete --quiet --zone ${ZONE_3} ${INSTANCE_NAME_3} |
This file contains 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
# base image | |
FROM docker.elastic.co/elasticsearch/elasticsearch:7.7.0 | |
# PATH | |
ENV PATH /usr/share/elasticsearch/bin:$PATH | |
# work directory | |
WORKDIR /usr/share/elasticsearch | |
USER elasticsearch | |
# copy configuration file | |
COPY elasticsearch.yml /usr/share/elasticsearch/config/ | |
# install plugins | |
RUN elasticsearch-plugin install analysis-kuromoji | |
RUN elasticsearch-plugin install analysis-icu | |
# switch user to root | |
USER root | |
# system configuration | |
# https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html | |
RUN mkdir -p /etc/systemd/system/elasticsearch.service.d/ | |
RUN touch /etc/systemd/system/elasticsearch.service.d/override.conf | |
RUN echo "[Service]" >> /etc/systemd/system/elasticsearch.service.d/override.conf | |
RUN echo "LimitMEMLOCK=infinity" >> /etc/systemd/system/elasticsearch.service.d/override.conf | |
COPY entrypoint.sh . | |
ENTRYPOINT ["./entrypoint.sh"] |
This file contains 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
cluster.name: es-test-cluster | |
#node.name: es-test-node-1 | |
#node.master: true | |
#node.data: true | |
bootstrap.memory_lock: true | |
network.host: 0.0.0.0 | |
network.bind_host: 0.0.0.0 | |
#discovery.seed_hosts: ["es-test-vm-1.asia-northeast1-a.c.lf-rd-zoo.internal"] | |
#cluster.initial_master_nodes: ["es-test-node-1"] | |
xpack.license.self_generated.type: basic | |
xpack.security.enabled: false | |
xpack.monitoring.enabled: false | |
xpack.monitoring.collection.enabled: false | |
xpack.sql.enabled: false | |
xpack.watcher.enabled: false | |
xpack.ml.enabled: false |
This file contains 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 | |
# system configuration | |
# https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html | |
ulimit -n 65536 | |
ulimit -l unlimited | |
# change owner of data directory to avoid access denied exception | |
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data | |
# start the elasticsearch node | |
/usr/local/bin/docker-entrypoint.sh eswrapper |
This file contains 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 | |
# increase mmap count | |
# https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html | |
sysctl -w vm.max_map_count=262144 | |
echo "vm.max_map_count = 262144" >> /etc/sysctl.d/99-sysctl.conf | |
# increase resource limits | |
# https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#systemd | |
ulimit -n 65536 | |
ulimit -l unlimited | |
echo "root * nofile 65536" >> /etc/security/limits.conf | |
echo "root * memlock unlimited" >> /etc/security/limits.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment