2024年3月24日发(作者:)

Hadoop使用常见问题以及解决方法

1:Shuffle Error: Exceeded MAX_FAILED_UNIQUE_FETCHES; bailing-out

Answer:

程序 里面需要打开多个文件 ,进行分析,系统一般默认数量是1024,(用ulimit -a可

以看到)对于正常使用是够了,但是对于程序来讲,就太少了。

修改办法:

修改2个文件。

/etc/security/

vi /etc/security/

加上:

* soft nofile 102400

* hard nofile 409600

$cd /etc/pam.d/

$sudo vi login

添加 session required /lib/security/pam_

针对第一个问题 我纠正下答案:

这是reduce 预处理阶段shuffle时获取 已完成的map的输出失败次数超过上限造成的,

上限默认为5。引起此问题的方式可能会有很多种,比如网络连接不正常,连接超时,带宽

较差以及端口阻塞等。。。通常框架内网络情况较好是不会出现此错误的。

2:Too many fetch-failures

Answer:

出现这个问题主要是结点间的连通不够全面。

1) 检查、/etc/hosts

要求本机ip对应 服务 器名

要求要包含所有的服务器ip + 服务器名

2) 检查 .ssh/authorized_keys

要求包含所有服务器(包括其自身)的public key

3:处理速度特别的慢出现map很快但是reduce很慢而且反复出现 reduce=0%

Answer:

结合第二点,然后

修改 conf/ 中的export HADOOP_HEAPSIZE=4000

4:能够启动 datanode ,但无法访问,也无法结束的错误

在重新格式化一个新的分布式 文件时,需要将你NameNode上所配置的

这一namenode用来存放NameNode持久存储名字空间及事务日志的本地 文件系统路

径 删除,同时将各DataNode上的 .dir的路径DataNode存放块数据 的本地

文件系统路径的目录也删除。如本此配置就是在NameNode上删除

/home/hadoop/NameData,在DataNode上删除/home/hadoop/DataNode1和

/home/hadoop/DataNode2。这是因为Hadoop 在格式化一个新的分布式文件系统时,

每个存储的名字空间都对应了建立时间的那个版本(可以查看/home/hadoop

/NameData/current目录下的VERSION文件,上面记录了版本信息),在重新格式化

新的分布式系统文件时,最好先删除NameData目录。必须删除各DataNode的

。这样才可以使namedode和datanode记录的信息版本对应。

注意:删除是个很危险的动作,不能确认的情况下不能删除!!做好删除的文件等通通备份!!

5: Exception : Could not obtain block:

blk_4901469_1100

file=/user/hive/warehouse/src_20090724_log/src_20090724_log

出现这种情况大多是结点断了,没有连接上。

6:emoryError: Java heap space

出现这种异常,明显是jvm内存不够得原因,要修改所有的datanode的jvm内存大小。

Java -Xms1024m -Xmx4096m

一般jvm的最大内存使用应该为总内存大小的一半,我们使用的8G内存,所以设置为

4096m,这一值可能依旧不是最优的值。

7:IO写操作出现问题

0-98, infoPort=50075, ipcPort=50020):Got exception while

serving blk_-5911280_1292 to /172.16.100.165:

TimeoutException: 480000 millis timeout while waiting for

channel to be ready for write. ch : Channel[connected

local=/

172.16.100.165:50010 remote=/172.16.100.165:50930]

at

rIO(SocketIOWithTimeou

:185)

at

rWritable(SocketOutputSt

:159)

erToFully(SocketOu

:198)

at

unks(BlockSend

:293)

at

ock(BlockSender

.java:387)

at

ock(DataXceiver.

java:179)

at

(:9

4)

(:619)

It seems there are many reasons that it can timeout, the example given in

HADOOP-3831 is a slow reading client.

解决办法:在中设置t=0试试;

My understanding is that this issue should be fixed in Hadoop 0.19.1 so that

we should leave the standard timeout. However until then this can help

resolve issues like the one you're seeing.

8:hadoopOutOfMemoryError:

解决方法:

-Xmx800M -server

With the right JVM size in your , you will have to copy this

to all mapred nodes and restart the cluster.

或者:hadoop jar jarfile [main class] -D =-Xmx800M

9:ption: Job failed! at

(:1232) while

indexing.

when i use nutch1.0,get this error:

ption: Job failed! at

(:1232) while

indexing.

这个也很好解决:

可以删除conf/ties,然后可以看到详细的错误报告

我这儿出现的是out of memory

解决办法是在给运行主类加上参数:-Xms64m

-Xmx512m

你的或许不是这个问题,但是能看到详细的错误报告问题就好解决了

其他问题

status of 255 error

错误类型:

ption: Task process exit with nonzero status of 255.

at (:424)

错误原因:

Set al and to

higher value. By default, their values are 24 hours. These might be the reason

for failure, though I'm not sure

split size

FileInputFormat input splits: (详见《the definitive guide》P190)

: default=1, the smallest valide size in bytes for a file split.

: default=_VALUE, the largest valid size.

: default = 64M, 系统中设置为128M。

