在Ecipse中配置Nutch

在Windows下面配置Nutch有两种方法,一种是使用cygwin模拟Linux环境,另一种是配置到Eclipse中运行。因为linux环境不熟悉,所以还是决定使用eclipse了。

 

在Eclipse中配置Nutch的步骤:(Eclipse3.4, Nutch0.9)

第一步:下载release版本的nutch-0.9.tar.gz.解压到d盘.保证下载的nutch中没有.classpath和.projsect.即d:/nutch-0.9。注意解压路径中最好不要包含中文,因为将爬行结果在Tomcat中配置时,就可以直接指向保存结果的文件夹。

 

 

 

第二步: 修改nutch-0.9\conf目录下的nutch-site.xmlcrawl-urlfilter.txt两个文件

打开nutch-0.9\conf\nutch-site.xml文件。 

<configuration></configuration>中间插入以下内容:

 

<property>

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

<value>Jennifer</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>Jennifer</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>Jennifer</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>Jennifer</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>

 

 

并修改<value></value>中间的值,这里的设置是因为Nutch遵守了robots协议,在获取response时,把自己的相关信息提交给被爬行的网站,以供识别。所以设置成任何你喜欢的值都可以的。

 

打开Nutch-0.9\conf\crawl-urlfilter.txt文件

找到"+^http://([a-z0-9]*\.)* MY.DOMAIN.NAME/”,将其中的'MY.DOMAIN.NAME/'直接删除。

 

(为了后面的方便,建议在修改完成后将conf文件夹复制一下,并保存在硬盘的其他的地方。)

 

 

 

 

第三步:到下面两个页面去下载两个jar文件,他们分别是:

http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-mp3/lib/

http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-rtf/lib/

下载其中的jid3lib-0.5.1.jarrtf-parser.jar两个文件,并分别把他们拷贝到Nutch\src\plugin\parse-mp3\libNutch\src\plugin\parse-rtf\lib两个文件夹下。

也可以从本文的附件中下载。

 

 

 

第四步: 准备工作做好以后就可以在Eclipse中配置Nutch了。打开Eclipse后,我们开始建立Java project。具体的做法是:

File > New > Project > Java project创建Java项目(注意不是JavaWeb项目),给我们的项目命名,然后选择Create project from existing source,并指向你的Nutch录。

 

 

 点击Next后我们就能看到用于定义Java build的设置环境。在第一个选项卡source下面我们可以看到三个连接,我们需要选择第三个:Add project ‘Nutch’ to build path,点击之后我们就选择conf,完成以上步骤之后我们就将conf加入到了classpath中。注意:这里不是指上面的第三个选项卡。

 

 

现在需要我们选择Default output folder,在这里我们必须选择Nutch/conf作为它的Default output folder,否则就会找不到crawl-urlfilter.txt,从而不能完成网站的爬行,会出现以下提示:

Generator: 0 records selected for fetching, exiting ...

Stopping at depth=0 - no more URLs to fetch.

No URLs to fetch - check your seed list and URL filters.

 

 

 

第五步: 点击Finish,这时我们就完成了前续的配置工作,这时我们就可点击运行,选择Java Application点击OK,开始让Eclipse自己寻找项目的主类。我们选择Crawl-org.apache.nutch.crawl,点击OK。这时程序会报错,不过没关系,我们的目的只是运行一次。

这时我们可以回到nutch-0.9/conf目录下看下,我们可以看到里面的内容发生了改变,这时就需要我们还原原来conf下的内容,这时我们在第2步中另外保存的conf文件夹就起到了作用。(当然,新生成的东西并不影响我们的后续爬行工作,我们可以只考虑将原来conf下的内容复制回来,但是我个人觉得为了文件夹的管理和查找方便,我建议将新生成的内容全部删除后在将原来conf下的内容复制回来。还有一点需要我们注意,conf里面不可以有org文件夹,如果有的话delete,否则的话会影响index)当然,拷回来以后得记得刷新一下哦!

 

 

 

 

第六步: 点击菜单中的Run > Run Configurations,选中Arguments选项卡。

Program arguments中填写爬行命令,

如: urls -dir crawl -depth 2 -topN 50

 

urls: 自己创建的文件夹,位置在d:/nutch-0.9/urls,即项目的根目录下,该文件夹下需要一个文本文件,名字和后缀名任取,如:nutch.txt。该文件中填写要爬行的起始网页URL,如:http://www.baidu.com/ 。

 

-dir crawl: 设定存放爬行结果的文件夹,crawl文件夹在程序运行时会自动创建,如果已经存在该文件夹,运行时会报错。

 

-depth 2: 设定爬行时的深度,个人理解为爬行时的次数。

 

-topN 50: 设定一次爬行最多可以读取到的链接数。

 

VM arguments中填写:

-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log

 

从参数名称可以看出,这两个参数时用来设置存放日志文件的文件夹和文件名称。

 

填写完成后,点击apply完成提交。由于我们到目前为止还没有建立需要我们爬行的url地址,所以我们在提交完成后,点击close。

 

 

 

 

第七步: 现在我们就可以建立需要Nutch爬行的url地址:

在urls/nutch.txt文件中输入http://www.baidu.com/

 

然后在nutch-0.9/conf/crawl-urlfilter.txt 文件中 找到# accept hosts in MY.DOMAIN.NAME

将下面的+^http://([a-z0-9]*\.)*

改为+^http://([a-z0-9]*\.)*baidu.com/

 

建好之后,只要我们在点击工具栏上的运行按钮,我们就可以在Console的透视图中看到Nutch爬行的结果了。当然如果我们之前已经建立好了我们需要爬行的url地址,我们就可以直接点击run,这时我们也可以在Console的透视图中看到Nutch爬行的结果。

你可能感兴趣的:(eclipse,linux,hadoop,配置管理,cvs)