Linux下Hadoop2.7.3集群环境的搭建
Linux下Hadoop2.7.3集群环境的搭建
本文旨在提供最基本的,可以用于在生产环境进行Hadoop、HDFS分布式环境的搭建,对自己是个总结和整理,也能方便新人学习使用。
基础环境
JDK的安装与配置
现在直接到Oracle官网(http://www.oracle.com/)寻找JDK7的安装包不太容易,因为现在官方推荐JDK8。找了半天才找到JDK下载列表页的地址(http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html)。因为选择Linux操作系统作为部署环境,所以选择64位的版本。我选择的是jdk-7u79-linux-x64.gz。
这里直接使用rpm包直接安装
rpm –ivh jdk-7u131-linux-x64.rpm
回到/home/hadoop目录,配置java环境变量,命令如下:
在.bash_profile中加入以下内容:

立刻让java环境变量生效,执行如下命令:
source .bash_profile
最后验证java是否安装配置正确:

Host
由于我搭建Hadoop集群包含三台机器,所以需要修改调整各台机器的hosts文件配置,命令如下:
vi /ets/hosts
如果没有足够的权限,可以切换用户为root。
三台机器的内容统一增加以下host配置:

SSH信任
由于NameNode与DataNode之间通信,使用了SSH,所以需要配置免登录,使slave可以ssh免密登陆master。
具体配置可参考:
http://www.cnblogs.com/chenjunjie/p/4000228.html
文件目录
为了便于管理,给Master的hdfs的NameNode、DataNode及临时文件,在用户目录下创建目录:
/home/hadoop/hdfs/name
/home/hadoop/hdfs/data
/home/hadoop/hdfs/tmp
然后将这些目录通过scp命令拷贝到Slave1和Slave2的相同目录下。
Hadoop的安装与配置
下载
首先到Apache官网(http://www.apache.org/dyn/closer.cgi/hadoop/common/)下载Hadoop,从中选择推荐的下载镜像(http://mirrors.hust.edu.cn/apache/hadoop/common/),我选择hadoop-2.7.3的版本
使用以下命令hadoop-2.7.2.tar.gz解压缩到/home/hadoop目录
tar -zxvf hadoop-2.7.3.tar.gz
环境变量
回到/home/hadoop目录,配置hadoop环境变量,命令如下:
vi .bash_profile
在.bash_profile中加入以下内容:
export HADOOP_DEV_HOME=/home/hadoop/hadoop-2.7.3
export PATH=$PATH:$HADOOP_DEV_HOME/bin
export PATH=$PATH:$HADOOP_DEV_HOME/sbin
export HADOOP_MAPARED_HOME=${HADOOP_DEV_HOME}
export HADOOP_COMMON_HOME=${HADOOP_DEV_HOME}
export HADOOP_HDFS_HOME=${HADOOP_DEV_HOME}
export YARN_HOME=${HADOOP_DEV_HOME}
export HADOOP_CONF_DIR=${HADOOP_DEV_HOME}/etc/hadoop
export HDFS_CONF_DIR=${HADOOP_DEV_HOME}/etc/hadoop
export YARN_CONF_DIR=${HADOOP_DEV_HOME}/etc/hadoop
export JAVA_LIBRARY_PATH='/home/hadoop/hadoop-2.7.3/lib/native'
export HBASE_HOME=/home/hadoop/hbase-1.2.4
export PATH=$PATH:$HBASE_HOME/bin
立刻让hadoop环境变量生效,执行如下命令:
source .bash_profile
Hadoop的配置
进入hadoop-2.7.3的配置目录:
cd home/hadoop/hadoop-2.7.3/etc/hadoop
依次修改core-site.xml、hdfs-site.xml、mapred-site.xml及yarn-site.xml文件。
core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?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>hadoop.tmp.dir</name>
<value>file:/home/hadoop/hdfs/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://Master:9000</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>
hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?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>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/hdfs/name</value>
<final>true</final>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/hdfs/data</value>
<final>true</final>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>Master:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
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>
</configuration>
yarn-site.xml
<?xml version="1.0"?>
<!--
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.
-->
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.address</name>
<value>Master:18040</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>Master:18030</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>Master:18088</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>Master:18025</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>Master:18141</value>
</property>
<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>
</configuration>
在hadoop-env.sh中加入如下配置:
export JAVA_HOME=/usr/java/jdk1.7.0_131
在masters中加入
master
在slave中加入
slave1
slave2
样例如图:

最后,将整个hadoop-2.7.3文件夹及其子文件夹使用scp复制到两台Slave的相同目录中:
scp -r hadoop-2.7.3 hadoop@Slave1:/home/hadoop/
scp -r hadoop-2.7.3 hadoop@Slave2:/home/hadoop/
运行Hadoop
运行HDFS
格式化NameNode
执行命令:
hadoop namenode -format
执行过程如下图:

最后的执行结果如下图:

启动NameNode
hadoop-daemon.sh start namenode
执行结果如下图:

最后在Master上执行ps -ef | grep hadoop,得到如下结果:

在Master上执行jps命令,得到如下结果:

说明NameNode启动成功。
启动DataNode
执行命令如下:
hadoop-daemons.sh start datanode
执行结果如下:

在Slave1上执行命令,如下图:

在Slave2上执行命令,如下图:

说明Slave1和Slave2上的DataNode运行正常。
以上启动NameNode和DataNode的方式,可以用start-dfs.sh脚本替代:

运行YARN
运行Yarn也有与运行HDFS类似的方式。启动ResourceManager使用以下命令:
yarn-daemon.sh start resourcemanager
批量启动多个NodeManager使用以下命令:
yarn-daemons.sh start nodemanager
以上方式我们就不赘述了,来看看使用start-yarn.sh的简洁的启动方式:
在Master上执行jps:

说明ResourceManager运行正常。
在两台Slave上执行jps,也会看到NodeManager运行正常,如下图:


测试Hadoop
测试HDFS
最后测试下亲手搭建的Hadoop集群是否执行正常,测试的命令如下图所示:

测试YARN
可以访问YARN的管理界面,验证YARN,如下图所示:

测试mapreduce
本人比较懒,不想编写mapreduce代码。幸好Hadoop安装包里提供了现成的例子,在Hadoop的share/hadoop/mapreduce目录下。运行例子:



配置运行Hadoop中遇见的问题
yarn.nodemanager.aux-services错误
在执行start-yarn.sh脚本启动YARN时,在Slave1和Slave2机器上执行jps命令未发现NodeManager进程,于是登录Slave机器查看日志,发现以下错误信息:

参考网上的解决方式,是因为yarn-site.xml文件中yarn.nodemanager.aux-services对应的值mapreduce.shuffle已经被替换为mapreduce_shuffle。有些参考用书上也错误的写为另一个值mapreduce-shuffle。

Linux下Hadoop2.7.3集群环境的搭建的更多相关文章
- Linux下Hadoop2.6.0集群环境的搭建
本文旨在提供最基本的,可以用于在生产环境进行Hadoop.HDFS分布式环境的搭建,对自己是个总结和整理,也能方便新人学习使用. 基础环境 JDK的安装与配置 现在直接到Oracle官网(http:/ ...
- Linux下Hadoop2.7.1集群环境的搭建(超详细版)
本文旨在提供最基本的,可以用于在生产环境进行Hadoop.HDFS分布式环境的搭建,对自己是个总结和整理,也能方便新人学习使用. 一.基础环境 ...
- 基于原生态Hadoop2.6 HA集群环境的搭建
hadoop2.6 HA平台搭建 一.条件准备 软件条件: Ubuntu14.04 64位操作系统, jdk1.7 64位,Hadoop 2.6.0, zookeeper 3.4.6 硬件条件 ...
- (2)虚拟机下hadoop1.1.2集群环境搭建
hadoop集群环境的搭建和单机版的搭建差点儿相同,就是多了一些文件的配置操作. 一.3台主机的hostname改动和IP地址绑定 注意:以下的操作我都是使用root权限进行! (1)3太主机的基本网 ...
- centos6.5环境下zookeeper-3.4.6集群环境部署及单机部署详解
centos6.5环境下Zookeeper-3.4.6集群环境部署 [系统]Centos 6.5 集群部署 [软件]准备好jdk环境,此次我们的环境是open_jdk1.8.0_101 zookeep ...
- Linux下MySQL/MariaDB Galera集群搭建过程【转】
MariaDB介绍 MariaDB是开源社区维护的一个MySQL分支,由MySQL的创始人Michael Widenius主导开发,采用GPL授权许可证. MariaDB的目的是完全兼容MySQL,包 ...
- hadoop集群环境的搭建
hadoop集群环境的搭建 今天终于把hadoop集群环境给搭建起来了,能够运行单词统计的示例程序了. 集群信息如下: 主机名 Hadoop角色 Hadoop jps命令结果 Hadoop用户 Had ...
- Nacos集群环境的搭建与配置
Nacos集群环境的搭建与配置 集群搭建 一.环境: 服务器环境:CENTOS-7.4-64位 三台服务器IP:192.168.102.57:8848,192.168.102.59:8848,192. ...
- redis集群环境的搭建和错误分析
redis集群环境的搭建和错误分析 redis集群时,出现的几个异常问题 09 redis集群的搭建 以及遇到的问题
随机推荐
- JDBC(二)—— 获取连接池方式
## 获取数据库连接的方式 ### 方式一 ```javaDriver driver = new com.mysql.cj.jdbc.Driver(); String url = "jdbc ...
- 学习笔记:Link Cut Tree
模板题 原理 类似树链剖分对重儿子/长儿子剖分,Link Cut Tree 也做的是类似的链剖分. 每个节点选出 \(0 / 1\) 个儿子作为实儿子,剩下是虚儿子.对应的边是实边/虚边,虚实时可以进 ...
- VS调试相关
1.查看DataSet的数据
- 前端面试题CSS-div宽度设置为100%,设置属性margin-left和margin-right时出现的问题
前端面试题CSS-div宽度设置为100%,设置属性margin-left和margin-right时出现的问题 div格式如下 <div class="a"> < ...
- docker(专业版) 安装过程报错
1.安装docker Desktop时遇到的错误 1.1安装Docker Desktop报错:WSL 2 installation is incomplete 解决: # 更新版本 https://b ...
- common 模块的 context.py
1.context.py 是写正则表达式的,源码如下: import re#s 是目标字符串#dict 是替换的内容#找到目标字符串里面的标识符KEY,去d里面拿到替换的值#替换到s 里面去,然后仔 ...
- 没有部署ingress pod的woker节点telnet slb的80 443端口不通
一,问题描述 没有部署ingress pod的woker节点telnet slb的80 443端口不通 二,解决办法 方法一:改用svc地址调用 方法二:让每台woker节点都部署ingress po ...
- 安卓和ios的app证书过期的相关问题汇总
一,ios的APP的发布流程请见:ios的APP的发布流程 http://www.jianshu.com/p/b1b77d804254 这篇文章写得很好很全面 二,app证书过期了怎么办: IOS的情 ...
- HashMap 中 Key 类型的选择
什么对象可以作为HashMap的key值? 从HashMap的语法上来讲,一切对象都可以作为Key值.如:Integer.Long.String.Object等.但是在实际工作中,最常用的使用Stri ...
- 一次数独生成及解题算法的剖析(Java实现)
数独生成及解题算法剖析(Java实现) 关键词 数独9x9 数独生成算法 数独解题算法 序言 最近业务在巩固Java基础,编写了一个基于JavaFX的数独小游戏(随后放链接).写到核心部分发现平时玩的 ...