`

开源搜索引擎Nutch 0.9的安装使用

阅读更多

Nutch是Apache组织的一个开源项目,利用它用户可以 建立自己内部网的搜索引擎,也可以建立针对整个网络的搜索引擎。
一、Linux下的安装使用
  (我使用的操作系统是red hat as4)

  1.安装JDK,我安装的是JDK1.5 update11,安装方法到网上搜

  2.安装TOMCAT,我安装的是tomcat5.5.23,安装方法到网上搜,输入http://127.0.0.1:8080出现变态猫就ok了,可以进入下一步。

  3.到http://www.nutch.org下载Nutch 0.9,2007年4月2日发布的,嘿嘿。

    解压与安装
    下来的文件是nutch-0.9.tar.gz
    运行以下命令以解压:
    gunzip nutch-0.9.tar.gz            
    得到文件:nutch-0.9.tar
    再运行以下命令解包:
    tar –xvf nutch-0.9.tar
    终于得到了nutch-0.9目录,里面包含了nutch代码/文档

    测试
    进入nutch-0.9目录,执行bin/nutch,
    看到下列提示,则说明安装成功:
    Usage: nutch COMMAND
    where COMMAND is one of :
    ......

    设置待抓取网站
    在nucth-0.9目录下建立urls目录(也可以自己命名),在urls目录下建立个文件,我取名为nutch,没有扩展名,扩展名为.txt应该也可以
    打开刚才建立的这个名称为nutch的文件,输入待抓取的网站地址,如:
    http://www.sunleap.com/
    最后的/不能漏掉.

    编辑conf目录下的crawl-urlfilter.txt文件,该文件用于设置爬虫的过滤条件
    # accept hosts in MY.DOMAIN.NAME
    +^http://([a-z0-9]*\.)*MY.DOMAIN.NAME/
    修改为:
    # accept hosts in MY.DOMAIN.NAME
    +^http://([a-z0-9]*\.)*www.sunleap.com/
    表示抓取http://([a-z0-9]*\.)*www.sunleap.com/域名下的所有页面

    编辑conf目录下的nutch-site.xml文件,该文件用于将爬虫信息告诉被抓取的网站,如果不进行设置nutch不能运行.
    该文件默认为这样:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

    <!-- Put site-specific property overrides in this file. -->

    <configuration>
   
    </configuration>

    下面是我修改后的一个例子:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

    <!-- Put site-specific property overrides in this file. -->

    <configuration>
        <property>
          <name>http.agent.name</name>
          <value>myfirsttest</value>
          <description>HTTP 'User-Agent' request header. MUST NOT be empty -
          please set this to a single word uniquely related to your organization.

          NOTE: You should also check other related properties:
   
          http.robots.agents
          http.agent.description
          http.agent.url
          http.agent.email
          http.agent.version

          and set their values appropriately.

          </description>
        </property>

        <property>
          <name>http.agent.description</name>
          <value>myfirsttest</value>
          <description>Further description of our bot- this text is used in
          the User-Agent header.  It appears in parenthesis after the agent name.
          </description>
        </property>

        <property>
          <name>http.agent.url</name>
          <value>myfirsttest.com</value>
          <description>A URL to advertise in the User-Agent header.  This will
           appear in parenthesis after the agent name. Custom dictates that this
           should be a URL of a page explaining the purpose and behavior of this
           crawler.
          </description>
        </property>

        <property>
          <name>http.agent.email</name>
          <value>test@test.com</value>
          <description>An email address to advertise in the HTTP 'From' request
           header and User-Agent header. A good practice is to mangle this
           address (e.g. 'info at example dot com') to avoid spamming.
          </description>
        </property>

    </configuration>
    上述文件描述了爬虫的名称/描述/来自哪个网站/联系email等信息.

    抓取
    执行抓取并建立索引的命令:
    bin/nutch crawl urls -dir sunleap -depth 4 -threads 5 -topN 1000 >&logs/log1.log
    其中
        urls目录中的文件里记录了待爬网站地址
        -dir指定爬来的信息放到哪个目录下
        -depth 指定抓取的深度
        -thread 指定线程数
        -topN 指定抓取该网站的前若干页,这个参数对于抓取大网站的网页非常有用
        >&logs/log1.log指定日志存放位置,如果你想在控制台监视运行情况,可以不使用这行代码

    等待几分钟,抓取及建立索引结束

    配置tomcat
    删除Tomcat/webapps下的ROOT文件夹。
    复制nutch-0.9.war到到tomcat的webapps/下,同时改名为ROOT.war(Tomcat运行时将自动解开为ROOT目录)
    修改/webapps/ROOT/WEB-INF/classes/nutch-site.xml :
    将
    <configuration>
    </configuration>
    换成
    <configuration>
        <property>
            <name>searcher.dir</name>
            <value>/www/nutch0.9/sunleap</value>
        </property>
    </configuration>   
    把value里的内容替换为你实际存放抓取内容的地址,注意最后没有/,我开始加了/好像不行.


    为了支持中文需要修改tomcat的配置文件,打开tomcat\conf下的server.xml文件,将其中的Connector部分改成如下形式即可:
    <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
        enableLookups="false"
        redirectPort="8443"
        acceptCount="100"
        connectionTimeout="20000"
        disableUploadTimeout="true"
        URIEncoding="UTF-8" useBodyEncodingForURI="true" />
    注意最后一行的两项是新加的.

    利用tomcat搜索   
    重启tomcat,在浏览器中输入:http://127.0.0.1:8080
    出现nutch搜索界面,
    在搜索框中输入java并搜索,将看到你的搜索结果

二、Windows下的安装使用
    在安装nutch前先下载安装Cygwin,Cygwin是一个在Windows平台上模拟运行Unix的环境.
    nutch的安装/设置可以在windows下完成,但执行nutch的命令(如crwal)需要在Cygwin中进行.
    tomcat的配置同上. 

发表于 @ 2007年04月07日 20:55:00|评论(1 <script type="text/javascript"></script> )|编辑

新一篇: Webmin的安装使用 | 旧一篇: Hibernate几种产品简介

<script type="text/javascript"></script><script src="http://hi.images.csdn.net/js/blog/feedback.js" type="text/javascript"></script>
yutao175 发表于2007年8月30日 1:56:31  IP:举报
您好:
我初次使用nutch,是按照您的 <<开源搜索引擎Nutch 0.9的安装使用 >>
来做的.我有个问题想请教一下:
-----
修改/webapps/ROOT/WEB-INF/classes/nutch-site.xml :

<configuration>
</configuration>
换成
<configuration>
<property>
<name>searcher.dir</name>
<value>/www/nutch0.9/sunleap</value>
</property>
</configuration>
把value里的内容替换为你实际存放抓取内容的地址,注意最后没有/,我开始加了/

好像不行.
----
???? 我们并没有设置关于nutch的环境变量(我用env查询没有发现关于nutch的
安装路径的环境变量,只有一个指定NUTCH_JAVA_HOME的环境变量).那Tomcat是怎样
找到存储查询结果的sunleap这个目录的呢?
谢谢.
我的email 是leo.yu.175@hotmail.com
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics