官方文檔:nutch+hadoop
版本:
nutch:nutch1.6
solr: solr3.6.2
可以參照hadoop1.0.4+nutch1.6“單機”配置
一,ant編譯nutch
下載apache-nutch-1.6-src.tar.gz,解壓之。
在nutch1.6/conf下
先修改 nutch-default.xml中http.agent.name和http.robots.agents,value值隨意,但是要保持一致
<name>http.agent.name</name> <value>sleeper_qp</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.robots.agents</name> <value>sleeper_qp</value> <description>The agent strings we'll look for in robots.txt files, comma-separated, in decreasing order of precedence. You should put the value of http.agent.name as the first agent name, and keep the default * at the end of the list. E.g.: BlurflDev,Blurfl,* </description> </property>
然后
cp nutch-default.xml nutch-site.xml
在nutch1.6下ant編譯
二,測試nutch
啟動hadoop,新建,上傳urls.txt
~/hadoop-1.0.4$ bin/start-all.sh ~/hadoop-1.0.4$ touch urls.txt 在urls.txt寫入你想爬的網站 ~/hadoop-1.0.4$ bin/hadoop fs -mkdir urls ~/hadoop-1.0.4$ bin/hadoop fs -put urls.txt urls/
添加hadoop的環境變量
修改~/.bashrc:
export HADOOPHOME=/home/hadoop/hadoop
export PATH=$PATH:$HADOOPHOME/bin
說明:直接輸入hadoop的命令可能會有警告,這是因為hadoop自身也配置了自己的路徑(在HADOOP_HOME/bin/hadoop-config.sh)
在nutch/runtime/deploy下輸入
~/nutch1.6/runtime/deploy$ bin/nutch crawl urls -dir crawl -depth 3 -topN 3
解釋
-dir是爬取內容存放的文件 -depth 爬取深度 -topN
完成后可查看hdfs
輸入hadoop fs -ls查看新的crawl文件夾
三,安裝solr
下載解壓solr3.6.2
修改NUTCH_HOME/conf下的schema.xml
<field name="content" type="text" stored="true" indexed="true"/>
拷貝NUTCH_HOME/conf下的schema.xml到solr/example/solr/conf/下
然后solr/example/solr/conf/下的solrconfig.xml中的str name="df"后的text全部改為content PS:因為版本的變更,默認值有text該為了content
在{APACHE_SOLR_HOME}/example下輸入:
java -jar start.jar
四,整合測試
保證正確,重啟hadoop(刪除前面的hdfs中的crawl),重啟solr
在瀏覽器下查看相關信息:
在~/nutch1.6/runtime/deploy下輸入
bin/nutch crawl urls -solr http://localhost:8983/solr -dir crawl -depth 1 -topN 1
在正確運行的情況下,可以在http://localhost:8983/solr/admin/ 輸入你先前爬取網站的相關內容,可以得到一個xml格式的結果