前提:配置好机器名以、JDK环境及安装包
所有配置文件路径:$HADOOP_HOME/etc/hadoop
配置环境变量
- 打开/etc/profile文件
添加以下内容:vi /etc/profile
export HADOOP_HOME=/usr/local/hadoop-3.2.1
export PATH=$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$PATH
测试环境变量:hadoop version
[root@hadoop101 ~]# hadoop version Hadoop 3.2.1 Source code repository https://gitbox.apache.org/repos/asf/hadoop.git -r b3cbbb467e22ea829b3808f4b7b01d07e0bf3842 Compiled by rohithsharmaks on 2019-09-10T15:56Z Compiled with protoc 2.5.0 From source with checksum 776eaf9eee9c0ffc370bcbc1888737 This command was run using /usr/local/hadoop-3.2.1/share/hadoop/common/hadoop-common-3.2.1.jar
配置core-site.xml
进入配置文件目录:$HADOOP_HOME/etc/hadoop
cd $HADOOP_HOME/etc/hadoop
编辑core-site.xml文件:vi core-site.xml
- 添加以下配置信息:
注意:<configuration> <property> <name>fs.defaultFS</name> <value>hdfs://hadoop101:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/data/hadoop/tmp</value> </property> </configuration>
- defaultFS中的值hadoop101为当前主机的主机名
- tmp.dir为数据临时目录,需保证父目录存在
配置hdfs-site.xml
进入配置文件目录:$HADOOP_HOME/etc/hadoop
cd $HADOOP_HOME/etc/hadoop
编辑hdfs-site.xml文件:vi hdfs-site.xml
- 添加以下配置信息:
注意:<configuration> <property> <name>dfs.replication</name> <value>1</value> </property> </configuration>
- dfs.replication:表示复本的数量
配置yarn-site.xml
进入配置文件目录:$HADOOP_HOME/etc/hadoop
cd $HADOOP_HOME/etc/hadoop
编辑hdfs-site.xml文件:vi yarn-site.xml
- 添加以下配置信息:
注意:<configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <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> <property> <name>yarn.resourcemanager.hostname</name> <value>hadoop101</value> </property> </configuration>
- yarn.nodemanager.aux-services: Shuffle service that needs to be set for Map Reduce applications.
- yarn.nodemanager.env-whitelist: Environment properties to be inherited by containers from NodeManagers
配置hadoop-env.sh
进入配置文件目录:$HADOOP_HOME/etc/hadoop
cd $HADOOP_HOME/etc/hadoop
编辑hdfs-site.xml文件:vi hadoop-env.sh
- 添加以下配置信息:
export JAVA_HOME=/usr/local/jdk1.8.0_144 export HADOOP_LOG_DIR=/home/data/hadoop/logs