zoukankan      html  css  js  c++  java
  • Windows7环境下MyEclipse+Nutch2.2.1+Mysql搭建

    一、环境准备

    首先肯定是配置开发环境,这里暂时不作详细描述。

    需要的环境有jdk1.7,MyEclipse,SVN,ant,以及MyEclipse下的三个插件subclipse 、IvyDe和m2e,下载地址http://subclipse.tigris.org/update_1.8.xhttp://www.apache.org/dist/ant/ivyde/updatesite以及http://download.eclipse.org/technology/m2e/releases

    二、从svn检出项目,地址https://svn.apache.org/repos/asf/nutch/tags/release-2.2.1

    Finish完成导入。

    三、  修改ivy目录下的ivysetting.xml地址http://mirrors.ibiblio.org/maven2/(只有这个地址访问是正常的,其余的地址我尝试访问不了)

    四、  修改ivy目录下的ivy.xml(增加mysql访问依赖java包)

    修改gora-core版本为0.2.1,并解除注释gora-sql和mysql-connector-java

    五、  Cd 到目录执行Ant eclipse(直接在Eclipse下ant build貌似有问题)

    六、  回到Eclipse工程,刷新项目,会发现目录结构已经发生变化

    七、  看到还有一个错误,是编码的问题,工程右键Properties -> Resource ->utf-8

    八、  工程右键Build Path->Config Build Path->Order and Export下选中Conf 文件夹置顶

     

    九、  修改Conf文件夹下gora.properties配置mysql

     

    #Default MySQL properties        #
    ###############################
    gora.datastore.default=org.apache.gora.sql.store.SqlStore
    gora.datastore.autocreateschema=true
    gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
    gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
    gora.sqlstore.jdbc.user=root
    gora.sqlstore.jdbc.password=123456

    十、工程目录下新建文件夹urls,urls目录下新建一个文件url,里面输入要爬取的root_url,比如http://www.qq.com

    十一、配置conf目录下nutch-site.xml

    <property>
      <name>http.agent.name</name>
      <value>YourNutchSpider</value>
     </property>
     
     <property>
      <name>http.accept.language</name>
      <value>ja-jp, en-us,en-gb,en,zh-cn,zh-tw;q=0.7,*;q=0.3</value>
      <description>Value of the “Accept-Language” request header field.
      This allows selecting non-English language as default one to retrieve.
      It is a useful setting for search engines build for certain national group.</description>
     </property>
      
     <property>
      <name>parser.character.encoding.default</name>
      <value>utf-8</value>
      <description>The character encoding to fall back to when no other information
      is available</description>
     </property>
      
     <property>
      <name>plugin.folders</name>
      <value>src/plugin</value>
      <description>Directories 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>
    </pre><pre name="code" class="html"><!-- 为解决utf-8类中的空指针问题 -->
    <property>
    <span>	</span><name>generate.batch.id</name>
    <span>	</span><value>*</value>
    </property>
      
     <property>
      <name>storage.data.store.class</name>
      <value>org.apache.gora.sql.store.SqlStore</value>
      <description>The Gora DataStore class for storing and retrieving data.
      Currently the following stores are available: ….</description>
     </property>

    十二、 配置完上述步骤后配置命令运行Run Configuration选择org.apache.nutch.crawl.Crawler,参数设置urls -depth 3 -topN 5和-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log

    这时运行会遇到错误Exception in thread "main" java.io.IOException: Failed to set permissions of path: mphadoop-AdministratormapredstagingAdministrator606301699.staging to 0700

    十三、上述错误一般只是windows下才会遇到的,所以我们一般的做法是找到Hadoop-core-1.2.0源码中的org.apache.hadoop.fs下的FileUtil.java修改其中的CheckReturnValue方法,注释掉其中的内容

     private static void checkReturnValue(boolean rv, File p, 
                                           FsPermission permission
                                           ) throws IOException {
    //    if (!rv) {
    //      throw new IOException("Failed to set permissions of path: " + p + 
    //                            " to " + 
    //                            String.format("%04o", permission.toShort()));
    //    }
      }


     然后编译成java包替换我们工程build/lib下的hadoop-core-1.2.0.jar。

    另外一种方法是找到FileUtil.java编译过后的class文件,替换掉jar包中相应的class文件FileUtil.clas和FileUtil$CygPathCommand.clas(用压缩软件打开就行)

    附上已修改编译的Hadoop-core-1.2.0.jar文件,包含单独的FileUtil.class文件,链接http://download.csdn.net/detail/cvj1991/7727299(1个积分,有钱的捧个钱场)和直接下载链接https://files.cnblogs.com/e-life/hadoop-core-1.2.0.rar

    十四、接下来再运行就没有问题

    这里注意,你会发现mysql数据库中很多记录除了id,status这几个基本字段有数据外其他值都是null,这是正常情况,请注意status字段,

    status    记录抓取状态
            1     unfetched (links not yet fetched due to limits set in regex-urlfilter.txt, -TopN crawl parameters, etc.)  
            2     fetched (page was successfully fetched)  
            3     gone (that page no longer exists)  
            4     redir_temp (temporary redirection — see reprUrl below for more details)  
            5     redir_perm (permanent redirection — see reprUrl below for more details)  
            34     retry  
            38     not modified     

    这是因为我们的topN设置太小,所以很多url被限制抓取了(当然还有可能是url被regex-urllfilter过滤了),自己注意一下就好了。

    Good Job,到此我们就完成了整个流程的配置和运行。

  • 相关阅读:
    redis 操作使用
    sublime 设置像IDE一样的 ctrl+鼠标左键 跳转到定义方法
    tensorflow进阶篇-5(反向传播2)
    tensorflow进阶篇-5(反向传播1)
    Linux后台进程管理以及ctrl+z(挂起)、ctrl+c(中断)、ctrl+(退出)和ctrl+d(EOF)的区别(转)
    mysql基础知识(3)
    mysql基础知识(2)
    tensorflow进阶篇-4(损失函数3)
    tensorflow进阶篇-4(损失函数2)
    mysql基础知识(1)
  • 原文地址:https://www.cnblogs.com/e-life/p/3897881.html
Copyright © 2011-2022 走看看