一、Hadoop常用端口说明
端口名称 |
Hadoop2.x |
Hadoop3.x |
NameNode内部通信端口 |
8020 / 9000 |
8020 / 9000 / 9820 |
NameNode HTTP UI |
50070 |
9870 |
MapReduce查看执行任务端口 |
8088 |
8088 |
历史服务器通信端口 |
19888 |
19888 |
二、Hadoop同步文件脚本
#1.新建脚本目录,并配置环境变量(省略)
[delopy@hadoop102 ~]$ mkdir bin
[delopy@hadoop102 ~]$ cd bin
#2.编写Hadoop同步文件脚本
[delopy@hadoop102 bin]$ vim xsync
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
#3.添加执行权限
[delopy@hadoop102 bin]$ chmod +x xsync
三、Hadoop集群启停脚本
#1.编写hadoop集群启停脚本(包含HDFS,Yarn,Historyserver)
[delopy@hadoop102 bin]$ vim myhadoop.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 hadoop集群 ==================="
echo " --------------- 启动 hdfs ---------------"
ssh hadoop102 "/opt/module/hadoop/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh hadoop103 "/opt/module/hadoop/sbin/start-yarn.sh"
echo " --------------- 启动 historyserver ---------------"
ssh hadoop102 "/opt/module/hadoop/bin/mapred --daemon start historyserver"
;;
"stop")
echo " =================== 关闭 hadoop集群 ==================="
echo " --------------- 关闭 historyserver ---------------"
ssh hadoop102 "/opt/module/hadoop/bin/mapred --daemon stop historyserver"
echo " --------------- 关闭 yarn ---------------"
ssh hadoop103 "/opt/module/hadoop/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh hadoop102 "/opt/module/hadoop/sbin/stop-dfs.sh"
;;
*)
echo "Input Args Error..."
;;
esac
#2.添加执行权限
[delopy@hadoop102 bin]$ chmod +x myhadoop.sh
四、查看集群Java进程脚本
#1.编写查看集群java进程脚本
[delopy@hadoop102 bin]$ vim jpsall
#!/bin/bash
for host in hadoop102 hadoop103 hadoop104
do
echo =============== $host ===============
ssh $host jps
done
#2.添加执行权限
[delopy@hadoop102 bin]$ chmod +x jpsall
#3.同步脚本文件到其他机器
[delopy@hadoop102 bin]$ xsync ./*