nutch环境配置备忘:
1、Cygwin安装
我使用的是Cygwin本地安装版,local install,并把所有组件都设为installed即可。
2、解压nutch
将NUTCH-0.9解压后复制到HOME/Administrator下,或者在Cygwin下使用gunzip命令皆可。
3、安装JDK
可能是我的系统最近不正常吧,我的JDK必须安装在nutch目录下才能找到(正确设置了环境变量,可是只要安装在其它位置,就找不到JDK,如果哪位能知道原因,请指教,非常感谢!)我这里的安装路径是:C:\cygwin\home\Administrator\nutch-0.9\JDK

环境变量设置如下:
JAVA_HOME C:\cygwin\home\Administrator\nutch-0.9\JDK
CLASS_PATH 添加 ;C:\cygwin\home\Administrator\nutch-0.9\JDK\lib
NUTCH_JAVA_HOME C:\cygwin\home\Administrator\nutch-0.9\JDK
PATH 添加 ;C:\cygwin\home\Administrator\nutch-0.9\JDK\bin

4、使用爬虫之前的准备
首先在bin目录下新建目录urls,在urls中新建一个文本文家nutch.txt,将要抓取的网站地址输入,比如http://www.sina.com.cn/(注意最后的/一定要有)

打开conf\crawl-urlfilter.txt文件,将
# accept hosts in MY.DOMAIN.NAME
+^http://([a-z0-9]*\.)*MY.DOMAIN.NAME/

改为
# accept hosts in MY.DOMAIN.NAME
+^http://([a-z0-9]*\.)*sina.com.cn/(这里也要有/呦)

打开nutch/conf/nutch-site.xml文件,修改<configuration></configuration>为:
<configuration>
<property>
<name>http.agent.name</name>
<value>HD nutch agent</value>
</property>
<property>
<name>http.agent.version</name>
<value>1.0</value>
</property>
</configuration>
保存
5、开始爬
进入nutch目录,进入bin目录
$sh nutch crawl urls -dir sina -depth 4 -threads 5 -topN 1000 >&logs/log1.log
crawl:通知nutch.jar,执行crawl的main方法。
urls:存放需要爬行的url.txt文件的目录
-dir sina 爬行后文件保存的位置
-depth 2:爬行次数,或者成为深度,不过还是觉得次数更贴切,建议测试时改为1。
-threads 指定并发的进程 这是设定为 4
-topN :一个网站保存的最大页面数。
**注意sina文件夹不能存在,会报错

曾经出现的错误:
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.
解决方法:在urls的nutch.txt中再添加一个URL即可,原因现在还不知道。

6、挂上服务器
当爬取网页成功之后,开始配置TOMCAT
TOMCAT的安装目录是:C:\Program Files\Apache Software Foundation\Tomcat 5.5

TOMCAT_HOME C:\Program Files\Apache Software Foundation\Tomcat 5.5
CALSSPATH 添加: %TOMECAT_HOME%\bin;

在服务器关闭的状态下,删除TOMCAT中WEBAPPS文件夹中的ROOT文件夹,将nutch-0.9.war拷贝到webapps下,改名为ROOT.war,启动TOMCAT,会自动解压出ROOT文件。
修改/webapps/ROOT/WEB-INF/classes/nutch-site.xml:

<configuration>
</configuration>
换成
<configuration>
<property>
<name>searcher.dir</name>
<value>C:\cygwin\home\Administrator\nutch-0.9\bin\dlut</value>
</property>
</configuration>
为了支持中文需要修改tomcat的配置文件,打开tomcat\conf下的server.xml文件,将其中的Connector部分改成如下形式即可:

<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false"
redirectPort="8443"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8" useBodyEncodingForURI="true" />
注意最后一行的两项是新加的.
利用tomcat搜索
重启tomcat,在浏览器中输入:http://127.0.0.1:8080
出现nutch搜索界面,
在搜索框中输入java并搜索,将看到你的搜索结果

***曾经出现的错误
org.apache.jasper.JasperException: /search.jsp(151,22) Attribute value language + "/include/header.html" is quoted with " which must be escaped when used within the value
这个错误困扰了我很长时间,后来在http://news.skelter.net/articles/2008/09/24/nutch-0-9-quoted-with-must-be-escaped
找到解答
解决方法是:把search.jsp的第151行改成
<jsp:include page="<%= language + \"/include/header.html\"%>"/>。问题解决
posted on 2010-01-01 11:49  Myhsg  阅读(985)  评论(0编辑  收藏  举报