nutch安装,使用,二次开发入门 ( by quqi99 )

                   nutch安装,使用,二次开发入门 ( by quqi99 )

作者:张华 发表于:2007-05-24  ( http://blog.csdn.net/quqi99 )

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明。


1 Nutch(windows 环境下 )

1.1 Nutch 安装

    参考资料: http://www.blogjava.net/dev2dev/archive/2006/02/01/29415.aspx Nutch Windows 中安装之细解

由于运行 Nutch 自带的脚本命令需要 Linux 的环境,所以必须首先安装 Cygwin 来模拟这种环境。

1 )安装 cgwin

2) 下载 nutch-0.9.tar.gz, winrar 解压后,例如放在 g:/nutch-0.9

3) 安装 nutch ,打开 cgwin ,运行命令:

   cd /cygdrive/g/nutch-0.9  ( 也就是进入 nutch 解压的目录 )

   bin/nutch                  ( 执行 nutch 脚本安装 )

4) OK !

1.2 Nutch 使用入门

资料: http://blog.csdn.net/zjzcl/archive/2006/02/06/593138.aspx

Nutch 使用之锋芒初试   (包括下载及检索两部分)

注意:请使用 JDK1.5 ,用 JDK1 4 会报错误: unsupported major.minor version 49.0 n

设置环境变量: NUTCH_JAVA_HOME = c:/jdk1.5

1.2.1 抓取少量网站

1) nutch 的安装目录新建一个文件 url.txt ,指明要抓取网站的顶级网址,写入:

   http://www.aerostrong.com.cn

2) 编辑 conf/crawl-urlfilter.txt ,修改 MY.DOMAIN.NAME 部分

   # accept hosts in MY.DOMAIN.NAME

#+^http://([a-z0-9]*.)*MY.DOMAIN.NAME/

+^http://www.aerostrong.com.cn

    3) 运行脚本命令抓取,脚本命令全是 linux 下的 shell 命令,在 window 下运行它需要 cgwin ,打开 cgwin ,运行命令 :

   cd /cygdrive/g/nutch-0.9  ( 也就是进入 nutch 解压的目录 )

   bin/nutch crawl url.txt -dir crawled -depth 3 -threads 4 >& crawl.log

   参数解释:

      -dir dir names the directory to put the crawl in.

-depth depth indicates the link depth from the root page that should be crawled.

-delay delay determines the number of seconds between accesses to each host.

-threads threads determines the number of threads that will fetch in parallel.

1.2.2 抓取整个因特网

http://hedong.3322.org/archives/000247.html 试用 nutch

1 、概念解释:

   1 web database: nutch 所知道的 page, 以及在这些 page 里头的 links ( injector 通过 DMOZ 往里添加 page Dmoz(The Open Directory Project/ODP) 是一个人工编辑管理的目录集合,为 搜索引擎提供结果或数据。 )

   2)  segments. :是指 page 的一个集合,对它进行抓取与索引都作为同一个单元对待。它包含以下类型:

       Fetchlist 这些 page 的名称的集合

       Fetcher output: 这些 page 文件的集合

       Index:  lucene 格式的索引输出

2 建立 web database segments

  

初始准备

 

 

 

mkdir db

建立目录存放web database

 

mkdir segments

 

 

bin/nutch admin db -create

建一个新的空的数据库( 这步出错了 )

第一轮抓取

 

 

 

bin/nutch inject db -dmozfile content.rdf.u8 -subset 3000

DMOZ 列表中取得URL 并加入数据库

 

bin/nutch generate db segments

根据数据库内容,生成一个抓取列表(fetchlist)

 

s1=`ls -d segments/2* | tail -1`

刚才生成的抓取列表放在最后一个目录中,取其名

 

bin/nutch fetch $s1

利用机器人抓页面

 

bin/nutch updatedb db $s1

利用抓取结果更新数据库

第二轮抓取

 

 

 

bin/nutch analyze db 5

迭代5 次分析页面的链接

 

bin/nutch generate db segments -topN 1000

将排行前1000URL 生成新的抓取列表

 

s2=`ls -d segments/2* | tail -1`

执行抓取、更新、并迭代2 次分析链接

 

bin/nutch fetch $s2

 

 

bin/nutch updatedb db $s2

 

第三轮抓取

 

 

 

bin/nutch analyze db 2

 

 

bin/nutch generate db segments -topN 1000

 

 

s3=`ls -d segments/2* | tail -1`

 

 

bin/nutch fetch $s3

 

 

bin/nutch updatedb db $s3

 

 

bin/nutch analyze db 2

(为下一次做准备?)

索引并去重

 

 

 

bin/nutch index $s1

 

 

bin/nutch index $s2

 

 

bin/nutch index $s3

 

 

bin/nutch dedup segments dedup.tmp

 

1.2.3 检索

   1) nutch-0.9.war 包丢到 tomcat 发布目录

   2) 修改配置文件指定索引库 .( WEB-INFclasses 下的 nutch-site.xml):

     <?xml version="1.0"?>
   <?xml-stylesheet type="text/xsl" href="nutch-conf.xsl"?>

    <nutch-conf>
    <property>
     <name>searcher.dir</name>
     <value>G:/nutch-0.9/crawled</value>
    </property>
   </nutch-conf>

注意,当复制上述配置文件时,如果出现下列错误,是因为复制文件时带有空格或编码格式,重敲一遍即可 : java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence

3) 测试 http://172.17.1.122:8081

  注意,若查询字符串输出中文时出现编码问题,这个问题和 nutch 关系不大,主要是 tomcat 有关系,修改 tomcat server.xml ,在 Connector 元素中增加属性:

  URIEncoding="UTF-8" useBodyEncodingForURI="true"

1.3 nutch 的二次开发

  参考:

http://www.mysoo.com.cn/news/2007/200721679.shtml Google 式的搜索引擎实现

http://today.java.net/pub/a/today/2006/01/10/introduction-to-nutch-1.html Introduction to Nutch, Part 1: Crawling

http://today.java.net/pub/a/today/2006/02/16/introduction-to-nutch-2.html Introduction to Nutch, Part 2: Searching

 

资料

Nutch相关资料收集整理 http://www.gispark.com/html/spatial/2006/1008/294.html    

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

quqi99

你的鼓励就是我创造的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值