Zookeeper集群一键启动
在 /usr/local/bin目录下创建脚本 zk
#!/bin/sh
case $1 in
"start"){
for i in centos3 centos4 centos5
do
echo "********$i --> zkServer.sh start **********"
ssh $i 'source /etc/profile; /opt/module/zookeeper/bin/zkServer.sh start;exit'
done
};;
"stop"){
for i in centos3 centos4 centos5
do
echo "********$i --> zkServer.sh stop **********"
ssh $i 'source /etc/profile; /opt/module/zookeeper/bin/zkServer.sh stop;exit'
done
};;
"status"){
for i in centos3 centos4 centos5
do
echo "********$i --> zkServer.sh status **********"
ssh $i 'source /etc/profile; /opt/module/zookeeper/bin/zkServer.sh status;exit'
done
};;
"restart"){
for i in centos3 centos4 centos5
do
echo "********$i --> zkServer.sh restart **********"
ssh $i 'source /etc/profile; /opt/module/zookeeper/bin/zkServer.sh restart;exit'
done
};;
esac
可在任何位置执行该脚本
启动、查看状态、关闭zookeeper集群:
zk start
jps脚本查看执行进程
zk status
zk stop
kafka集群启动关闭脚本
/usr/local/bin下编写脚本 kk
#!/bin/sh
case $1 in
"start"){
for i in centos3 centos4 centos5
do
echo "******** $i --> kafka-server-start.sh **********"
ssh $i 'source /etc/profile;sh /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties'
done
};;
"stop"){
for i in centos3 centos4 centos5
do
echo "******** $i --> kafka-server-stop.sh **********"
ssh $i 'source /etc/profile; /opt/module/kafka/bin/kafka-server-stop.sh /opt/module/kafka/config/server.properties;exit'
done
};;
esac
启动kafka集群
查看启动进程
关闭kafka
xjps集群查看java进程脚本
#!/bin/sh
for i in centos3 centos4 centos5
do
echo "============ $i -> jps============"
ssh $i '/opt/module/jdk1.8.0_271/bin/jps'
done
/opt/module/jdk1.8.0_271为jdk安装目录
直接使用 xjps
执行脚本。
本文脚本在集群中正常执行的前提
-
修改集群中每个主机的/etc/hosts文件
-
须生成rsa密钥,配置给从机(关键)
可以参考xsync同步脚本的使用。 -
sync脚本
#!/bin/sh
# 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount!=4)); then
echo Usage: $0 filename servername startno endno
exit;
fi
# 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname
# 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir
# 获取当前用户名称
user=`whoami`
# 获取hostname及起止号
slave=$2
startline=$3
endline=$4
# 循环
for((host=$startline; host<=$endline; host++)); do
echo $pdir/$fname $user@$slave$host:$pdir
echo ==================$slave$host==================
rsync -rvl $pdir/$fname $user@$slave$host:$pdir
done
调用形式:xsync 文件或目录 centos 4 5
脚本文件存放目录:/usr/local/bin