Hadoop 1.2 集群搭建与环境配置

摘要

一、虚拟机环境 见我的另一篇 http://www.searu.org/2016-12/137955.htm […]

一、虚拟机环境

见我的另一篇 http://www.searu.org/2016-12/137955.htm

需要安装JDK环境,CentOS下安装JDK可参考:http://www.searu.org/2016-12/137956.htm

注意三台机器均要配置,因为启动时,namenode会启动其它机器。

二、Hadoop环境

hadoop1.2.1

idk7u79-linux-i586.tar.gz

三、开始搭完全分布式hadoop

三台机器,角色配置如下

hostname 角色配置
centos1 namenode
centos2 datanode, secondaryNameNode
centos3 datanode

1、hadoop配置

分别在三台虚拟机内拷贝hadoop-1.2.1.tar.gz,并解压: tar -zxvf hadoop-1.2.1.tar.gz

conf目录文件配置

conf目录下文件 配置项 备注
core-site.xml

<configuration>

    <property>

        <name>fs.default.name</name>

        <value>hdfs://centos:9000</value>

    </property>

    <property>

        <name>hadoop.tmp.dir</name>

        <value>/opt/hadoop-tmp</value>

    </property>

</configuration>

1、fs.default.name:配置namenode站点地址。需要注意。9000端口是hdfs rpc协议端口,如果从浏览器访问,则是http协议,端口号是50070.例:http://cetnos:50070
2、hadoop.tmp.dir默认配置/tmp/hadoop-${user.name},hadoop文件数据会默认配置在此目录,由于tmp目录,linux重启后自动清空,因此这里对hadoop.tmp.dir进行手动指定。

hadoop-env.sh export JAVA_HOME=/usr/local/java/jdk1.7.0_79

配置jdk时在系统配置了JAVA_HOME,但是hadoop不认,必须要在这里修改成你现在的路径。

hdfs-site.xml

<configuration>

    <property>

        <name>dfs.replication</name>

        <value>2</value>

    </property>

</configuration>

lock最大附本数,配置2台dataNode,此处填2.
masters centos1 master文件用来配置secondaryNameNod, 注意是secondaryNameNode,不是nameNode
slaves

centos1
centos2  (一个节点一行)

slaves用来配置dataNode

2、格式化dfs

cd /home/hadoop-1.2/bin/

./hadoop namenode -format    (格式化成功后会在/opt/hadoop-tmp/dfs/name/下生成格式化文件)

3、hadoop路径每台机器要保持一致

配置完成后,NameNode机器上输入命令,即可完成hadoopo的hdfs分布式服务的启动。

[email protected] bin]# ./start-dfs.sh

4、启动后结果

在浏览器中输入http://{NameNode IP}:50070即可访问配置的hdfs环境

四、配置中常见问题

1、JAVA_HOME is not set.

错误日志:

[email protected] bin]# ./start-dfs.sh

starting namenode, logging to /home/alvin/hadoop-1.2.1/libexec/../logs/hadoop-root-namenode-centos.out

centos1: bash: line 0: cd: /home/alvin/hadoop-1.2.1/libexec/..: No such file or directory

centos2: bash: line 0: cd: /home/alvin/hadoop-1.2.1/libexec/..: No such file or directory

centos2: starting datanode, logging to /opt/hadoop-1.2/libexec/../logs/hadoop-root-datanode-centos2.out

centos1: starting datanode, logging to /usr/hadoop-1.2.1/libexec/../logs/hadoop-root-datanode-centos1.out

centos2: Error: JAVA_HOME is not set.

centos1: Error: JAVA_HOME is not set.

centos1: bash: line 0: cd: /home/alvin/hadoop-1.2.1/libexec/..: No such file or directory

centos1: starting secondarynamenode, logging to /usr/hadoop-1.2.1/libexec/../logs/hadoop-root-secondarynamenode-centos1.out

centos1: Error: JAVA_HOME is not set.

产生原因三种:

(1)、JDK未配置

解决方法:配置JDK解决,可参考 http://www.searu.org/2016-12/137956.htm

(2)、hadoop在每台机器路径不一致,会报JAVA_HOME is not set.问题

该问题首先会想到centos1, centos2两台机器JDK环境是否有配置JAVA_HOME,但是查看均已配了JDK环境。

仔细阅读日志,发现问题是No such file or directory

centos1: bash: line 0: cd: /home/alvin/hadoop-1.2.1/libexec/..: No such file or directory

centos2: bash: line 0: cd: /home/alvin/hadoop-1.2.1/libexec/..: No such file or directory

解决方法:hadoop在每台机器配置路径要一致

(3)、hadoop-env.sh里面没有配置JAVA_HOME

解决方法:配置jdk时在系统配置了JAVA_HOME,但是hadoop不认,必须要在这里修改成你现在的路径。

分析原因:

由于centos1下hadoop路径在/home/alvin/hadoop-1.2.1/下,centos2与centos3路径在/opt/hadoop-1.2/下,

启动datanode或secondaryNameNode节点时,报No such file or directory.

可以看到centos2与centos3都是按照centos1机器的hadoop路径去读取文件的。因此报 No such file or directory

2、启动dfs服务时,jps命令查看,NameNode启动,DataNode和SecondaryNameNode未启动。

防火墙未关,输入命令service iptables stop关闭三台机器防火墙

3、org.apache.hadoop.security.AccessControlException

解决方法

在 hdfs-site.xml 添加参数:

<property>

        <name>dfs.permissions</name>

        <value>false</value>

  </property> 

</configuration>

4、org.apache.hadoop.hdfs.server.datanode.DataNode: java.io.IOException: Incompatible namespaceIDs in /opt/hadoop-tmp/dfs/data: namenode namespaceID = 1165565627; datanode namespaceID = 1468616188

解决方法:以name为准,将namenode节点上${hadoop-tmp}/hfs/data/current/VERSION文件的namespaceID改为${hadoop-tmp}/hfs/name/current/VERSION文件的namespaceID。同时将datanode节点上的${hadoop-tmp}/hfs/data/current/VERSION文件的namespaceID相应修改

5、org.apache.hadoop.hdfs.server.datanode.DataNode: All directories in dfs.data.dir are invalid

发生错误的原因就是hdfs下的data文件夹权限设置错误,应为rwxr-xr-x,因此修改方式如下:

解决方法:chmod 755 /opt/hadoop-tmp/ –R

6、ERROR security.UserGroupInformation: PriviledgedActionException as:alvin cause:java.net.ConnectException: Call to 192.168.95.134/192.168.95.134:9091 failed on connection exception: java.net.ConnectException: Connection refused

java.net.ConnectException: Call to 192.168.95.134/192.168.95.134:9091 failed on connection exception: java.net.ConnectException: Connection refused

at org.apache.hadoop.ipc.Client.wrapException(Client.java:1142)

解决方法:确认IP和端口号是否正确,mapreduce端口号是9001,这里是9091.所以报错

7、启动hadoop时,log中出现:java.io.IOException: NameNode is not formatted.

解决方法:初始化namenode

./hadoop namenode –format

下面关于Hadoop的文章您也可能喜欢,不妨看看:

Ubuntu14.04下Hadoop2.4.1单机/伪分布式安装配置教程  http://www.searu.org/2015-02/113487.htm

CentOS安装和配置Hadoop2.2.0  http://www.searu.org/2014-01/94685.htm

CentOS 6.3下Hadoop伪分布式平台搭建  http://www.searu.org/2016-11/136789.htm

Ubuntu 14.04 LTS下安装Hadoop 1.2.1(伪分布模式) http://www.searu.org/2016-09/135406.htm

Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) http://www.searu.org/2013-01/77681.htm

实战CentOS系统部署Hadoop集群服务 http://www.searu.org/2016-11/137246.htm

单机版搭建Hadoop环境图文教程详解 http://www.searu.org/2012-02/53927.htm

Hadoop 2.6.0 HA高可用集群配置详解  http://www.searu.org/2016-08/134180.htm

Spark 1.5、Hadoop 2.7 集群环境搭建  http://www.searu.org/2016-09/135067.htm

更多Hadoop相关信息见Hadoop 专题页面 http://www.searu.org/topicnews.aspx?tid=13

本文永久更新链接地���http://www.searu.org/2016-12/137957.htm

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: