1. 快速启停Hadoop集群
#!/bin/bash
if [ $# -lt 1 ]
then
echo "没有输入参数,当前参数个数为0!"
exit ;
fi
hdfs_host=node-1
yarn_host=node-2
H_M=`echo $HADOOP_HOME`
if [ -z $H_M ]
then
echo "HADOOP_HOME未设置,程序停止!"
exit ;
fi
function my_Start()
{
echo " =================== 启动 hadoop 集群 ==================="
echo " --------------- 启动 hdfs ---------------"
ssh $hdfs_host "$H_M/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh $yarn_host "$H_M/sbin/start-yarn.sh"
echo " --------------- 启动 historyserver ---------------"
ssh $hdfs_host "$H_M/bin/mapred --daemon start historyserver"
}
function my_Stop()
{
echo " =================== 关闭 hadoop 集群 ==================="
echo " --------------- 关闭 historyserver ---------------"
ssh $hdfs_host "$H_M/bin/mapred --daemon stop historyserver"
echo " --------------- 关闭 yarn ---------------"
ssh $yarn_host "$H_M/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh $hdfs_host "$H_M/sbin/stop-dfs.sh"
}
case $1 in
"start")
my_Start
;;
"stop")
my_Stop
;;
"restart")
my_Stop
my_Start
;;
*)
echo "输入的参数不合法,目前仅支持启动 | 停止 | 重启!"
;;
esac
2. 快速同步文件[增量同步]
#!/bin/bash
if [ $# -lt 1 ]
then
echo "目前参数为0,没有传参!"
exit;
fi
c_host=`hostname`
for host in node-1 node-2 node-3
do
echo "检测节点: $host"
if [ $c_host = $host ]
then
echo ">>>>>>>>>>>>>>跳过当前主机:$c_host !<<<<<<<<<<<<<<<<"
continue
fi
echo ====================发送到: $host ====================
for file in $@
do
if [ -e $file ]
then
pdir=$(cd -P $(dirname $file); pwd)
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file "文件不存在!"
fi
done
done
3. 查看所有节点上的 jps 进程
#!/bin/bash
for host in node-1 node-2 node-3
do
echo =============== $host ===============
ssh $host jps
done
4. 快速启动hive3.x版本
#!/bin/bash
if [ $1 = start ];
then
nohup $HIVE_HOME/bin/hive --service metastore 2>&1>> $HOME/logs/hive-3.1.2/metastore.out &
nohup $HIVE_HOME/bin/hive --service hiveserver2 2>&1>> $HOME/logs/hive-3.1.2/hiveserver2.out &
else
hive_id=`ps -ef | grep RunJar | grep -v grep | awk '{print $2}'`
for id in $hive_id
do
kill -9 $id
echo "killed $id"
done
fi
|