最近学习大数据 每次到要启动很多东西 每次一个个启动 特别费劲 于是写了一个脚本 一起启动
脚本如下
脚本的原理是检测是否 参数包含要启动类目
realtime-0317.sh hdfs hbase 包含hdfs hbase 于是 就去启动 hdfs hbase
#!/bin/bash
echo -e " 欢迎使用实时项目配套脚本,这个脚本可以让你直接启动\033[41;33m hdfs hbase zk kafka canal jartomcat \033[0m 你可以根据自己的选择启动 !"
## 需要执行的服务器 单机的话是102
mHost=hadoop102
## 全部需要执行
mHostList[0]=hadoop102
mHostList[1]=hadoop103
mHostList[2]=hadoop104
out_no="参数不对,大侠请重新来过!"
######################################### HDFS ######################################
# 启动HDFS
function hdfs_start()
{
for host in $mHost ; do
echo "在 $host 启动hdfs集群"
ssh $host "source /etc/profile; start-dfs.sh"
done
}
# 关闭HDFS
function hdfs_stop()
{
for host in $mHost ; do
echo "在 $host 关闭hdfs集群"
ssh $host "source /etc/profile; stop-dfs.sh"
done
}
# Hdfs
function Hdfs(){
flot=1;
while [[ $flot -eq 1 ]]; do
read -p "请问是否需要启动或者关闭hdfs? yes/no/un " hdfs
echo $hdfs
case $hdfs in
"yes")
hdfs_start;
let flot++;
;;
"no")
hdfs_stop;
let flot++;
;;
"un")
echo "不执行任何操作"
let flot++;
;;
*)
echo $out_no
echo '参数只能是 yes|no|un'
;;
esac
done
}
######################################### hbase ######################################
# 启动hbase
function hbase_start()
{
for host in $mHost ; do
echo "在 $host 启动hdfs集群"
ssh $host "source /etc/profile; cd $HBASE_HOME; bin/start-hbase.sh"
done
}
# 关闭hbase
function hbase_stop()
{
for host in $mHost ; do
echo "在 $host 关闭hdfs集群"
ssh $host "source /etc/profile; cd $HBASE_HOME; bin/stop-hbase.sh"
done
}
# hbase
function Hbase(){
flot=1;
while [[ $flot -eq 1 ]]; do
read -p "请问是否需要启动或者关闭Hbase? yes/no/un " hbase
echo $hbase
case $hbase in
"yes")
hbase_start;
let flot++;
;;
"no")
hbase_stop;
let flot++;
;;
"un")
echo "不执行任何操作"
let flot++;
;;
*)
echo $out_no
echo '参数只能是 yes|no|un'
;;
esac
done
}
######################################### zk ######################################
# 启动zk
function zk_start()
{
for host in hadoop102 hadoop103 hadoop104 ; do
echo "在 $host 启动zk服务"
ssh $host /opt/module/zookeeper-3.5.7/bin/zkServer.sh start
done
}
# 关闭zk
function zk_stop()
{
for host in hadoop102 hadoop103 hadoop104 ; do
echo "在 $host 关闭zk服务"
ssh $host /opt/module/zookeeper-3.5.7/bin/zkServer.sh stop
done
}
# ZK
function Zk(){
flot=1;
while [[ $flot -eq 1 ]]; do
read -p "请问是否需要启动或者关闭zk? yes/no/un " zk
echo $zk
case $zk in
"yes")
zk_start;
let flot++;
;;
"no")
zk_stop;
let flot++;
;;
"un")
echo "不执行任何操作"
let flot++;
;;
*)
echo $out_no
echo '参数只能是 yes|no|un'
;;
esac
done
}
######################################### kafka ######################################
# 启动kafka
function kafka_start()
{
for host in hadoop102 hadoop103 hadoop104 ; do
echo "在 $host 启动kafka服务"
ssh $host /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties
done
}
# 关闭kafka
function kafka_stop()
{
for host in hadoop102 hadoop103 hadoop104 ; do
echo "在 $host 关闭kfka服务"
ssh $host /opt/module/kafka/bin/kafka-server-stop.sh
done
}
# kafka
function Kafka(){
flot=1;
while [[ $flot -eq 1 ]]; do
read -p "请问是否需要启动或者关闭kafka? yes/no/un " kafka
echo $kafka
case $kafka in
"yes")
kafka_start;
let flot++;
;;
"no")
kafka_stop;
let flot++;
;;
"un")
echo "不执行任何操作"
let flot++;
;;
*)
echo $out_no
echo '参数只能是 yes|no|un'
;;
esac
done
}
######################################### canal ######################################
# 启动canal
function canal_start()
{
for host in $mHost ; do
echo "在 $host 启动canal服务器"
ssh $host "source /etc/profile; cd /opt/module/canal; bin/startup.sh"
done
}
# 关闭canal
function canal_stop()
{
for host in $mHost ; do
echo "在 $host 关闭canal服务器"
ssh $host "source /etc/profile; cd /opt/module/canal; bin/stop.sh"
done
}
# canal
function Canal(){
flot=1;
while [[ $flot -eq 1 ]]; do
read -p "请问是否需要启动或者关闭canal? yes/no/un " canal
echo $canal
case $canal in
"yes")
canal_start;
let flot++;
;;
"no")
canal_stop;
let flot++;
;;
"un")
echo "不执行任何操作"
let flot++;
;;
*)
echo $out_no
echo '参数只能是 yes|no|un'
;;
esac
done
}
# hdfs hbase zk kafka canal jartomcat
# 判断传递进来的参数 是否包含hdfs
if [[ $* =~ "hdfs" ]]; then
Hdfs;
echo "包含Hdfs"
fi
# 判断传递进来的参数 是否包含zk
if [[ $* =~ "zk" ]]; then
Zk;
echo "包含zk"
fi
# 判断传递进来的参数 是否包含hbase
if [[ $* =~ "hbase" ]]; then
Hbase;
echo "包含hbase"
fi
# 判断传递进来的参数 是否包含kafka
if [[ $* =~ "kafka" ]]; then
Kafka;
echo "包含kafka"
fi
# 判断传递进来的参数 是否包含canal
if [[ $* =~ "canal" ]]; then
Canal;
echo "包含canal"
fi
# 判断传递进来的参数 是否包含jartomcat
if [[ $* =~ "jartomcat" ]]; then
Jartomcat;
echo "包含jartomcat"
fi