异常:
Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-dell\mapred\staging\dell1008071661\.staging to 0700
    at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:691)
    at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:664)
原因:
hadoop在windows下文件权限问题,在linux不存在这个问题。
解决方法:
1 代码的修改:
笔者使用的是nutch-1.7,对应的hadoop版本为1.2.0 下载地址:(hadoop-core-1.2.0
在下载的release-1.2.0\src 下搜索 ‘FileUtil’ ,然后修改:
private static void checkReturnValue(boolean rv, File p, FsPermission permission)  {
/**
if (!rv) {
throw new IOException("Failed to set permissions of path: " + p +
" to " +
String.format("%04o", permission.toShort()));
}
**/
}

  

2 hadoop的编译:(不需要导入eclipse)
环境:Cygwin,Ant
Ant后会生成:\release-1.2.0\build\hadoop-core-1.2.1-SNAPSHOT.jar
改名为 hadoop-core-1.2.0 覆盖 \apache-nutch-1.7\lib\hadoop-core-1.2.0.jar即可。


异常
java.io.IOException: Job failed!
解决方案:

Src中的:
<property>
<name>plugin.folders</name>
<value>./src/plugin</value>
<description>./src/pluginDirectories where nutch plugins are located. Each
element may be a relative or absolute path. If absolute, it is used
as is. If relative, it is searched for on the classpath.</description>
</property> 记住是单数哦 bin中的:
plugin文件夹是单数,所以这里要做一下修改。
<property>
<name>plugin.folders</name>
<value>./src/plugins</value>
<description>./src/pluginDirectories where nutch plugins are located. Each
element may be a relative or absolute path. If absolute, it is used
as is. If relative, it is searched for on the classpath.</description>
</property>
异常:nutch下载的html不完整的因素
1 http://news.163.com/ skipped. Content of size 481597 was truncated to 65376
解决方案:
将conf/nutch-default.xml 将 parser.skip.truncated 为false 2 http请求的字节限制
<property>
  <name>http.content.limit</name>
  <value>-1</value>
  <description>The length limit for downloaded content using the http://
  protocol, in bytes. If this value is nonnegative (>=0), content longer
  than it will be truncated; otherwise, no truncation at all. Do not
  confuse this setting with the file.content.limit setting.
  </description>
</property>
异常:
种子添加了,http://www.gov.cn/
regex-urlfilter.txt 中添加了 +^http://www.gov.cn/
配置完全没错,但是爬虫却没采集到任何东西
原因:
对方设置了机器人协议。
解决方案:
如果要修改:Fetcher 类
/**
if (!rules.isAllowed(fit.u.toString())) {
// unblock
fetchQueues.finishFetchItem(fit, true);
if (LOG.isDebugEnabled()) {
LOG.debug("Denied by robots.txt: " + fit.url);
}
output(fit.url, fit.datum, null, ProtocolStatus.STATUS_ROBOTS_DENIED, CrawlDatum.STATUS_FETCH_GONE);
reporter.incrCounter("FetcherStatus", "robots_denied", 1);
continue;
}**/
异常 : unzipBestEffort returned null

转载自:http://blog.chinaunix.net/uid-8345138-id-3358621.html

Nutch爬虫爬取某网页是出现下列异常:

ERROR http.Http (?:invoke0(?)) - java.io.IOException: unzipBestEffort returned null
ERROR http.Http (?:invoke0(?)) - at org.apache.nutch.protocol.http.api.HttpBase.processGzipEncoded(HttpBase.java:472)
ERROR http.Http (?:invoke0(?)) - at org.apache.nutch.protocol.http.HttpResponse.<init>(HttpResponse.java:151)
ERROR http.Http (?:invoke0(?)) - at org.apache.nutch.protocol.http.Http.getResponse(Http.java:63)
ERROR http.Http (?:invoke0(?)) - at org.apache.nutch.protocol.http.api.HttpBase.getProtocolOutput(HttpBase.java:208)
ERROR http.Http (?:invoke0(?)) - at org.apache.nutch.fetcher.Fetcher$FetcherThread.run(Fetcher.java:173)

经过调试发现异常来源于:

java.io.IOException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:137)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)

该异常原因:

此页面采用这个是一个分段传输,而nutch爬虫则默认采用了非分段式处理,导致构造GZIP时出错,从而影响了后面的GZIP解压失败。

是否是分段传输可以在Http headers里面看到,如果是分段传输则有:transfer-encoding:chunked这样一个响应。

处理方法:

1. 修改接口org.apache.nutch.metadata.HttpHeaders, 添加:

  1. public final static String TRANSFER_ENCODING = "Transfer-Encoding";

2. 在nutch中的org.apache.nutch.protocol.http.HttpResponse类中已经提供了分段传输类型的处理方法:

  1. private void readChunkedContent(PushbackInputStream in,
  2. StringBuffer line)

我们只需要在HttpResponse的构造方法总调用该方法即可,添加如下代码:

  1. String transferEncoding = getHeader(Response.TRANSFER_ENCODING);
  2. if(transferEncoding != null && transferEncoding.equalsIgnoreCase("chunked")){
  3. StringBuffer line = new StringBuffer();
  4. this.readChunkedContent(in, line);
  5. }else{
  6. readPlainContent(in);
  7. }

修改完成,运行测试。

刚才不能爬取的站点终于可以爬取了

=========================================================

注:

1.有两个HttpResponse类,一个在protocol.http里面,一个在protocol.httpclient里面,我们需要修改的是前者。

2.Nutch2.0已将readChunkedContent方法删掉,故贴上Nutch1.5的方法,将这个方法放入HttpResponse:

点击(此处)折叠或打开

  1. private void readChunkedContent(PushbackInputStream in, StringBuffer line)
  2. throws HttpException, IOException {
  3. boolean doneChunks = false;
  4. int contentBytesRead = 0;
  5. byte[] bytes = new byte[Http.BUFFER_SIZE];
  6. ByteArrayOutputStream out = new ByteArrayOutputStream(Http.BUFFER_SIZE);
  7. while (!doneChunks) {
  8. if (Http.LOG.isTraceEnabled()) {
  9. Http.LOG.trace("Http: starting chunk");
  10. }
  11. readLine(in, line, false);
  12. String chunkLenStr;
  13. // if (LOG.isTraceEnabled()) { LOG.trace("chunk-header: '" + line +
  14. // "'"); }
  15. int pos = line.indexOf(";");
  16. if (pos < 0) {
  17. chunkLenStr = line.toString();
  18. } else {
  19. chunkLenStr = line.substring(0, pos);
  20. // if (LOG.isTraceEnabled()) { LOG.trace("got chunk-ext: " +
  21. // line.substring(pos+1)); }
  22. }
  23. chunkLenStr = chunkLenStr.trim();
  24. int chunkLen;
  25. try {
  26. chunkLen = Integer.parseInt(chunkLenStr, 16);
  27. } catch (NumberFormatException e) {
  28. throw new HttpException("bad chunk length: " + line.toString());
  29. }
  30. if (chunkLen == 0) {
  31. doneChunks = true;
  32. break;
  33. }
  34. if ((contentBytesRead + chunkLen) > http.getMaxContent())
  35. chunkLen = http.getMaxContent() - contentBytesRead;
  36. // read one chunk
  37. int chunkBytesRead = 0;
  38. while (chunkBytesRead < chunkLen) {
  39. int toRead = (chunkLen - chunkBytesRead) < Http.BUFFER_SIZE ? (chunkLen - chunkBytesRead)
  40. : Http.BUFFER_SIZE;
  41. int len = in.read(bytes, 0, toRead);
  42. if (len == -1)
  43. throw new HttpException("chunk eof after "
  44. + contentBytesRead + " bytes in successful chunks"
  45. + " and " + chunkBytesRead + " in current chunk");
  46. // DANGER!!! Will printed GZIPed stuff right to your
  47. // terminal!
  48. // if (LOG.isTraceEnabled()) { LOG.trace("read: " + new
  49. // String(bytes, 0, len)); }
  50. out.write(bytes, 0, len);
  51. chunkBytesRead += len;
  52. }
  53. readLine(in, line, false);
  54. }
  55. if (!doneChunks) {
  56. if (contentBytesRead != http.getMaxContent())
  57. throw new HttpException(
  58. "chunk eof: !doneChunk && didn't max out");
  59. return;
  60. }
  61. content = out.toByteArray();
  62. parseHeaders(in, line);
  63. }

3.修改构造方法的地方在call readPlainContent的地方。

could only be replicated to  nodes, instead of 

周末机房断电,然后hadoop爆出如题的错误,解决方案就是关闭所有节点的防火墙,相关命令如下:

查看防火墙状态:
/etc/init.d/iptables status
暂时关闭防火墙:
/etc/init.d/iptables stop
禁止防火墙在系统启动时启动
/sbin/chkconfig --level iptables off
重启iptables:
/etc/init.d/iptables restart

nutch 异常集锦的更多相关文章

  1. 【Apache Nutch系列】Nutch2.0配置安装异常集锦

    1.java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration Exception in thread &qu ...

  2. SP Flash Tool使用异常集锦

    1.The load scatter file is invalid无法载入scatter文件 (ubuntu下)我如果我们在使用MTK的Smart Phone Flash Tool过程中无法载入Sc ...

  3. java常见异常集锦

    1. java.lang.nullpointerexception 这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对 ...

  4. JAVA常见异常集锦(持续更新)

    No1:Nested in org.springframework.beans.factory.parsing.BeanDefinitionParsingException 2013-07-02 10 ...

  5. MyBatis 异常 集锦

    异常1.使用映射器 (还没有使用Spring) 异常信息摘要: org.apache.ibatis.binding.BindingException: Type interface com.jege. ...

  6. Hibernate 异常 集锦

    异常1.Error parsing JNDI name [foo] 异常信息摘要: org.hibernate.engine.jndi.JndiException: Error parsing JND ...

  7. JPA 系列教程 异常 集锦

    异常1.hibernate升级到3.5版本 异常信息摘要: Associations marked as mappedBy must not define database mappings like ...

  8. Tensorflow异常集锦

    一.tensorflow checkpoint报错 在调用tf.train.Saver#save时,如果使用的路径是绝对路径,那么保存的checkpoint里面用的就是绝对路径:如果使用的是相对路径, ...

  9. Hibernate 菜鸟教程 异常 集锦

    异常1.Error parsing JNDI name [foo] 异常信息摘要: org.hibernate.engine.jndi.JndiException: Error parsing JND ...

随机推荐

  1. NYOJ 38 布线问题_(解法2 Prim算法)

    时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 南阳理工学院要进行用电线路改造.如今校长要求设计师设计出一种布线方式.该布线方式须要满足下面条件: 1.把全部的楼都供 ...

  2. POJ 3614 Sunscreen 优先队列 贪心

    题意 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受不住 ...

  3. PureMVC(JS版)源码解析(一):观察者模式解析

          假设一种情景,在程序开发中,我们需要在某些数据变化时,其他的类做出相应,例如在游戏中,升级一件装备,会触发玩家金币数量改变,背包数据改变和冷却队列数据改变等等.我们不可能设置setInte ...

  4. SharePoint Dialog 使用

    SharePoint中弹出模态窗口对体验提高太大了 方法为: 父页面中调用子页面: function showDialog() {        var options = {             ...

  5. PHP能得到你是从什么页面过来的,r…

    在开发web程序的时候,有时我们需要得到用户是从什么页面连过来的,这就用到了referer. 它是http协议,所以任何能开发web程序的语言都可以实现,比如jsp中是: request.getHea ...

  6. grunt 构建工具(build tool)初体验

    操作环境:win8 系统,建议使用 git bash (window下的命令行工具) 1,安装node.js 官网下载:https://nodejs.org/  直接点击install ,会根据你的操 ...

  7. javascript技巧字典【转藏】

    2015-12-31 js判断undefined类型 if (reValue== undefined){    alert("undefined");    }  发现判断不出来, ...

  8. PHP一个最简单的CMS内容管理系统

    博客是一般程序员的入手戏,写得好写不好,有没有兴趣,逻辑性够不够都从这个里面入手 我现在摒弃前台.重点讲解下如何开发一个简单的CMS系统所需要的步骤: 1.清楚流程 1--------登录后台 2-- ...

  9. python基础知识六

    博客园的博文对每篇博文的长度似乎做了限制 面向对象编程, 在程序何种,根据操作数据的函数或语句块来设计程序.这被成为面向过程的编程.还有一种把数据和功能结合起来,用称为对象的东西包裹起来组织组织程序的 ...

  10. .net下载文件方法

    1.以文件流下载 byte[] fileStr=new byte[5]; MemoryStream btMs = new MemoryStream(fileStr); //以字符流的形式下载文件 by ...