Red Hat Enterprise Linux 5下搭建Nutch 1.3


我的安装环境Red Hat Enterprise Linux 5,jdk6,tomcat6。

1.   环境需求

1.1        Sun JDK 1.5 or 更高版本,设置NUTCH_JAVA_HOME为您的JVM安装的根。

1.2        Apache’s Tomcat 5.x or 更高版本。

1.3        1Gb的硬盘空间

2.   准备开始

首先你需要得到nutch的安装包

http://labs.renren.com/apache-mirror//nutch/

我下载的是apache-nutch-1.3-bin.tar.gz。解压并进入他的根目录

执行如下命令

runtime/local/bin/nutch得到-bash:runtime/local/bin/nutch: 权限不够。说明nutch没有执行权限

chomd 755 runtime/local/bin/nutch  (付给nutch执行权限)

再执行runtime/local/bin/nutch将显示nutch命令的用法。

很好!你可以准备“抓“你的网站了,你需要给你的crawler一个名字,这是必须的。否则他不能“抓”。

编辑$NUTCH_HOME/conf/nutch-site.xml($NUTCH_HOME/runtime/local/conf/nutch-site.xml with version >= 1.3)添加如下内容

<property>

 <name>http.agent.name</name>

 <value>你的CRAWLER的名字www.bkjia.com</value>

</property>

用任何你想要的名字代替“你的CRAWLER的名字www.bkjia.com”。

现在我们要准备crawl,有两种方法来crawl。

3.抓取命令

当你打算爬上少数Web服务器上的约100万页,检索命令是比较合适的。

抓取命令:配置

要抓东西,你必须配置的东西

A.创建一个目录,在此目录中创建一个文件,该文件里存放网址。例如,要抓取Nutch的网站,你不妨先创建文件名为urls/nutch的文件,该文件里只是包含Nutch的主页的网址。从这个网页,所有其他的Nutch的页面应该可以访问到。因此该文件应该包含 http://lucene.apache.org/nutch/

B.编辑文件$NUTCH_HOME/runtime/local/conf/regex-urlfilter.txt并且代替

# accept anything else+.  

匹配您要抓取的域。例如,如果你希望限制​​抓取到apache.org域中,该行应改为:

+^http://([a-z0-9]*\.)*apache.org/ 

这个这则表达式将包括所有的apache的网址。

抓取命令:运行抓取

一旦事情配置好,运行抓取是很容易的。只需使用抓取命令。其选项包括:

·        -dir dir names thedirectory to put the crawl in.

·        -threads threads determines thenumber of threads that will fetch in parallel.

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

·        -topN N determines the maximum number of pages that will be retrieved ateach level up to the depth.

典型的命令bin/nutch crawl urls/nutch -dir crawl -depth 3 -topN 50 

{Typicallyone starts testing one's configuration by crawling at shallow depths, sharplylimiting the number of pages fetched at each level (-topN), and watching theoutput to check that desired pages are fetched and undesirable pages are not.Once one is confident of the configuration, then an appropriate depth for afull crawl is around 10. The number of pages per level (-topN) for a full crawlcan be from tens of thousands to millions, depending on your resources.}

Nutch的详细介绍:请点这里
Nutch的下载地址:请点这里

相关内容