1、先创建一个文件存储脚本:
mkdir elasticsearch
mv elasticsearch/ elastic
2、进入该文件夹:
cd elastic
3、创建脚本:
touch elastic-stop.sh
4、添加权限:
chmod u+x elastic-stop.sh
5、编写脚本:
vim elastic-stop.sh
6、脚本内容如下:
#!/bin/sh
#######################################
##一键启动或关闭es集群
##author:July
##date:2019-08-30
#######################################
#ps -aux | grep org.elasticsearch.bootstrap.Elasticsearch | awk -F " " ‘{print $2}’ | xargs kill -9
USER=hadoop01
cat elastic-host.txt(写绝对路径) | while read host
do
##完成远程节点进程的关闭
nohup ssh “
U
S
E
R
"
@
"
{USER}"@"
USER"@"{host}” “ps -aux | grep org.elasticsearch.bootstrap.Elasticsearch | awk -F” " ‘{print $2}’ | xargs kill -9" >dev/null 2>&1 &
done
7、要杀死的进程列表,在同样文件下创建文件
vim elastic-host.txt
内容:
hadoop01
hadoop02
hadoop03
8、脚本调试查看命令:
bash -x elastic-stop.sh
9、执行脚本:直接执行就可以了