Bootstrap

shell脚本实现一键启动集群的zookeeper和hadoop

因为我的集群是高可用的,所以基本上都是和zookeeper整合的。然而zookeeper的启动又需要一个机器一个机器的启动,非常麻烦。所以我就产生了写一个shell脚本来启动集群。不说废话,直接上脚本。

#!/bin/bash
#一键启动集群
for i in {"hadoop01","hadoop02","hadoop03"};
do
	echo "-----$1 $i zookeeper-------"
	ssh $i "source /etc/profile;/export/servers/zookeeper-3.4.9/bin/zkServer.sh $1"
done
sleep 5
for j in {"hadoop01","hadoop02","hadoop03"};
do
	echo "------$j status-------"
	ssh $j "source /etc/profile;/export/servers/zookeeper-3.4.9/bin/zkServer.sh status"
done

sleep 5
var='-all.sh'
var1=$1$var

echo "-----$k hadoop $1-----"
ssh hadoop01 "sh /export/servers/hadoop-2.6.0-cdh5.14.0/sbin/$var1"

第6行和第12行的source /etc/profile 不要换成sh,否则出现结果二。

1.结果一之启动结果:

;