---
title: "eclipse部署配置nutch1.3"
author: "wangwei3"
date: "2010-11-19T12:15:06Z"
tags: []
categories: ["互联网"]
slug: "eclipse-nutch1-3"
draft: false
lastmod: "2011-11-18T17:15:09Z"
id: 816056
url: "https://wangwei3.iteye.com/blog/816056"
---

<span style="color:red">**原创文章，转载请注明出处  nutch群：74985182 欢迎加入交流**</span>

nutch是在hadoop基础上做的，由于hadoop只在linux上运行，里面涉及到大量的操作linux程序，所以我们在部署的时候必须先安装cygwin环境

**一、安装cygwin环境**cygwin是windows下模拟linux环境的免费软件

下载安装程序：<http://www.cygwin.com/setup.exe>
安装完成后运行setup.exe点击下一步如下图
![](http://www.programarts.com/cfree_ch/doc/help/UsingCF/CompilerSupport/Cygwin/Cygwin1.PNG)
界面出现三种安装模式:
Install from Internet，这种模式直接从Internet安装，适合网速较快的情况； 
Download Without Installing，这种模式只从网上下载Cygwin的组件包，但不安装； 
Install from Local Directory，这种模式与上面第二种模式对应，当你的Cygwin组件包已经下载到本地，则可以使用此模式从本地安装Cygwin。 

我选择直接下载(下载这东西超费劲)
下一步后出现一下界面需要选择安装目录
![](http://www.programarts.com/cfree_ch/doc/help/UsingCF/CompilerSupport/Cygwin/Cygwin2.PNG)
默认在C:\cygwin\，你也可以选择自己的安装目录，然后选择“下一步”

这一步我们可以选择安装过程中从网上下载的Cygwin组件包的保存位置，选择完以后，点击“下一步”

这一步选择连接的方式，选择你的连接方式，选默认的“diret Connection”然后选择“下一步”

这一步需要选择下载的服务地址，寻找Cygwin中国镜像的地址：http://www.cygwin.cn，如果找不到就add一下。我图方便选择了tw的地址，点击“下一步”

这一步选择需要安装的内容
![](http://www.programarts.com/cfree_ch/doc/help/UsingCF/CompilerSupport/Cygwin/Cygwin6.PNG)
常用的有default列表(表示值安装默认的安装项)、Install（表示安装全部程序）、Reinstall(表示重新安装程序),如果带宽允许就安装Install，一步到位，这样至少会下载1.5G的东东哦。我选择的是default主要是带宽慢，不知道以后会不会少东西，少了再补吧。哈哈。点击“下一步”

然后就都选默认就OK了

<span style="color:red">然后把cygwin/bin加入环境变量的path中。</span>

**二、Eclipse中部署nutch**
首先下载nutch，可以用svn或者到apache下载
nutch的主页是:http://lucene.apache.org/nutch/目前最新是1.3.下载tar.gz的文件。下载后解压到目录(我选择了D:/nutch).解压完成后打开eclipse
选择 file->新建->java project
选择 browse 按钮 选择工程解压到所在目录，在project name 写上project 名称。

![](http://dl.iteye.com/upload/picture/pic/102658/8a68837b-0fef-3667-9b5e-981e2a80d5e4.jpg)

点击下一步 选择libraries标签 然后选择Add Class Folder按钮 把conf文件夹加入

点击order and Export 标签 把conf置顶(top)
这步非常重要，我就是因为没有操作这步报了找不到plugin 的异常，看了官网才发现在测试文件 src/test中也有conf目录,而nutch会去找src/test/conf目录

然后选择finished完成！

然后会发现很多jar包没有，只需要选择build.xml 右键 -> run as ->ant build
便会下载所有的jar包。然后手动导入即可。

下面开始配置简单抓取

1. 在src目录下创建文件夹 urls 
   在urls文件夹下创建url.txt文件
    在url.txt文件中加入需要抓取的链接
     例如我下载的搜狐汽车我便加入
      
```java
http://auto.sohu.com/
```

      注意：必须以/结尾
2.配置nutch-site.xml

```java

<configuration>
	<property>
		<name>http.agent.name</name>
		<value>nutch-1.3</value>
		<description>user-agent这里可以自己写，伪装成IE或者谷歌爬虫等</description>
	</property>

	<property>
		<name>searcher.dir</name>
		<value>F:\testdb\ser</value>
		<description>索引目录.</description>
	</property>

	<property>
		<name>http.agent.url</name>
		<value>http://www.google.com/</value>
		<description>爬虫网站</description>
	</property>
	<property>
		<name>http.agent.email</name>
		<value>google@gmail.com</value>
		<description>可以联系到爬虫的mail</description>
	</property>
</configuration>

```


3.配置nutch-default.xml

```java

<property>
  <name>plugin.folders</name>
  <value>./src/plugin</value>
  <description>Directories where nutch plugins are located.  Each
  element may be a relative or absolute path.  If absolute, it is used
  as is.  If relative, it is searched for on the classpath.</description>
</property>

```


4.配置regex-urlfilter.txt

```java
# accept anything else
+^http://([a-z0-9]*\.)*sohu.com/
```

这里主要是根据自己的条件来过滤不需要下载的链接

5.运行
![](http://dl.iteye.com/upload/picture/pic/102660/a3aac187-028a-3acb-92ad-b70f2c3004d6.jpg)

如果需要solr就配置上 -solr http://localhost:8983/solr/ 
这个地址是solr服务的地址，需要先启动solr后才可配置，否则会报找不到solr服务的异常
否则可以忽略



配置完成后直接运行就可以了！
nutch1.3初步就配置完成了。