如果设置 minimum split size > block size, 会增加块的数量。(猜想从其他节点拿去数

据的时候,会合并block,导致block数量增多)

如果设置maximum split size < block size, 会进一步拆分block。

split size = max(minimumSize, min(maximumSize, blockSize));

其中minimumSize

sort by value

hadoop不提供直接的sort by value方法,因为这样会降低mapreduce性能。

但可以用组合的办法来实现,具体实现方法见《the definitive guide》, P250

基本思想:

1. 组合key/value作为新的key;

2. 重载partitioner,根据old key来分割;

titionerClass();

3. 自定义keyComparator:先根据old key排序,再根据old value排序;

putKeyComparatorClass();

4. 重载GroupComparator, 也根据old key 来组

合; putValueGroupingComparator();

small input files的处理

对于一系列的small files作为input file,会降低hadoop效率。

有3种方法可以将small file合并处理:

1. 将一系列的small files合并成一个sequneceFile,加快mapreduce速度。

详见WholeFileInputFormat及SmallFilesToSequenceFileConverter,《the

definitive guide》, P194

2. 使用CombineFileInputFormat集成FileinputFormat,但是未实现过;

3. 使用hadoop archives(类似打包),减少小文件在namenode中的metadata内存消

耗。(这个方法不一定可行,所以不建议使用)

方法:

将/my/files目录及其子目录归档成,然后放在/my目录下

bin/hadoop archive - /my/files /my

查看files in the archive:

bin/hadoopfs -lsr har://my/

skip bad records

JobConfconf = new JobConf();

Name("ProductMR");

putKeyClass();

putValueClass();

perClass();

ucerClass();

OutputCompressorClass();

utFormat();

putFormat();

String objpath = "abc1";

utPath(conf, new Path(objpath));

perMaxSkipRecords(conf, _VALUE);

emptsToStartSkipping(conf, 0);

pOutputPath(conf, new Path("data/product/skip/"));

String output = "abc";

putPath(conf, new Path(output));

(conf);

For skipping failed tasks try : t

restart 单个datanode

如果一个datanode出现问题,解决之后需要重新加入cluster而不重启cluster,方法如

下:

bin/ start datanode

bin/ start jobtracker

reduce exceed 100%

"Reduce Task Progress shows > 100% when the total size of map outputs (for a

single reducer) is high "

造成原因:

在reduce的merge过程中,check progress有误差,导致status > 100%,在统计

过程中就会出现以下错误:ndexOutOfBoundsException: 3

at

HttpServer$uceAv

arageProgresses(:228)

at

HttpServer$(Statu

:159)

e(:689)

at e(:802)

at

(:427)

at

ch(WebApplicationHan

:475)

at

(:567)

(:1565)

at

(WebApplicationConte

:635)

(:1517)

at e(:954)

jira地址: /jira/browse/HADOOP-5210

counters

1. built-in counters: Map input bytes, Map

2. enum counters

调用方式:

enum Temperature {

MISSING,

MALFORMED

}

unter(G, 1)

结果显示:

09/04/20 06:33:36 INFO ent: Air Temperature Recor

09/04/20 06:33:36 INFO ent: Malformed=3

09/04/20 06:33:36 INFO ent: Missing=66136856

3. dynamic countes:

调用方式:

unter("TemperatureQuality", lity(),1);

结果显示:

09/04/20 06:33:36 INFO ent: TemperatureQuality

09/04/20 06:33:36 INFO ent: 2=1246032

09/04/20 06:33:36 INFO ent: 1=973422173

09/04/20 06:33:36 INFO ent: 0=1

Namenode in safe mode 解决方法

bin/hadoopdfsadmin -safemode leave

eToHostException: No route to host 解决方法:

sudo /etc/init.d/iptables stop

更改namenode后,在hive中运行select 依旧指向之前的namenode地址

这是因为:When youcreate a table, hive actually stores the location of the table

