准备工作以及安装Hadoop之前的操作和Hadoop2.X的安装相同,在我上一篇博客中,这里不做过多介绍
https://www.cnblogs.com/lmandcc/p/15306163.html
1. 写一些关键脚本,利于后续集群使用
1.1集群分发脚本xsync
cd /bin/
vim xsyn
#!/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
1.2 查看节点Java进程脚本 jpsall
vim jpsall
#!/bin/bash
for i in hadoop102 hadoop103 hadoop104
do
echo =============== $i ===============
ssh $i "$*" "/usr/local/soft/jdk1.8.0_212/bin/jps"
done
1.3 控制Hadoop启动和停止脚本
vim myhadoop
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 hadoop集群 ==================="
echo " --------------- 启动 hdfs ---------------"
ssh hadoop102 "/usr/local/soft/hadoop-3.1.3/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh hadoop103 "/usr/local/soft/hadoop-3.1.3/sbin/start-yarn.sh"
echo " --------------- 启动 historyserver ---------------"
ssh hadoop102 "/usr/local/soft/hadoop-3.1.3/bin/mapred --daemon start his
toryserver";;
"stop")
echo " =================== 关闭 hadoop集群 ==================="
echo " --------------- 关闭 historyserver ---------------"
ssh hadoop102 "/usr/local/soft/hadoop-3.1.3/bin/mapred --daemon stop hist oryserver"
echo " --------------- 关闭 yarn ---------------"
ssh hadoop103 "/usr/local/soft/hadoop-3.1.3/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh hadoop102 "/usr/local/soft/hadoop-3.1.3/sbin/stop-dfs.sh"
;;
*)
echo "Input Args Error..."
;;
esac
注意:这里每个脚本都需要修改读写权限:chmod 777 脚本名称
2. 将Hadoop3.1.3用xftp导入Hadoop102中
3. 解压Hadoop文件
tar -zxvf /usr/local/module/hadoop-3.1.3.tar.gz -C /usr/local/soft
4. 配置环境变量
export JAVA_HOME=/usr/local/soft/jdk1.8.0_212
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_HOME=/usr/local/soft/hadoop-3.1.3
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export REDIS_HOME=/usr/local/soft/redis/
export PATH=$PATH:$REDIS_HOME/bin
5. 集群配置搭建
1) 集群部署规划
备注:NameNode和SecondaryNameNode不要安装在同一台服务器
备注:ResourceManager也很消耗内存,不要和NameNode、SecondaryNameNode配置在同一台机器上。
hadoop102 |
hadoop103 |
hadoop104 |
|
HDFS
|
NameNode DataNode |
DataNode |
SecondaryNameNode DataNode |
YARN |
NodeManager |
ResourceManager NodeManager |
NodeManager |
2)配置集群
cd /usr/local/soft/hadoop-3.1.3/etc/hadoop
(a) 核心配置文件 core.site.xml
<!-- 指定NameNode的地址 -->
>
>fs.defaultFS
>hdfs://hadoop102:8020
</property>
<!-- 指定hadoop数据的存储目录 -->
>
>hadoop.tmp.dir
>/usr/local/soft/hadoop-3.1.3/data
</property>
</configuration>
(b)HDFS文件 hdfs-site.xml
"1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
>
<!-- nn web端访问地址-->
>
>dfs.namenode.http-address
>hadoop102:9870
</property>
<!-- 2nn web端访问地址-->
>
>dfs.namenode.secondary.http-address
>hadoop104:9868
</property>
>
>dfs.permissions.enabled
>false
</property>
>
>
dfs.client.block.write.replace-datanode-on-failure.enable
</name>
>true
</property>
>
>
dfs.client.block.write.replace-datanode-on-failure.policy
</name>
>never
</property>
>
>dfs.webhdfs.enabled
>true
</property>
</configuration>
(c)YARN配置文件 yarn-site.xml
<!-- Site specific YARN configuration properties -->
<!-- 指定MR走shuffle -->
>
>yarn.nodemanager.aux-services
>mapreduce_shuffle
</property>
<!-- 指定ResourceManager的地址-->
>
>yarn.resourcemanager.hostname
>hadoop103
</property>
<!-- 环境变量的继承 -->
>
>yarn.nodemanager.env-whitelist
>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLAS
SPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
<!-- 开启日志聚集功能 -->
>
>yarn.log-aggregation-enable
>true
</property>
<!-- 设置日志聚集服务器地址 -->
>
>yarn.log.server.url
>http://hadoop102:19888/jobhistory/logs
</property>
<!-- 设置日志保留时间为7天 -->
>
>yarn.log-aggregation.retain-seconds
>604800
</property>
</configuration>
(d)MapReduce配置文件 mapred-site.xml
在这里需要重命名mapred-site.xml.template
命令:mv mapred-site.xml.template mapred-site.xml
"1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
>
<!-- 指定MapReduce程序运行在Yarn上 -->
>
>mapreduce.framework.name
>yarn
</property>
<!-- 历史服务器端地址 -->
>
>mapreduce.jobhistory.address
>hadoop102:10020
</property>
<!-- 历史服务器web端地址 -->
>
>mapreduce.jobhistory.webapp.address
>hadoop102:19888
</property>
</configuration>
(e)配置workers
(f)在/hadoop/sbin路径下:将start-dfs.sh,stop-dfs.sh两个文件顶部添加以下参数
HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
(g)start-yarn.sh,stop-yarn.sh顶部也需添加以下
YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root
6.分发Hadoop给剩余节点
xsync /usr/local/soft/hadoop-3.1.3
7. 启动集群
如果集群是第一次启动,需要在hadoop102节点格式化NameNode
使用myhadoop start 启动集群
使用jpsall查看Java进程
如果配置文件不出错的话,应该和我Java进程相同
8.停止Hadoop集群
myhadoop stop