3.1 使用brew 安装 Hadoop
brew install hadoop
3.2 查看是否安装成功
hadoop version
3.3 修改Hadoop 配置文件
3.3.1 进入Hadoop的目录
cd /opt/homebrew/Cellar/hadoop/3.4.0/libexec/etc/hadoop
3.3.2 修改core-site.xml
# 以文件方式打开配置文件
open -e core-site.xml
在core-site.xml文件的标签内添加如下内容:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:8020</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/opt/homebrew/Cellar/hadoop/tmp</value>
</property>
</configuration>
创建tmp文件夹,用来指定hadoop运行时产生文件的存放目录
mkdir /opt/homebrew/Cellar/hadoop/tmp
3.3.3 修改hdfs-site.xml
open -e hdfs-site.xml
在hdfs-site.xml文件的标签内添加如下内容:
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/opt/homebrew/Cellar/hadoop/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/opt/homebrew/Cellar/hadoop/tmp/dfs/data</value>
</property>
</configuration>
创建dfs、name、data文件夹(存放数据)
mkdir /opt/homebrew/Cellar/hadoop/tmp/dfs
mkdir /opt/homebrew/Cellar/hadoop/tmp/dfs/name
mkdir /opt/homebrew/Cellar/hadoop/tmp/dfs/data
3.3.4 修改mapred-site.xml
open -e mapred-site.xml
在配置文件中添加一下内容,注意配置中的路径
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9010</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=/opt/homebrew/Cellar/hadoop/3.4.1/libexec</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=/opt/homebrew/Cellar/hadoop/3.4.1/libexec</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=/opt/homebrew/Cellar/hadoop/3.4.1/libexec</value>
</property>
</configuration>
3.3.5 修改yarn-site.xml
open -e yarn-site.xml
在配置文件中添加一下配置:
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>localhost:9000</value>
</property>
<property>
<name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
<value>100</value>
</property>
</configuration>
3.4 修改hadoop-env.sh 文件
cd /opt/homebrew/Cellar/hadoop/3.4.0/libexec/etc/hadoop
open -e hadoop-env.sh
找到文件中 export JAVA_HOME该行,打开注释,并添加Java安装路径,如下: