zoukankan      html  css  js  c++  java
  • nutch遇到的问题

    1、在重新格式化一个新的分布式文件时,需要将你NameNode上所配置的dfs.name.dir这一namenode用来存放NameNode 持久存储名字空间及事务日志的本地文件系统路径删除,同时将各DataNode上的dfs.data.dir的路径 DataNode 存放块数据的本地文件系统路径的目录也删除。如本此配置就是在NameNode上删除/home/hadoop/NameData,在DataNode上删除/home/hadoop/DataNode1和/home/hadoop/DataNode2。

           这是因为Hadoop在格式化一个新的分布式文件系统时,每个存储的名字空间都对应了建立时间的那个版本(可以查看/home/hadoop /NameData/current目录下的VERSION文件,上面记录了版本信息),在重新格式化新的分布式系统文件时,最好先删除NameData 目录。必须删除各DataNode的dfs.data.dir。这样才可以使namedode和datanode记录的信息版本对应。
         否则会出现能够启动datanode,但无法访问,也无法结束的错误,如下:

    hadoop@HadoopHost:~/HadoopInstall/hadoop$ bin/stop-all.sh
    stopping jobtracker
    125.216.227.**2: stopping tasktracker
    125.216.227.**3: stopping tasktracker
    stopping namenode
    125.216.227. ** 2: no datanode to stop
    125.216.227. ** 3: no datanode to stop
    125.216.227. ** 1: stopping secondarynamenode

    2、如何绕过目标站点的robots.txt限制 
    多数站点都是只允许百度、google等搜索引擎抓取的,所以会在robots.txt里限制其他爬虫。 
    nutch自然是会遵循robots协议的,但是我们可以通过修改nutch源码来绕过限制。 
    相关代码位于(nutch版本1.5.1,其他版本未测试): 
    org.apache.nutch.fetcher.Fetcher的run方法. 

    找到以下几行代码并注释掉就OK了。 

    if (!rules.isAllowed(fit.u)) {
        // 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;
    }

    3、url掉转导致html parse不成功的问题 
    在抓取百度百科的景点数据时,发现部分页面不会走html parse部分的逻辑,而我的plugin是基于HtmlParserFilter扩展点的,因而没有生效。 
    后来发现请求部分页面的链接返回的http状态为301,跳转之后才会到真正页面,而nutch默认是不会抓取跳转后的页面的.这时需要修改nutch-site.xml,加入以下配置即可,nutch-default.xml里的默认值是0,我们这里改成一个大于0的值,nutch就会继续抓取跳转后的页面了。 

    <property>
      <name>http.redirect.max</name>
      <value>2</value>
      <description>The maximum number of redirects the fetcher will follow when
      trying to fetch a page. If set to negative or 0, fetcher won't immediately
      follow redirected URLs, instead it will record them for later fetching.
      </description>
    </property>

    4、抽取的过程中发现某些属性老是抽不到,而在不使用nutch抓取的情况下是能抽到的,进而怀疑nutch抓取的页面不全。于是去google了一下"nutch content limit",发现nutch有这么一个配置项: 

    <property>  
      <name>http.content.limit</name>  
      <value>65536</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>  

    用来限制抓取内容的大小,放大10倍后,问题解决。 
    需要注意的是nutch还有一个很容易混淆的配置项: 

    <property>  
      <name>file.content.limit</name>  
      <value>65536</value>  
      <description>The length limit for downloaded content using the file://  
      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 http.content.limit setting.  
      </description>  
    </property>  

    两个配置用于的协议不同,前者是http协议,后者是file协议,我一开始就配置错了,折腾了半天。。。 
    PS:最后推荐两篇介绍nutch的文章,在官方文档不那么给力的情况下,这两篇文章给了我不小的帮助,感谢下作者。 
    http://www.atlantbh.com/apache-nutch-overview/ 对nutch的整体流程做了介绍 

    http://www.atlantbh.com/precise-data-extraction-with-apache-nutch/ 用实际例子介绍了nutch plugin的开发和部署

    参考:http://lc87624.iteye.com/blog/1625677

  • 相关阅读:
    Flink:What is stream processing?
    Flink1.10.1集成Hadoop3.0.0源码编译实战
    2003-Can't connect to Mysql on '主机名'(10061)
    Mybatis:Tag name expected
    谷歌浏览器安装json格式化插件
    kafka最佳实践:Kafka Best Practices
    kafka生产者性能监控:Monitor Kafka Producer for Performance
    kafka2.3性能测试:Kafka 2.3 Performance testing
    Tomcat 8 Invalid character found in the request target. The valid characters are defined in RFC 3986
    Springboot集成Mybatis、JPA
  • 原文地址:https://www.cnblogs.com/dgy5554/p/3973419.html
Copyright © 2011-2022 走看看