elasticsearch集群一键部署安装

1.前提条件

机器已经配置ssh无密码登录

2.安装包制作

到官网下载elasticsearch的安装包,根据下面的要求修改配置,并且替换掉。(测试安装包为elasticsearch-2.3.4)

重新打包成.tar.gz。如果安装包不一致,脚本也要做相应的修改。

elasticsearch.yml

 把所有的都注释掉,只保留下面几个,不知道为何,请在每行前面加上一个空格,注意保存字符格式为utf-8

 cluster.name: escluster

 node.name: xx

 path.data: /data/es

 network.host: xx

 discovery.zen.ping.unicast.hosts: ["xx","xx","xx"]

 discovery.zen.minimum_master_nodes: 2

把上面的内容更换如下:

 cluster.name: escluster

 shNameHost

 path.data: shESDIR

 shNetHost

 discovery.zen.ping.unicast.hosts: [shHost]

 discovery.zen.minimum_master_nodes: 2

3.一键安装脚本编写

新增配置文件conf.properties,内容如下

#安装目录install_dir=/usr/local/tinstall

#es数据目录es_dir=/data/es#es节点es_nodes=node1 node2 node3

添加安装脚本install-es.sh,内容如下:

#!/bin/bash

file_name="./conf/conf.properties"

#安装目录
install_dir=`cat ${file_name} | grep install_dir`
install_dir=${install_dir#*=}
#es数据目录
es_dir=`cat ${file_name} | grep es_dir`
es_dir=${es_dir#*=}
#es节点
es_nodes=`cat ${file_name} | grep es_nodes`
es_nodes=${es_nodes#*=}
home=`env | grep ^HOME= | cut -c 6-`
this_host=`hostname`
mkdir_cmd="mkdir ${install_dir}"
es_config="${home}/elasticsearch-2.3.4/config/"
adduser="adduser es"
chownes="chown es:es -R ${install_dir}/elasticsearch-2.3.4"
rmtmpes="rm -rf ${home}/elasticsearch-2.3.4"

echo "Elasticsearch开始安装..."
echo "${this_host}节点解压zookeeper..."
tar -xzvf ./app/elasticsearch-2.3.4.tar.gz -C  $home
hosts=""
for node in ${es_nodes[*]}
do
hosts=${hosts}"\"${node}\","
done
echo ${es_config}
sed -i "s/shHosts/${hosts%?}/g" ${es_config}elasticsearch.yml
sed -i "s/shESDIR/${es_dir//\//\\/}/g" ${es_config}elasticsearch.yml
node_value="shNameHost"
net_value="shNetHost"
for node in ${es_nodes[*]}
do
echo $node
sed -i "s/${node_value}/node.name: ${node}/g" ${es_config}elasticsearch.yml
sed -i "s/${net_value}/network.host: ${node}/g" ${es_config}elasticsearch.yml
node_value="node.name: ${node}"
net_value="network.host: ${node}"
if test "$node" == "$this_host"
then
$mkdir_cmd
cp -r ${home}/elasticsearch-2.3.4 ${install_dir}
$adduser
$chownes
else
echo "${node}节点安装es..."
ssh -t -p 22 root@$node $mkdir_cmd
scp -r ${home}/elasticsearch-2.3.4 ${node}:${install_dir}/
ssh -t -p 22 root@$node $adduser
ssh -t -p 22 root@$node $chownes
fi
done
$rmtmpes
echo "安装es成功!"

编写脚本完成后,为脚本授权chmod +x install-es.sh

运行./install-es.sh



你可能感兴趣的:(elasticsearch,shell)