目录

centos 启动大数据脚本

../../images/weixin_public.png

启动大数据相关环境脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh

# ServerHosts
ServerHosts='vm0101 vm0102 vm0103'

usage() {
    echo "Usage: sh 执行脚本.sh [zookeeper|kafka|flink] [start|stop|restart|status]"
    exit 1
}

# ZooKeeper Cluster Start
FunctionZK(){
	echo "--------正在 $1 Zookeeper Cluster--------"
	for zoo in $ServerHosts
	do
	   	ssh $zoo "source /etc/profile;/home/bigdata/zookeeper/bin/zkServer.sh $1"
		if [ $1 == 'stop' ]; then
			echo 从节点 $zoo 停止zookeeper...[done]
		else
			echo 从节点 $zoo 启动zookeeper...[done]
		fi
	sleep 1
	done
}

# Kafka Cluster
FunctionKafka(){
	
	echo "--------正在 $1 Kafka Cluster--------"
	for kafka in $ServerHosts
	do
		if [ $1 == 'stop' ]; then
			ssh $kafka "source /etc/profile;/home/bigdata/kafka/bin/kafka-server-stop.sh"
		else
			ssh $kafka "source /etc/profile;/home/bigdata/kafka/bin/kafka-server-start.sh -daemon /home/bigdata/kafka/config/server.properties"
		fi
	echo 从节点 $kafka $1 kafka ...[done]
	sleep 1
	done
}

# Flink Cluster
FunctionFlink(){
	echo "--------正在 $1 Flink Cluster--------"
	if [ $1 == 'stop' ]; then
		ssh vm0201 "source /etc/profile;/home/bigdata/flink/bin/stop-cluster.sh"
	else
		ssh vm0201 "source /etc/profile;/home/bigdata/flink/bin/start-cluster.sh"
	fi
}

case $1 in
	"zookeeper")
		FunctionZK $2
		;;
	"kafka")
		FunctionKafka $2
		;;
	"flink")
		FunctionFlink $2
		;;
	*)
		usage
		;;
esac