任务描述
项目的运行环境为基于Hadoop的全分布式模式集群。
任务的主要内容为安装Hadoop分布式集群环境。
任务指导
Hadoop集群需要整个集群所有节点安装的Hadoop版本保持一致,并且拥有相同的配置
具体配置步骤如下:
-
解压缩Hadoop的压缩包
-
配置Hadoop的环境变量
-
修改Hadoop的配置文件,Hadoop的配置文件存放在Hadoop安装目录下的etc/hadoop/中
-
首先在一台节点对整个Hadoop集群进行配置,再将此节点的配置发送到集群的其它节点上。
-
具体需要修改的Hadoop的配置文件包括 core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、hadoop-env.sh、slaves
任务实现
- 安装Hadoop。在【master1】服务器解压并配置完成后,再复制到其它服务器。
在/opt/software目录下解压Hadoop的安装包;
输入【cd /opt/software】命令转到/opt/software目录下;
输入【tar -xzf hadoop-2.10.1.tar.gz -C /opt/app/】命令解压;
- 配置Hadoop环境变量,修改系统配置文件/etc/profile。
在集群中所有节点添加Hadoop的环境变量
输入【vi /etc/profile】命令,编辑/etc/profile文件。
在/etc/profile文件尾部追加如下内容:
export HADOOP_HOME=/opt/app/hadoop-2.10.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
使用【source /etc/profile】使配置文件生效。
-
进入hadoop的配置文件夹。
[root@master1 ~]# cd $HADOOP_HOME/etc/hadoop
-
配置core-site.xml文件。该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
<configuration> <property> <name>fs.defaultFS</name> <value>hdfs://master1:9000</value> </property> <property> <name>io.file.buffer.size</name> <value>131072</value> </property> <property> <name>hadoop.tmp.dir</name> <value>file:/opt/app/hadoop_path/tmp</value> </property> <property> <name>fs.trash.interval</name> <value>1440</value> </property> <property> <name>fs.trash.checkpoint.interval</name> <value>0</value> </property> </configuration>
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
--> -
配置 hdfs-site.xml 文件,该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
<configuration> <property> <name>dfs.namenode.secondary.http-address</name> <value>slave2:9001</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/opt/app/hadoop_path/hdfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/opt/app/hadoop_path/hdfs/data</value> </property> <property> <name>dfs.replication</name> <value>2</value> </property> </configuration>
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
--> -
配置 mapred-site.xml 文件。
首先,输入【cp mapred-site.xml.template mapred-site.xml】命令将mapred-site.xml.template命名为mapred-site.xml。
配置$HADOOP_HOME/etc/hadoop目录下的mapred-site.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master1:19888</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<!-- 开启uber模式(针对小作业的优化) -->
<property>
<name>mapreduce.job.ubertask.enable</name>
<value>true</value>
</property>
<!-- 配置启动uber模式的最大map数 -->
<property>
<name>mapreduce.job.ubertask.maxmaps</name>
<value>9</value>
</property>
<!-- 配置启动uber模式的最大reduce数 -->
<property>
<name>mapreduce.job.ubertask.maxreduces</name>
<value>1</value>
</property>
</configuration>
-
配置yarn-site.xml文件,该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:
<?xml version="1.0"?>http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>master1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master1:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master1:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master1:8088</value>
</property>
</configuration> -
配置hadoop-env.sh文件,文件存放在$HADOOP_HOME/etc/hadoop目录下,配置文件的JAVA_HOME变量。如果不设置,无法正常启动集群。
输入【vim hadoop-env.sh】打开准备修改的配置文件hadoop-env.sh,修改JAVA_HOME环境变量。
找到默认的JAVA_HOME配置修改为如下配置:
export JAVA_HOME=/opt/app/jdk1.8.0_181
在【hadoop-env.sh】文件末尾添加如下内容,使Hadoop在操作HBase能使用对应的类库:
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/opt/app/hbase-2.3.5/lib/*
-
配置slaves文件,该文件存在在$HADOOP_HOME/etc/hadoop目录下,删除默认的localhost,增加3个从节点的IP地址或host主机名。
slave1
slave2 -
为Hadoop创建目录
[root@master1 ~]# mkdir -p /opt/app/hadoop_path/tmp
[root@master1 ~]# mkdir -p /opt/app/hadoop_path/hdfs/name
[root@master1 ~]# mkdir /opt/app/hadoop_path/hdfs/data -
将配置好的Hadoop复制到其他节点对应位置上,通过scp命令发送。
[root@master1 ~]# scp -rq /opt/app/hadoop-2.10.1 slave1:/opt/app
[root@master1 ~]# scp -rq /opt/app/hadoop-2.10.1 slave2:/opt/app[root@master1 ~]# scp -rq /opt/app/hadoop_path slave1:/opt/app
[root@master1 ~]# scp -rq /opt/app/hadoop_path slave2:/opt/app
转发后在所有节点执行【 source /etc/profile 】命令重新加载环境变量