Zookeeper集群启动停止脚本
在/home/hadoop/bin目录下创建脚本zk.sh
#! /bin/bash
case $1 in
"start"){
for i in bigdata02 bigdata03 bigdata04
do
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
done
};;
"stop"){
for i in bigdata02 bigdata03 bigdata04
do
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
done
};;
"status"){
for i in bigdata02 bigdata03 bigdata04
do
ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh status"
done
};;
esac
集群日志生成启动脚本
在/home/hadoop/bin目录下创建脚本lg.sh
#! /bin/bash
for i in bigdata02 bigdata03
do
ssh $i "java -classpath /opt/module/log-collector-1.0-SNAPSHOT-jar-with-dependencies.jar com.bigdata.appclient.AppMain $1 $2 > /dev/null 2 > &1 &"
done
集群时间同步修改脚本
在/home/hadoop/bin目录下创建脚本dt.sh
#!/bin/bash
for i in bigdata02 bigdata03 bigdata04
do
echo "========== $i =========="
ssh -t $i "sudo date -s $1"
done
ssh -t 通常用于ssh远程执行sudo命令
集群所有进程查看脚本
在/home/hadoop/bin目录下创建脚本xcall.sh
#! /bin/bash
for i in bigdata02 bigdata03 bigdata04
do
echo --------- $i ----------
ssh $i "$*"
done
Kafka集群启动停止脚本
在/home/hadoop/bin目录下创建脚本kf.sh
#! /bin/bash
case $1 in
"start"){
for i in bigdata02 bigdata03 bigdata04
do
echo " --------启动 $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties "
done
};;
"stop"){
for i in bigdata02 bigdata03 bigdata04
do
echo " --------停止 $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh stop"
done
};;
esac
日志采集Flume启动停止脚本
在/home/hadoop/bin目录下创建脚本f1.sh
#! /bin/bash
case $1 in
"start"){
for i in bigdata02 bigdata03
do
echo " --------启动 $i 采集flume-------"
ssh $i "nohup /opt/module/flume/bin/flume-ng agent --conf-file /opt/module/flume/conf/file-flume-kafka.conf --name a1 -Dflume.root.logger=INFO,LOGFILE > /opt/module/flume/test1 2 > &1 &"
done
};;
"stop"){
for i in bigdata02 bigdata03
do
echo " --------停止 $i 采集flume-------"
ssh $i "ps -ef | grep file-flume-kafka | grep -v grep |awk '{print \$2}' | xargs kill"
done
};;
esac
awk:默认分隔符为空格
xargs:表示取出前面命令运行的结果,作为后面命令的输入参数
日志消费Flume启动停止脚本
在/home/hadoop/bin目录下创建脚本f2.sh
#! /bin/bash
case $1 in
"start"){
for i in bigdata04
do
echo " --------启动 $i 消费flume-------"
ssh $i "nohup /opt/module/flume/bin/flume-ng agent --conf-file /opt/module/flume/conf/kafka-flume-hdfs.conf --name a1 -Dflume.root.logger=INFO,LOGFILE >/opt/module/flume/log.txt 2>&1 &"
done
};;
"stop"){
for i in bigdata04
do
echo " --------停止 $i 消费flume-------"
ssh $i "ps -ef | grep kafka-flume-hdfs | grep -v grep |awk '{print \$2}' | xargs kill"
done
};;
esac
采集通道启动/停止脚本
在/home/hadoop/bin目录下创建脚本cluster.sh
#! /bin/bash
case $1 in
"start"){
echo " -------- 启动 集群 -------"
echo " -------- 启动 hadoop集群 -------"
/opt/module/hadoop-2.7.2/sbin/start-dfs.sh
ssh bigdata03 "/opt/module/hadoop-2.7.2/sbin/start-yarn.sh"
#启动 Zookeeper集群
zk.sh start
sleep 4s;
#启动 Flume采集集群
f1.sh start
#启动 Kafka采集集群
kf.sh start
sleep 6s;
#启动 Flume消费集群
f2.sh start
};;
"stop"){
echo " -------- 停止 集群 -------"
#停止 Flume消费集群
f2.sh stop
#停止 Kafka采集集群
kf.sh stop
sleep 6s;
#停止 Flume采集集群
f1.sh stop
#停止 Zookeeper集群
zk.sh stop
echo " -------- 停止 hadoop集群 -------"
ssh bigdata03 "/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh"
/opt/module/hadoop-2.7.2/sbin/stop-dfs.sh
};;
esac