1、启动elasticsearch的脚本
1.1 先创建一个文本
touch start_elasticsearch
2.2 将下面内容粘贴到文本中
echo START es6@148
/home/cloud/platform/elasticsearch-6.7.1/bin/elasticsearch -d
echo START es6@149
ssh cloud32 "/home/cloud/platform/elasticsearch-6.7.1/bin/elasticsearch -d"
echo START es6@150
ssh cloud33 "/home/cloud/platform/elasticsearch-6.7.1/bin/elasticsearch -d"
echo START es6@151
ssh cloud34 "/home/cloud/platform/elasticsearch-6.7.1/bin/elasticsearch -d"
#echo START es6@233
#ssh cloud35 "/home/cloud/platform/elasticsearch-6.7.1/bin/elasticsearch -d"
2.3 赋予文本权限
chmod +x start_elasticsearch
3.4 执行文本
./start_elasticsearch
2、停止elasticsearch的脚本
2.1 先创建一个文本
touch stop_elasticsearch
2.2 将下面内容粘贴到文本中
#!/bin/bash
hosts=(centos03 centos04 centos05 centos06 centos07)
for host in ${hosts[@]}
do
ssh $host "source /etc/profile;ps -ef | grep elasticsearch | grep -v grep | awk '\$0~/es6.7.1_29200/ {print \$2}' | xargs kill -9"
if [ $? -eq 0 ]; then
echo -e "关闭$host\033[32m[成功]\033[0m!"
else
echo -e "关闭$host\033[31m[失败]\033[0m!"
fi
done
解释:
hosts 里面是服务器的hostname,一共五台服务器。
| awk ‘$0~/es6.7.1_29200/ {print $2}’ | : 通过ps -ef | grep es6.7.1_29200,是查找需要kill掉的es查找的id,然后kill掉。
2.3 赋予文本权限
chmod +x stop_elasticsearch
3.4 执行文本
./stop_elasticsearch