1.准備(一下版本為本人使用版本)
- 下載JDK1.7,建議下載安裝版jdk-7u15-windows-x64.exe;(安裝,並配置JAVA_HOME,PATH,CLASSPATH路徑)
- 下載cygwin,下載安裝版cygwin-setup.exe;
- 下載tomcat,apache-tomcat-7.0.37.exe;
- 下載nutch,apache-nutch-1.2-bin.zip;
2.cygmin安裝與配置
雙擊cygwin-setup.exe安裝,一般都選默認即可
注意:選擇下載鏡像時一定避免選擇163.com的,因為這個是漢化的,以后會遇到兼容問題,要選美國服務器上的
下一步.....下一步....我的安裝位置是D:\tool\cygwin和D:\tool\cygwinPackage
最后桌面上出現圖標,能運行如下即可:

3.安裝nutch
3.1.解壓縮apache-nutch-1.2-bin.zip到D:\tool\cygwin\home下
3.2.打開cygwin,在cygwin環境下進入nutch-1.2目錄下(cd /home/nutch-1.2),使用命令 bin/nutch進行測試,正常的情況下出現的結果是,說明nutch可運行了:

4. 配置nutch
4.1.在D:\tool\cygwin\home\nutch-1.2\下新建一個目錄urls,在urls下建一個url.txt文件用以保存需要搜索的網站,在文件中輸入http://www.163.com,在D:\tool\cygwin\home\nutch-1.2下新建一個目錄logs,在logs目錄下新建log1.log文件用以保存日志文件
4.2.打開D:\tool\cygwin\home\nutch-1.2\conf\nutch-site.xml,按以下示例輸入
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>http.agent.name</name>
<value>mynutch</value>
<description>test
</description>
</property>
<property>
<name>http.agent.description</name>
<value>spider</value>
<description> spider
</description>
</property>
<property>
<name>http.agent.url</name>
<value>http://www.xxx.com </value>
<description>http://www.xxx.com
</description>
</property>
<property>
<name>http.agent.email</name>
<value>MyEmail</value>
<description>md.peter@163.com
</description>
</property>
</configuration>
4.3.打開文件D:\tool\cygwin\home\nutch-1.2\conf\crawl-urlfilter.txt文件,把MY.DOMAIN.NAME字符替換為myurl內的域名(比如我改成了“+^http://([a-z0-9]*/.)*163.com/”,其實更簡單點,直接刪除MY.DOMAIN.NAME這幾個字就可以了,也就是說,只保存+^http://([a-z0-9]*/.)*這幾個字就可以了,表示所有http的網站都同意爬行)。
4.4.運行爬蟲,在Cygwin輸入以下命令:
bin/nutch crawl urls/url.txt -dir crawled -depth 4 -threads 5 -topN 1000 >&logs/log1.log
這里-dir表示存儲的目錄,-depth表示網址爬的深度,最后是指明日志文件
運行結束后,你可以打開日志文件查看爬蟲運行的詳細過程,以及存儲目錄中的文件:

5.tomcat上運行nutch
5.1.把nutch-1.2.war拷貝到Tomcat//webapps/下面,重啟tomcat,這步是為了使tomcat展開nutch-1.2.war,然后修改webapps/ nutch-1.2/WEB-INF/classes/nutch-site.xml文件如下:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>searcher.dir</name>
<value>c:/cygwin/home/nutch-1.2/crawled</value>
</property>
</configuration>
5.2.為了支持中文的搜索,修改Tomcat/conf/server.xml。找到對應的地方修改成
connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
5.3.在瀏覽器中輸入http://localhost:8080/nutch-1.2/
