[root@hadoop01 hadoop]# vim hadoop-env.sh
[root@hadoop01 hadoop]# vim mapred-env.sh
[root@hadoop01 hadoop]# vim yarn-env.sh
export JAVA_HOME="/opt/jdk1.8.0_101" # 路径为jdk安装路径
3. 修改Hadoop配置文件
Hadoop安装目录下的etc/hadoop目录中,需修改core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、slaves(3.0之后为workers)文件,根据实际情况修改配置信息。
(1)core-site.xml
<configuration>
<property>
<!-- 配置hdfs地址 -->
<name>fs.defaultFS</name>
<value>hdfs://hadoop01:9000</value>
</property>
<property>
<!-- 保存临时文件目录,需先在/opt/hadoop-2.7.7下创建tmp目录 -->
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop-2.7.7/tmp</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>
(2)hdfs-site.xml
<configuration>
<property>
<!-- 主节点地址 -->
<name>dfs.namenode.http-address</name>
<value>hadoop01:50070</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/opt/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/opt/hadoop/dfs/data</value>
</property>
<property>
<!-- 备份份数 -->
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<!-- 第二节点地址 -->
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop02:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
<description>配置为false后,可以允许不要检查权限就生成dfs上的文件,需防止误删操作</description>
</property>
</configuration>
(3)mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop01:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop01:19888</value>
</property>
</configuration>
(4)yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>hadoop01:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>hadoop01:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>hadoop01:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>hadoop01:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>hadoop01:8088</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<!-- NodeManager中的配置,这里配置过小可能导致nodemanager启动不起来
大小应该大于 spark中 executor-memory + driver的内存 -->
<value>6144</value>
</property>
<property>
<!-- RsourceManager中配置
大小应该大于 spark中 executor-memory + driver的内存 -->
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>61440</value>
</property>
<property>
<!-- 使用核数 -->
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>2</value>
</property>