Zookeeper脚本
vim myzookeeper.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit;
fi
case $1 in
"start")
hosts=(node01 node02 node03)
for host in ${hosts[*]}
do
echo "-----------------启动${host} Zookeeper----------------"
ssh $host "/opt/soft/zookeeper-3.7.1/bin/zkServer.sh start"
done
exit 0
;;
"stop")
hosts=(node01 node02 node03)
for host in ${hosts[*]}
do
echo "-----------------停止${host} Zookeeper----------------"
ssh $host "/opt/soft/zookeeper-3.7.1/bin/zkServer.sh stop"
done
exit 0
;;
"status")
hosts=(node01 node02 node03)
for host in ${hosts[*]}
do
echo "-----------------停止${host} Zookeeper----------------"
ssh $host "/opt/soft/zookeeper-3.7.1/bin/zkServer.sh status"
done
exit 0
;;
*)
echo "Input Args Error.."
;;
esac
Hadoop脚本
vim myhadoop.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit;
fi
case $1 in
"start")
echo "=================启动Hadoop集群==============="
echo "-----------------启动hdfs----------------"
ssh node01 "/opt/soft/hadoop-3.3.3/sbin/start-dfs.sh"
echo "-----------------启动yarn----------------"
ssh node02 "/opt/soft/hadoop-3.3.3/sbin/start-yarn.sh"
echo "-----------------启动historyserver----------------"
ssh node01 "/opt/soft/hadoop-3.3.3/bin/mapred --daemon start historyserver"
;;
"stop")
echo "=================关闭Hadoop集群==============="
echo "-----------------关闭historyserver----------------"
ssh node01 "/opt/soft/hadoop-3.3.3/bin/mapred --daemon stop historyserver"
echo "-----------------关闭yarn----------------"
ssh node02 "/opt/soft/hadoop-3.3.3/sbin/stop-yarn.sh"
echo "-----------------关闭hdfs----------------"
ssh node01 "/opt/soft/hadoop-3.3.3/sbin/stop-dfs.sh"
;;
*)
echo "Input Args Error.."
;;
esac
Hive脚本
#!/bin/bash
#创建Hive启动日志
HIVE_LOG_DIR=$HIVE_HOME/logs
if [ ! -d $HIVE_LOG_DIR ]
then
mkdir -p $HIVE_LOG_DIR
fi
#检查进程是否运行正常,参数 1 为进程名,参数 2 为进程端口
function check_process()
{
pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print $2}')
ppid=$(netstat -nltp 2>/dev/null | grep $2 | awk '{print $7}' | cut -d '/' -f 1)
echo $pid
[[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1
}
function hive_start()
{
metapid=$(check_process HiveMetastore 9083)
cmd="nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
[ -z "$metapid" ] && eval $cmd || echo "Metastroe 服务已启动"
server2pid=$(check_process HiveServer2 10000)
cmd="nohup hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &"
[ -z "$server2pid" ] && eval $cmd || echo "HiveServer2 服务已启动"
}
function hive_stop()
{
metapid=$(check_process HiveMetastore 9083)
[ "$metapid" ] && kill $metapid || echo "Metastore 服务未启动"
server2pid=$(check_process HiveServer2 10000)
[ "$server2pid" ] && kill $server2pid || echo "HiveServer2 服务未启动"
}
case $1 in
"start")
hive_start
;;
"stop")
hive_stop
;;
"restart")
hive_stop
sleep 2
hive_start
;;
"status")
metapid=$(check_process HiveMetastore 9083)
server2pid=$(check_process HiveServer2 10000)
[ "$metapid" ] && echo "Metastore 服务运行正常" || echo "Metastore 服务运行异常"
[ "$server2pid" ] && echo "HiveServer2 服务运行正常" || echo "HiveServer2 服务运行异常"
;;
*)
echo Invalid Args!
echo 'Usage: '$(basename $0)' start|stop|restart|status'
;;
esac
spark脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit;
fi
case $1 in
"start")
echo "-----------------启动SparkHistory----------------"
ssh node01 "/opt/soft/spark-3.2.1-yarn/sbin/start-history-server.sh"
;;
"stop")
echo "-----------------停止SparkHistory----------------"
ssh node01 "/opt/soft/spark-3.2.1-yarn/sbin/stop-history-server.sh"
;;
*)
echo "Input Args Error.."
;;
esac
hbase脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit;
fi
case $1 in
"start")
echo "-----------------启动HBase----------------"
ssh node03 "/opt/soft/hbase-2.4.12/bin/start-hbase.sh "
;;
"stop")
echo "-----------------停止HBase----------------"
ssh node03 "/opt/soft/hbase-2.4.12/bin/stop-hbase.sh "
;;
*)
echo "Input Args Error.."
;;
esac