nutch安装,使用,二次开发入门 ( by quqi99 )
作者:张华 发表于:2007-05-24 ( http://blog.csdn.net/quqi99 )
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明。
1 Nutch(windows环境下)1.1 Nutch安装由于运行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使用入门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,指明要抓取网站的顶级网址,写入: 2) 编辑conf/crawl-urlfilter.txt,修改MY.DOMAIN.NAME部分 # accept hosts in MY.DOMAIN.NAME #+^http://([a-z0-9]*.)*MY.DOMAIN.NAME/ 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 抓取整个因特网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 | | | | | | | | | | bin/nutch admin db -create | | | | | | bin/nutch inject db -dmozfile content.rdf.u8 -subset 3000 | | | bin/nutch generate db segments | 根据数据库内容,生成一个抓取列表(fetchlist) | | s1=`ls -d segments/2* | tail -1` | | | | | | bin/nutch updatedb db $s1 | | | | | | | | | bin/nutch generate db segments -topN 1000 | | | s2=`ls -d segments/2* | tail -1` | | | | | | bin/nutch updatedb db $s2 | | | | | | | | | bin/nutch generate db segments -topN 1000 | | | s3=`ls -d segments/2* | tail -1` | | | | | | bin/nutch updatedb db $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 注意,若查询字符串输出中文时出现编码问题,这个问题和nutch关系不大,主要是tomcat有关系,修改tomcat的server.xml,在Connector元素中增加属性: URIEncoding="UTF-8" useBodyEncodingForURI="true" 1.3 nutch的二次开发 参考: 资料
摘自:http://blog.csdn.net/quqi99/article/details/1624210
|