From 5db7509b52ca35dac1a075ed9daaf32c30756e04 Mon Sep 17 00:00:00 2001 From: manuasir Date: Fri, 19 Jul 2019 18:06:27 +0200 Subject: [PATCH 1/2] Fixed cluster configuration --- elasticsearch/config/config_cluster.sh | 55 ++++++++++++-------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/elasticsearch/config/config_cluster.sh b/elasticsearch/config/config_cluster.sh index 2222099e..406cdf30 100644 --- a/elasticsearch/config/config_cluster.sh +++ b/elasticsearch/config/config_cluster.sh @@ -3,39 +3,36 @@ elastic_config_file="/usr/share/elasticsearch/config/elasticsearch.yml" +remove_single_node_conf(){ + if grep -Fq "discovery.type" $1; then + sed -i '/discovery.type\: /d' $1 + fi +} -# If Elasticsearch cluster is enable -if [[ $ELASTIC_CLUSTER == "true" ]] -then - - # Set the cluster.name and discovery.zen.minimun_master_nodes variables - sed -i 's:cluster.name\: "docker-cluster":cluster.name\: "'$CLUSTER_NAME'":g' $elastic_config_file - #sed -i 's:discovery.zen.minimum_master_nodes\: 1:discovery.zen.minimum_master_nodes\: '$CLUSTER_NUMBER_OF_MASTERS':g' $elastic_config_file +# If Elasticsearch cluster is enable, then set up the elasticsearch.yml +if [[ $ELASTIC_CLUSTER == "true" && $CLUSTER_NODE_MASTER != "" && $CLUSTER_NODE_DATA != "" && $CLUSTER_NODE_INGEST != "" ]];then - # Add the cluster configuration - echo " -#cluster node -node: - master: ${CLUSTER_NODE_MASTER} - data: ${CLUSTER_NODE_DATA} - ingest: ${CLUSTER_NODE_INGEST} - name: ${CLUSTER_NODE_NAME} - max_local_storage_nodes: ${CLUSTER_MAX_NODES} + remove_single_node_conf $elastic_config_file -bootstrap: - memory_lock: ${CLUSTER_MEMORY_LOCK} + # Remove the old configuration + sed -i '/# cluster node/,/# end cluster config/d' $elastic_config_file -cluster.initial_master_nodes: - - '${CLUSTER_INITIAL_MASTER_NODES}' + # Add the current cluster configuration +cat > $elastic_config_file << EOF +# cluster node +network.host: 0.0.0.0 +node.name: $CLUSTER_NODE_NAME +node.master: $CLUSTER_NODE_MASTER -" >> $elastic_config_file -else - -cat >> $elastic_config_file <<'EOF' -cluster.initial_master_nodes: - - 'elasticsearch' +cluster.initial_master_nodes: + - $CLUSTER_INITIAL_MASTER_NODES +# end cluster config" EOF -# echo 'discovery.type: single-node' - -fi +# If the cluster is disabled, then set a single-node configuration +else + sed -i '/# cluster node/,/# end cluster config/d' $elastic_config_file + # If it's not already configured + remove_single_node_conf $elastic_config_file + echo "discovery.type: single-node" >> $elastic_config_file +fi \ No newline at end of file From 9740ddcf3ee5b4f0451ba3848af8c4ff9c99a381 Mon Sep 17 00:00:00 2001 From: "Manuel J. Bernal" Date: Fri, 19 Jul 2019 23:03:11 +0200 Subject: [PATCH 2/2] Added more fixes to configuration files --- docker-compose.yml | 21 +++++++++++++----- elasticsearch/Dockerfile | 5 ++--- elasticsearch/config/config_cluster.sh | 30 ++++++++++++++++++++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 31ca6356..6face8e8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,22 +12,33 @@ services: - "514:514/udp" - "55000:55000" elasticsearch: - image: wazuh/wazuh-elasticsearch:3.9.2_7.1.1 + build: elasticsearch hostname: elasticsearch restart: always ports: - "9200:9200" environment: - - node.name=node-1 - - cluster.name=wazuh - - network.host=0.0.0.0 - - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + - ELASTIC_CLUSTER=true + - CLUSTER_NODE_MASTER=true + - CLUSTER_MASTER_NODE_NAME=es01 + + es02: + build: elasticsearch + hostname: es02 + restart: always + environment: + - "ES_JAVA_OPTS=-Xms1g -Xmx1g" + - ELASTIC_CLUSTER=true + - CLUSTER_MASTER_NODE_NAME=elasticsearch + - CLUSTER_NODE_NAME=es02 ulimits: memlock: soft: -1 hard: -1 mem_limit: 2g + + kibana: image: wazuh/wazuh-kibana:3.9.2_7.1.1 hostname: kibana diff --git a/elasticsearch/Dockerfile b/elasticsearch/Dockerfile index 05ad928a..a2764d01 100644 --- a/elasticsearch/Dockerfile +++ b/elasticsearch/Dockerfile @@ -22,10 +22,11 @@ ARG TEMPLATE_VERSION=v3.9.2 # CLUSTER_INITIAL_MASTER_NODES set to own node by default. ENV ELASTIC_CLUSTER="false" \ CLUSTER_NAME="wazuh" \ - CLUSTER_NODE_MASTER="true" \ + CLUSTER_NODE_MASTER="false" \ CLUSTER_NODE_DATA="true" \ CLUSTER_NODE_INGEST="true" \ CLUSTER_NODE_NAME="wazuh-elasticsearch" \ + CLUSTER_MASTER_NODE_NAME="master-node" \ CLUSTER_MEMORY_LOCK="true" \ CLUSTER_DISCOVERY_SERVICE="wazuh-elasticsearch" \ CLUSTER_NUMBER_OF_MASTERS="2" \ @@ -33,8 +34,6 @@ ENV ELASTIC_CLUSTER="false" \ CLUSTER_DELAYED_TIMEOUT="1m" \ CLUSTER_INITIAL_MASTER_NODES="wazuh-elasticsearch" -ADD https://raw.githubusercontent.com/wazuh/wazuh/$TEMPLATE_VERSION/extensions/elasticsearch/7.x/wazuh-template.json /usr/share/elasticsearch/config - COPY config/entrypoint.sh /entrypoint.sh RUN chmod 755 /entrypoint.sh diff --git a/elasticsearch/config/config_cluster.sh b/elasticsearch/config/config_cluster.sh index 406cdf30..2a851286 100644 --- a/elasticsearch/config/config_cluster.sh +++ b/elasticsearch/config/config_cluster.sh @@ -10,25 +10,41 @@ remove_single_node_conf(){ } # If Elasticsearch cluster is enable, then set up the elasticsearch.yml -if [[ $ELASTIC_CLUSTER == "true" && $CLUSTER_NODE_MASTER != "" && $CLUSTER_NODE_DATA != "" && $CLUSTER_NODE_INGEST != "" ]];then +if [[ $ELASTIC_CLUSTER == "true" && $CLUSTER_NODE_MASTER != "" && $CLUSTER_NODE_DATA != "" && $CLUSTER_NODE_INGEST != "" && $CLUSTER_MASTER_NODE_NAME != "" ]]; then remove_single_node_conf $elastic_config_file # Remove the old configuration sed -i '/# cluster node/,/# end cluster config/d' $elastic_config_file - # Add the current cluster configuration +if [[ $CLUSTER_NODE_MASTER == "true" ]]; then +# Add the master configuration +# cluster.initial_master_nodes for bootstrap the cluster +cat > $elastic_config_file << EOF +# cluster node +network.host: 0.0.0.0 +node.name: $CLUSTER_MASTER_NODE_NAME +node.master: $CLUSTER_NODE_MASTER +cluster.initial_master_nodes: + - $CLUSTER_MASTER_NODE_NAME +# end cluster config" +EOF + +elif [[ $CLUSTER_NODE_NAME != "" ]];then + +sed -i '/# cluster node/,/# end cluster config/d' $elastic_config_file + cat > $elastic_config_file << EOF # cluster node network.host: 0.0.0.0 node.name: $CLUSTER_NODE_NAME -node.master: $CLUSTER_NODE_MASTER - -cluster.initial_master_nodes: - - $CLUSTER_INITIAL_MASTER_NODES +node.master: false +discovery.seed_hosts: + - $CLUSTER_MASTER_NODE_NAME + - $CLUSTER_NODE_NAME # end cluster config" EOF - +fi # If the cluster is disabled, then set a single-node configuration else sed -i '/# cluster node/,/# end cluster config/d' $elastic_config_file