zookeeper一键启动脚本配置

创建onekey目录

mkdir /export/server/onekey

创建zk目录

mkdir /export/server/onekey/zk

创建脚本文件slave,startzk.sh,stopzk.sh

-rw-r--r--. 1 root root  21 Nov 11 03:46 slave
-rwxr-xr-x. 1 root root 160 Nov 11 03:46 startzk.sh
-rwxr-xr-x. 1 root root 172 Nov 11 03:47 stopzk.sh

slave文件(hosts里配置的)

node01
node02
node03

startzk.sh文件

cat /export/servers/oneKey/zk/slave | while read line
do
{
 echo $line
 ssh $line "source /etc/profile;nohup zkServer.sh start >/dev/nul* 2>&1 &"
}&
wait
done 

stopzk.sh 停止脚本

    cat /export/servers/oneKey/zk/slave | while read line
do
{
 echo $line
 ssh $line "source /etc/profile;jps |grep QuorumPeerMain |cut -c 1-4 |xargs kil* -s 9"
}&
wait
done 

一键启动脚本的环境变量配置

#set onekey env
export OK_HOME=/export/servers/onekey
export PATH=${OK_HOME}/zk:$PATH

zookeeper的环境变量

set zookeeper env
export ZK_HOME=/export/software/zk
export PATH=${ZK_HOME}/bin:$PATH

跨服务器运行命令

ssh hostname "command"

你可能感兴趣的:(zk一键启动脚本)