Loading docker-compose.dev.yml +1 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ services: environment: - ES_CLUSTER_NAME=elasticsearch_dev - ES_NODE_NAME=node-1 - ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES=1 ulimits: memlock: soft: -1 Loading docker-compose.prod.yml +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ services: - es-{{.Task.Slot}} environment: - SWARM_MODE=true - DISCOVERY_DELAY=60 - SERVICE_NAME={{.Service.Name}} - ES_CLUSTER_NAME=redmic - ES_NODE_NAME={{.Service.Name}}-{{.Task.Slot}} Loading docker-compose.tmpl.yml +0 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ services: environment: - ES_BOOTSTRAP_MEMORY_LOCK=true - ES_JAVA_OPTS=-Xms2g -Xmx2g -Djava.security.policy=file:///usr/share/elasticsearch/config/grovy-classes_whitelist.policy - ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES=1 - ES_PLUGINS - OLD_ELASTIC_ADMIN_PASS - ELASTIC_ADMIN_PASS Loading scripts/docker-entrypoint.sh +32 −28 Original line number Diff line number Diff line #!/bin/bash TEMPLATE_FILENAME="elasticsearch" OTHER_NODES="" templateFilename="elasticsearch" otherNodes="" chown -R elasticsearch:elasticsearch ${ES_DATA_PATH} Loading @@ -11,43 +11,47 @@ if [ -n "${SWARM_MODE}" ]; then exit 3 fi DISCOVERY_DELAY=${DISCOVERY_DELAY:-15} echo "Waiting ${DISCOVERY_DELAY}s before discovering..." # Delay to let hostname to be published to swarm DNS service sleep ${DISCOVERY_DELAY:-15} sleep ${DISCOVERY_DELAY} echo "Discovering other nodes in cluster..." # Docker swarm's DNS resolves special hostname "tasks.<service_name" to IP addresses of all containers inside overlay network SWARM_SERVICE_IPs=$(dig tasks.${SERVICE_NAME} +short) swarmServiceIps=$(dig tasks.${SERVICE_NAME} +short) echo "Nodes of service ${SERVICE_NAME}:" echo "$SWARM_SERVICE_IPs" echo "${swarmServiceIps}" HOSTNAME=$(hostname) MY_IP=$(dig ${HOSTNAME} +short) echo "My IP: ${MY_IP}" hostname=$(hostname) myIp=$(dig ${hostname} +short) echo "My IP: ${myIp}" for NODE_IP in $SWARM_SERVICE_IPs for nodeIp in ${swarmServiceIps} do if [ "${NODE_IP}" == "${MY_IP}" ];then if [ "${nodeIp}" == "${myIp}" ];then continue; fi OTHER_NODES="${OTHER_NODES}${NODE_IP}," otherNodes="${otherNodes}${nodeIp}," done if [ -n "${MY_IP}" ];then echo "Setting network.publish_host=${MY_IP}" export ES_NETWORK_PUBLISH_HOST=${MY_IP} if [ -n "${myIp}" ];then echo "Setting network.publish_host=${myIp}" export ES_NETWORK_PUBLISH_HOST=${myIp} fi fi envsubst < /${TEMPLATE_FILENAME}.template > ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml envsubst < /${templateFilename}.template > ${ES_PATH}/config/${templateFilename}.yml # Search nodes if [ -n "${OTHER_NODES}" ];then echo "Setting discovery.zen.ping.unicast.hosts=${OTHER_NODES%,}" export ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=${OTHER_NODES%,} if [ -n "${otherNodes}" ];then echo "Setting discovery.zen.ping.unicast.hosts=${otherNodes%,}" export ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=${otherNodes%,} ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=",${ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS}" echo "discovery.zen.ping.unicast.hosts: ${ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS}" \ | sed -e 's/,/\n - /g' >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml | sed -e 's/,/\n - /g' >> ${ES_PATH}/config/${templateFilename}.yml else echo "There is no another nodes in cluster. I am alone!" fi Loading @@ -68,30 +72,30 @@ function check_credentials_s3() { exit 1 fi echo "cloud.aws.s3.access_key: ${AWS_ACCESS_KEY_ID}" >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml echo "cloud.aws.s3.secret_key: ${AWS_SECRET_ACCESS_KEY}" >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml echo "cloud.aws.s3.access_key: ${AWS_ACCESS_KEY_ID}" >> ${ES_PATH}/config/${templateFilename}.yml echo "cloud.aws.s3.secret_key: ${AWS_SECRET_ACCESS_KEY}" >> ${ES_PATH}/config/${templateFilename}.yml } # Install plugins pluginsInstalled=$(${ES_PATH}/bin/elasticsearch-plugin list) IFS=';' read -ra PLUGINS <<< "${ES_PLUGINS}" for PLUGIN in "${PLUGINS[@]}"; do echo "Installing plugin ${PLUGIN}" for plugin in "${PLUGINS[@]}"; do echo "Installing plugin ${plugin}" if [ "${PLUGIN}" == "repository-s3" ]; then if [ "${plugin}" == "repository-s3" ]; then check_credentials_s3 fi echo "${pluginsInstalled}" | grep "${PLUGIN}" echo "${pluginsInstalled}" | grep "${plugin}" if [ "${?}" -ne "0" ]; then gosu elasticsearch ${ES_PATH}/bin/elasticsearch-plugin install --batch ${PLUGIN} gosu elasticsearch ${ES_PATH}/bin/elasticsearch-plugin install --batch ${plugin} else echo "Plugin ${PLUGIN} already installed!" echo "Plugin ${plugin} already installed!" fi done cat ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml cat ${ES_PATH}/config/${templateFilename}.yml /manage-users.sh & disown Loading scripts/manage-users.sh +10 −10 Original line number Diff line number Diff line #!/bin/sh ELASTIC_ADMIN=elastic retryManageUsers=true elasticAdmin=elastic retryManageUsers=1 while [ "${retryManageUsers}" -eq "true" ] while [ "${retryManageUsers}" -eq "1" ] do responseStatus=$(curl --write-out %{http_code} --silent --output /dev/null \ -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ localhost:9200/_cluster/health) echo "Trying to manage users, got ${responseStatus} response" if [ "${responseStatus}" -eq "401" ] || [ "${responseStatus}" -eq "200" ] then retryManageUsers=false retryManageUsers=0 else sleep 1 continue Loading @@ -23,8 +23,8 @@ do if [ "${responseStatus}" -eq "401" ] then curl -XPUT -u "${ELASTIC_ADMIN}:${OLD_ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${ELASTIC_ADMIN}/_password" \ curl -XPUT -u "${elasticAdmin}:${OLD_ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${elasticAdmin}/_password" \ -H "Content-Type: application/json" -d "{ \"password\": \"${ELASTIC_ADMIN_PASS}\" }" Loading @@ -40,12 +40,12 @@ do echo "Trying to create default role and user" responseStatus=$(curl --write-out %{http_code} --silent --output /dev/null \ -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/role/${ELASTIC_USER_ROLE}") if [ "${responseStatus}" -eq "404" ] then curl -XPOST -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ curl -XPOST -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/role/${ELASTIC_USER_ROLE}" \ -H "Content-Type: application/json" -d '{ "run_as": [], Loading @@ -61,7 +61,7 @@ do echo "Role created" fi curl -XPOST -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ curl -XPOST -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${ELASTIC_USER}" \ -H "Content-Type: application/json" -d "{ \"password\": \"${ELASTIC_USER_PASS}\", Loading Loading
docker-compose.dev.yml +1 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ services: environment: - ES_CLUSTER_NAME=elasticsearch_dev - ES_NODE_NAME=node-1 - ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES=1 ulimits: memlock: soft: -1 Loading
docker-compose.prod.yml +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ services: - es-{{.Task.Slot}} environment: - SWARM_MODE=true - DISCOVERY_DELAY=60 - SERVICE_NAME={{.Service.Name}} - ES_CLUSTER_NAME=redmic - ES_NODE_NAME={{.Service.Name}}-{{.Task.Slot}} Loading
docker-compose.tmpl.yml +0 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,6 @@ services: environment: - ES_BOOTSTRAP_MEMORY_LOCK=true - ES_JAVA_OPTS=-Xms2g -Xmx2g -Djava.security.policy=file:///usr/share/elasticsearch/config/grovy-classes_whitelist.policy - ES_DISCOVERY_ZEN_MINIMUM_MASTER_NODES=1 - ES_PLUGINS - OLD_ELASTIC_ADMIN_PASS - ELASTIC_ADMIN_PASS Loading
scripts/docker-entrypoint.sh +32 −28 Original line number Diff line number Diff line #!/bin/bash TEMPLATE_FILENAME="elasticsearch" OTHER_NODES="" templateFilename="elasticsearch" otherNodes="" chown -R elasticsearch:elasticsearch ${ES_DATA_PATH} Loading @@ -11,43 +11,47 @@ if [ -n "${SWARM_MODE}" ]; then exit 3 fi DISCOVERY_DELAY=${DISCOVERY_DELAY:-15} echo "Waiting ${DISCOVERY_DELAY}s before discovering..." # Delay to let hostname to be published to swarm DNS service sleep ${DISCOVERY_DELAY:-15} sleep ${DISCOVERY_DELAY} echo "Discovering other nodes in cluster..." # Docker swarm's DNS resolves special hostname "tasks.<service_name" to IP addresses of all containers inside overlay network SWARM_SERVICE_IPs=$(dig tasks.${SERVICE_NAME} +short) swarmServiceIps=$(dig tasks.${SERVICE_NAME} +short) echo "Nodes of service ${SERVICE_NAME}:" echo "$SWARM_SERVICE_IPs" echo "${swarmServiceIps}" HOSTNAME=$(hostname) MY_IP=$(dig ${HOSTNAME} +short) echo "My IP: ${MY_IP}" hostname=$(hostname) myIp=$(dig ${hostname} +short) echo "My IP: ${myIp}" for NODE_IP in $SWARM_SERVICE_IPs for nodeIp in ${swarmServiceIps} do if [ "${NODE_IP}" == "${MY_IP}" ];then if [ "${nodeIp}" == "${myIp}" ];then continue; fi OTHER_NODES="${OTHER_NODES}${NODE_IP}," otherNodes="${otherNodes}${nodeIp}," done if [ -n "${MY_IP}" ];then echo "Setting network.publish_host=${MY_IP}" export ES_NETWORK_PUBLISH_HOST=${MY_IP} if [ -n "${myIp}" ];then echo "Setting network.publish_host=${myIp}" export ES_NETWORK_PUBLISH_HOST=${myIp} fi fi envsubst < /${TEMPLATE_FILENAME}.template > ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml envsubst < /${templateFilename}.template > ${ES_PATH}/config/${templateFilename}.yml # Search nodes if [ -n "${OTHER_NODES}" ];then echo "Setting discovery.zen.ping.unicast.hosts=${OTHER_NODES%,}" export ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=${OTHER_NODES%,} if [ -n "${otherNodes}" ];then echo "Setting discovery.zen.ping.unicast.hosts=${otherNodes%,}" export ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=${otherNodes%,} ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS=",${ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS}" echo "discovery.zen.ping.unicast.hosts: ${ES_DISCOVERY_ZEN_PING_UNICAST_HOSTS}" \ | sed -e 's/,/\n - /g' >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml | sed -e 's/,/\n - /g' >> ${ES_PATH}/config/${templateFilename}.yml else echo "There is no another nodes in cluster. I am alone!" fi Loading @@ -68,30 +72,30 @@ function check_credentials_s3() { exit 1 fi echo "cloud.aws.s3.access_key: ${AWS_ACCESS_KEY_ID}" >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml echo "cloud.aws.s3.secret_key: ${AWS_SECRET_ACCESS_KEY}" >> ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml echo "cloud.aws.s3.access_key: ${AWS_ACCESS_KEY_ID}" >> ${ES_PATH}/config/${templateFilename}.yml echo "cloud.aws.s3.secret_key: ${AWS_SECRET_ACCESS_KEY}" >> ${ES_PATH}/config/${templateFilename}.yml } # Install plugins pluginsInstalled=$(${ES_PATH}/bin/elasticsearch-plugin list) IFS=';' read -ra PLUGINS <<< "${ES_PLUGINS}" for PLUGIN in "${PLUGINS[@]}"; do echo "Installing plugin ${PLUGIN}" for plugin in "${PLUGINS[@]}"; do echo "Installing plugin ${plugin}" if [ "${PLUGIN}" == "repository-s3" ]; then if [ "${plugin}" == "repository-s3" ]; then check_credentials_s3 fi echo "${pluginsInstalled}" | grep "${PLUGIN}" echo "${pluginsInstalled}" | grep "${plugin}" if [ "${?}" -ne "0" ]; then gosu elasticsearch ${ES_PATH}/bin/elasticsearch-plugin install --batch ${PLUGIN} gosu elasticsearch ${ES_PATH}/bin/elasticsearch-plugin install --batch ${plugin} else echo "Plugin ${PLUGIN} already installed!" echo "Plugin ${plugin} already installed!" fi done cat ${ES_PATH}/config/${TEMPLATE_FILENAME}.yml cat ${ES_PATH}/config/${templateFilename}.yml /manage-users.sh & disown Loading
scripts/manage-users.sh +10 −10 Original line number Diff line number Diff line #!/bin/sh ELASTIC_ADMIN=elastic retryManageUsers=true elasticAdmin=elastic retryManageUsers=1 while [ "${retryManageUsers}" -eq "true" ] while [ "${retryManageUsers}" -eq "1" ] do responseStatus=$(curl --write-out %{http_code} --silent --output /dev/null \ -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ localhost:9200/_cluster/health) echo "Trying to manage users, got ${responseStatus} response" if [ "${responseStatus}" -eq "401" ] || [ "${responseStatus}" -eq "200" ] then retryManageUsers=false retryManageUsers=0 else sleep 1 continue Loading @@ -23,8 +23,8 @@ do if [ "${responseStatus}" -eq "401" ] then curl -XPUT -u "${ELASTIC_ADMIN}:${OLD_ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${ELASTIC_ADMIN}/_password" \ curl -XPUT -u "${elasticAdmin}:${OLD_ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${elasticAdmin}/_password" \ -H "Content-Type: application/json" -d "{ \"password\": \"${ELASTIC_ADMIN_PASS}\" }" Loading @@ -40,12 +40,12 @@ do echo "Trying to create default role and user" responseStatus=$(curl --write-out %{http_code} --silent --output /dev/null \ -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/role/${ELASTIC_USER_ROLE}") if [ "${responseStatus}" -eq "404" ] then curl -XPOST -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ curl -XPOST -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/role/${ELASTIC_USER_ROLE}" \ -H "Content-Type: application/json" -d '{ "run_as": [], Loading @@ -61,7 +61,7 @@ do echo "Role created" fi curl -XPOST -u "${ELASTIC_ADMIN}:${ELASTIC_ADMIN_PASS}" \ curl -XPOST -u "${elasticAdmin}:${ELASTIC_ADMIN_PASS}" \ "localhost:9200/_xpack/security/user/${ELASTIC_USER}" \ -H "Content-Type: application/json" -d "{ \"password\": \"${ELASTIC_USER_PASS}\", Loading