vim /etc/hostname # 修改主機名稱
vim /etc/hosts # 修改主機host映射
# 關閉防火墻
systemctl stop firewalld
systemctl disable firewalld.service
安裝hadoop
上傳 hadoop-3.2.4.tar.gz 到/opt/software/
tar -zxvf hadoop-3.2.4.tar.gz -C /opt/module/
mv hadoop-3.2.4 hadoop
sudo vim /etc/profile.d/my_env.sh
添加hadoop環(huán)境變量
#HADOOP_HOME
export HADOOP_HOME=/opt/module/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
source /etc/profile.d/my_env.sh
核心配置文件
core-site.xml配置
cd $HADOOP_HOME/etc/hadoop
vim core-site.xml
文件內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop102:8020</value>
</property>
<!-- 指定hadoop數(shù)據(jù)的存儲目錄 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/module/hadoop/data</value>
</property>
<!-- 配置HDFS網頁登錄使用的靜態(tài)用戶為qani -->
<property>
<name>hadoop.http.staticuser.user</name>
<value>qani</value>
</property>
<!-- 配置該qani(superUser)允許通過代理訪問的主機節(jié)點 -->
<property>
<name>hadoop.proxyuser.qani.hosts</name>
<value>*</value>
</property>
<!-- 配置該qani(superUser)允許通過代理用戶所屬組 -->
<property>
<name>hadoop.proxyuser.qani.groups</name>
<value>*</value>
</property>
<!-- 配置該qani(superUser)允許通過代理的用戶-->
<property>
<name>hadoop.proxyuser.qani.users</name>
<value>*</value>
</property>
</configuration>
hdfs-site.xml配置
文件內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- nn web端訪問地址-->
<property>
<name>dfs.namenode.http-address</name>
<value>hadoop102:9870</value>
</property>
<!-- 2nn web端訪問地址-->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop104:9868</value>
</property>
<!-- 測試環(huán)境指定HDFS副本的數(shù)量1 -->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
yarn-site.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定MR走shuffle -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<!-- 指定ResourceManager的地址-->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop103</value>
</property>
<!-- 環(huán)境變量的繼承 -->
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
</property>
<!--yarn單個容器允許分配的最大最小內存 -->
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>512</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>4096</value>
</property>
<!-- yarn容器允許管理的物理內存大小 -->
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>4096</value>
</property>
<!-- 關閉yarn對物理內存和虛擬內存的限制檢查 -->
<property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
<!-- 開啟日志聚集功能 -->
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<!-- 設置日志聚集服務器地址 -->
<property>
<name>yarn.log.server.url</name>
<value>http://hadoop102:19888/jobhistory/logs</value>
</property>
<!-- 設置日志保留時間為7天 -->
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>604800</value>
</property>
</configuration>
mapred-site.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定MapReduce程序運行在Yarn上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<!-- 歷史服務器端地址 -->
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop102:10020</value>
</property>
<!-- 歷史服務器web端地址 -->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop102:19888</value>
</property>
</configuration>
配置workers
vim /opt/module/hadoop/etc/hadoop/workers
在該文件中增加如下內容:
hadoop102
hadoop103
hadoop104
啟動Hadoop
sbin/start-dfs.sh
sbin/start-yarn.sh
bin/mapred --daemon start historyserver # 啟動 historyserver
Web端查看HDFS的Web頁面:http://hadoop102:9870/
Web端查看SecondaryNameNode攒发,瀏覽器中輸入:http://hadoop104:9868/status.html
Hadoop啟動腳本
#!/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
hadoop常用命令
查看 Job 信息:
hadoop job -list
殺掉 Job:
hadoop job –kill job_id
yarn application --list --all