forked from wazuh/wazuh-docker
committed by
Jesús Linares
parent
303e0f6557
commit
086ba71c69
@@ -1,36 +1,93 @@
|
||||
#!/bin/bash
|
||||
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
|
||||
elastic_config_file="/usr/share/elasticsearch/config/elasticsearch.yml"
|
||||
|
||||
original_file="/usr/share/elasticsearch/config/original-elasticsearch.yml"
|
||||
ELASTIC_HOSTAME=`hostname`
|
||||
|
||||
echo "CLUSTER: - Prepare Configuration"
|
||||
echo "CLUSTER: - Hostname"
|
||||
echo $ELASTIC_HOSTAME
|
||||
echo "CLUSTER: - Security main node"
|
||||
echo $SECURITY_MAIN_NODE
|
||||
echo "CLUSTER: - Discovery seed"
|
||||
echo $CLUSTER_DISCOVERY_SEED
|
||||
echo "CLUSTER: - Elastic cluster flag"
|
||||
echo $ELASTIC_CLUSTER
|
||||
echo "CLUSTER: - Node Master"
|
||||
echo $CLUSTER_NODE_MASTER
|
||||
echo "CLUSTER: - Node Data"
|
||||
echo $CLUSTER_NODE_DATA
|
||||
echo "CLUSTER: - Node Ingest"
|
||||
echo $CLUSTER_NODE_INGEST
|
||||
|
||||
cp $elastic_config_file $original_file
|
||||
|
||||
# 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
|
||||
remove_single_node_conf(){
|
||||
if grep -Fq "discovery.type" $1; then
|
||||
sed -i '/discovery.type\: /d' $1
|
||||
fi
|
||||
}
|
||||
|
||||
# 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_cluster_config(){
|
||||
sed -i '/# cluster node/,/# end cluster config/d' $1
|
||||
}
|
||||
|
||||
bootstrap:
|
||||
memory_lock: ${CLUSTER_MEMORY_LOCK}
|
||||
# If Elasticsearch cluster is enable, then set up the elasticsearch.yml
|
||||
if [[ $ELASTIC_CLUSTER == "true" && $CLUSTER_NODE_MASTER != "" && $CLUSTER_NODE_DATA != "" && $CLUSTER_NODE_INGEST != "" && $ELASTIC_HOSTAME != "" ]]; then
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "CLUSTER: - Remove old configuration"
|
||||
|
||||
discovery:
|
||||
zen:
|
||||
ping.unicast.hosts: ${CLUSTER_DISCOVERY_SERVICE}
|
||||
minimum_master_nodes: ${CLUSTER_NUMBER_OF_MASTERS}
|
||||
|
||||
" >> $elastic_config_file
|
||||
if [[ $ELASTIC_HOSTAME == $SECURITY_MAIN_NODE ]]; then
|
||||
# Add the master configuration
|
||||
# cluster.initial_master_nodes for bootstrap the cluster
|
||||
echo "CLUSTER: - Add the master configuration"
|
||||
|
||||
cat > $elastic_config_file << EOF
|
||||
# cluster node
|
||||
cluster.name: $CLUSTER_NAME
|
||||
bootstrap.memory_lock: $CLUSTER_MEMORY_LOCK
|
||||
network.host: 0.0.0.0
|
||||
node.name: $ELASTIC_HOSTAME
|
||||
node.master: $CLUSTER_NODE_MASTER
|
||||
node.data: $CLUSTER_NODE_DATA
|
||||
node.ingest: $CLUSTER_NODE_INGEST
|
||||
node.max_local_storage_nodes: $CLUSTER_MAX_NODES
|
||||
cluster.initial_master_nodes:
|
||||
- $ELASTIC_HOSTAME
|
||||
# end cluster config"
|
||||
EOF
|
||||
|
||||
elif [[ $CLUSTER_DISCOVERY_SEED != "" ]]; then
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "CLUSTER: - Add standard cluster configuration."
|
||||
|
||||
cat > $elastic_config_file << EOF
|
||||
# cluster node
|
||||
cluster.name: $CLUSTER_NAME
|
||||
bootstrap.memory_lock: $CLUSTER_MEMORY_LOCK
|
||||
network.host: 0.0.0.0
|
||||
node.name: $ELASTIC_HOSTAME
|
||||
node.master: $CLUSTER_NODE_MASTER
|
||||
node.data: $CLUSTER_NODE_DATA
|
||||
node.ingest: $CLUSTER_NODE_INGEST
|
||||
node.max_local_storage_nodes: $CLUSTER_MAX_NODES
|
||||
discovery.seed_hosts:
|
||||
- $CLUSTER_DISCOVERY_SEED
|
||||
# end cluster config"
|
||||
EOF
|
||||
fi
|
||||
# If the cluster is disabled, then set a single-node configuration
|
||||
else
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "discovery.type: single-node" >> $elastic_config_file
|
||||
echo "CLUSTER: - Discovery type: single-node"
|
||||
fi
|
||||
|
||||
echo "CLUSTER: - Configured"
|
||||
Reference in New Issue
Block a user