(e.g.

hdfs://ip:port/user/root/...) in the SDS and DBS tables in the metastore . So

when I bring up a new cluster the master has a new IP, but hive's metastore is

still pointing to the locations within the old

cluster. I could modify the metastore to update with the new IP everytime I

bring up a cluster. But the easier and simpler solution was to just use an elastic

IP for the master

所以要将metastore中的之前出现的namenode地址全部更换为现有的namenode地

两个特别的异常:

异常1

hadoop@ubuntu:~$ hadoop/bin/hadoop

jar wordcount input01 output01

Exception in thread "main" ption: Error opening job jar:

at (:90)

Caused by: eption: error in opening zip file

at (Native Method)

at e.(:131)

at e.(:150)

at e.(:87)

at (:88)

发生这个异常后,找了很多帖子都没有解答,也有很多人遇到了类似的情况。其实这一般并

不是java包有问题,问题也简单的可笑,就是上面的命令行中

路径不完整造成的,需要注意一下命令行当前的位置,比如对于我的情况,改为

hadoop/就可以了

异常2

hadoop@ubuntu:~$ hadoop/bin/hadoop jar

hadoop/ wordcount input01 output02

ption: Task process exit with nonzero status of 1.

at (:418)

11/03/15 12:54:09 WARN ent: Error reading task

output-domain:50060/tasklog?plaintext=true&taskid=at

tempt_2_0001_m_000004_1&filter=stdout

......

这个问题困扰了我整整一晚上,中文博客基本没搜到什么有参考价值的文章,老外的很多博

客提到了,但是很多也没说清楚。其中有一些有提示作用,比如:

Just an FYI, found the solution to this problem.

Apparently, it's an OS limit on the number of sub-directories that can be reated

in another directory. In this case, we had 31998 sub-directories

uderhadoop/userlogs/, so any new tasks would fail in Job Setup.

From the unix command line, mkdir fails as well:

$ mkdirhadoop/userlogs/testdir

mkdir: cannot create directory `hadoop/userlogs/testdir': Too many links

Difficult to track down because the Hadoop error message gives no hint

whasoever. And normally, you'd look in the userlog itself for more info, butin

this case the userlog couldn't be created.

问题是,我可以通过这个小测试,在userlogs下面可以添加任意的文件夹和文件,当然也

有可能某些人确实就是这个问题,不能添加。

然后我的解决办法是,直接把这个userlogs给去掉或者换一个文件夹名

hadoop@ubuntu:~$ mv /home/hadoop/hadoop/logs/uerlogs/

/home/hadoop/hadoop/logs/uerlogsOLD/

即,把原来的文件夹改名成userlogsOLD(相当于一种移除、保存方式了),重新运行

hadoop@ubuntu:~$ hadoop/bin/hadoop jar

hadoop/ wordcount input01 output03

11/03/15 14:21:23 INFO putFormat: Total input paths to process :

3

11/03/15 14:21:23 INFO ent: Running job:

job_2_0004

11/03/15 14:21:24 INFO ent: map 0% reduce 0%

11/03/15 14:21:32 INFO ent: map 66% reduce 0%

11/03/15 14:21:35 INFO ent: map 100% reduce 0%

11/03/15 14:21:44 INFO ent: map 100% reduce 100%

11/03/15 14:21:46 INFO ent: Job complete:

job_2_0004

Hadoop 集群常见错误

(一)启动hadoop集群时易出现的错误:

1. 错误现象:eToHostException: No route to host.

原因:master服务器上的防火墙没有关闭。

解决方法: 在master上关闭防火墙: chkconfigiptables off.

2. 错误现象:: Server at JMN/10.22.1.203:9000 not

available yet. /* JMN/10.22.1.203是 hadoop集群当中master的主机名/ip */

原因:/etc/hosts中的文件被自动篡改。

解决方法: 将/etc/hosts 文件按配置文件要求改回来。

3. 错误现象:Too many fetch-failures.

原因:结点间的连通不够全面。

解决方法:

1) 检查 /etc/hosts要求本机ip对应服务器名,并且包含所有的服务器ip和服务器名。

2) 检查 .ssh/authorized_keys要求包含所有服务器(包括其自身)的public key。

(二) 在hadoop集群的master中用命令运行例子易出现的故障:

1. 错误现象:emoryError: Java heap space.

原因:JVM内存不够。

解决方法:修改中属性的值,其默认值是

-Xmx200m 可根据需要适当增大 该值。

2. 错误现象:could only be replicated to 0 nodes, instead of 1

解决方法:在NameNode上执行命令:hadoopnamenode –format重新格式化HDFS,

在格式化之前,需要将你 NameNode上所配置的这一namenode用来存放

NameNode 持久存储名字空间及事务日志的本地文件系统路径删除,同时将各DataNode

上的的路径DataNode存放块数据的本地文件系统路径的目录也删除。

3. 错误现象:namenode in safe mode.

原因:hadoop进入安全模式。

解决方法:在shell中执行命令hadoopdfsadmin -safemode leave 使hadoop离开安全

模式。

(三)在windows下Eclipse中运行例子易出现的错误:

1. 错误现象:ControlException: Permission denied:

user=administrator, access=EXECUTE,

inode="job_2_0003":heipark:supergroup:rwx-.

原因:本地用户administrator(本机windows用户)想要远程操作hadoop系统,没有权

限引起的。

解决办法:

i、如果是测试环境,可以取消hadoophdfs的用户权限检查。打开conf/,找到

sions属性修改为false(默认为true)OK了。

ii、修改hadoop location参数,在advanced parameter选项卡中,找到项,

将此项改为启动hadoop的用户名即可。

2.错误现象:IOException: Cannot run program "chmod": CreateProcess error=2.

原因: 没有安装cygwin或 没有配置环境变量。

解决办法:安装并配置环境变量 bin到 path下 重启 eclipse 问题即可。

3. 错误现象: WARN obRunner: job_local_0001

emoryError: Java heap space

at k$MapOutputBuffer.(:781)

at Mapper(:350)

………..

原因:客户端程序运行时java虚拟机内存分配不够

解决办法:修改run configuration,选择Arguments选项卡,在VM arguments栏中加

入-Xmx1024m,保存即可解决问题。