#!/bin/bash
slaves=("ip2" "ip3" "ip5")
monitors=("ip4")
masters=("ip1")
install_path=/home/user/opt/elasticsearch
cluster_name="Our Search"
index_number_of_shards=20
path_data=/data/d1/index
version=0.20.6
es_heap_master=3000
es_heap_monitor=2000
es_heap_slave=3000
#let's do it!
nodes=( ${slaves[@]} ${monitors[@]} ${masters[@]})
echo "Preparing cluster $cluster_name: ${nodes[@]}"
for node in ${nodes[@]}
do
echo "Preparing node $node"
ssh root@$node "$install_path/current/bin/service/elasticsearch stop
rm -rf $install_path;
mkdir -p $install_path;
cd $install_path;
wget -t 7 --waitretry=14 --random-wait -q http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.tar.gz;
tar -xf $install_path/elasticsearch-${version}.tar.gz;
ln -s $install_path/elasticsearch-${version} $install_path/current;
cd $install_path/current/bin;
wget -t 7 --waitretry=14 --random-wait -q https://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.zip;
unzip -q master.zip;
mv elasticsearch-servicewrapper-master/service . ;
rm -rf elasticsearch-servicewrapper* master.zip*";
echo "Node $node ready!"
done
gateway_expected_nodes=$((${#slaves[@]} + ${#monitors[@]} + ${#masters[@]}))
discovery_zen_ping_unicast_hosts=$(printf ",\"%s\"" "${masters[@]}")
discovery_zen_ping_unicast_hosts=${discovery_zen_ping_unicast_hosts:1}
#for master
for master in ${masters[@]}
do
echo "Installing master $master"
ssh root@$master "echo 'node.name: master ($master)
node.data: false
http.enabled: true
node.master: true
bootstrap.mlockall: true
index.number_of_shards: $index_number_of_shards
cluster.name: $cluster_name
path.data: $path_data
transport.tcp.compress: true
gateway.expected_nodes: $gateway_expected_nodes
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: [$discovery_zen_ping_unicast_hosts]' > $install_path/current/config/elasticsearch.yml"
ssh root@$master "sed -i 's#^\(set.default.ES_HOME\s*=\s*\).*\$#\1$install_path/current#' $install_path/current/bin/service/elasticsearch.conf"
ssh root@$master "sed -i 's#^\(set.default.ES_HEAP_SIZE\s*=\s*\).*\$#\1$es_heap_master#' $install_path/current/bin/service/elasticsearch.conf"
echo "Master $master installed, starting..."
ssh root@$master "$install_path/current/bin/service/elasticsearch start"
echo "Master $master started!"
done
#for slaves
for slave in ${slaves[@]}
do
echo "Installing slave $slave"
ssh root@$slave "echo 'node.name: data ($slave)
node.data: true
http.enabled: false
node.master: false
bootstrap.mlockall: true
index.number_of_shards: $index_number_of_shards
cluster.name: $cluster_name
path.data: $path_data
transport.tcp.compress: true
gateway.expected_nodes: $gateway_expected_nodes
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: [$discovery_zen_ping_unicast_hosts]' > $install_path/current/config/elasticsearch.yml"
ssh root@$slave "sed -i 's#^\(set.default.ES_HOME\s*=\s*\).*\$#\1$install_path/current#' $install_path/current/bin/service/elasticsearch.conf"
ssh root@$slave "sed -i 's#^\(set.default.ES_HEAP_SIZE\s*=\s*\).*\$#\1$es_heap_slave#' $install_path/current/bin/service/elasticsearch.conf"
echo "Slave $slave installed, starting..."
ssh root@$slave "$install_path/current/bin/service/elasticsearch start"
echo "Slave $slave started!"
done
#for monitors
for monitor in ${monitors[@]}
do
echo "Installing monitor $monitor"
ssh root@$monitor "$install_path/current/bin/plugin -install karmi/elasticsearch-paramedic"
ssh root@$monitor "echo 'node.name: monitor ($monitor)
node.data: false
http.enabled: true
node.master: false
bootstrap.mlockall: true
index.number_of_shards: $index_number_of_shards
cluster.name: $cluster_name
path.data: $path_data
transport.tcp.compress: true
gateway.expected_nodes: $gateway_expected_nodes
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: [$discovery_zen_ping_unicast_hosts]' > $install_path/current/config/elasticsearch.yml"
ssh root@$monitor "sed -i 's#^\(set.default.ES_HOME\s*=\s*\).*\$#\1$install_path/current#' $install_path/current/bin/service/elasticsearch.conf"
ssh root@$monitor "sed -i 's#^\(set.default.ES_HEAP_SIZE\s*=\s*\).*\$#\1$es_heap_monitor#' $install_path/current/bin/service/elasticsearch.conf"
echo "Monitor $monitor installed, starting..."
ssh root@$monitor "$install_path/current/bin/service/elasticsearch start"
echo "Monitor $monitor started!"
done