歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Red Hat Enterprise Linux 5下搭建Nutch 1.3

Red Hat Enterprise Linux 5下搭建Nutch 1.3

日期:2017/2/28 16:00:14   编辑:Linux教程

我的安裝環境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.linuxidc.com</value>

</property>

用任何你想要的名字代替“你的CRAWLER的名字www.linuxidc.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的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved