【Nutch】Linux下應用nutch 1.0 Web前端實現單機檢索

來源:互聯網
上載者:User

nutch的爬蟲和搜尋可以說是分離的兩塊,爬蟲可以是M/R作業,但搜尋不是M/R作業。搜尋有兩種方式:一是將爬蟲資料(或者稱索引資料)放在本地硬碟,進行搜尋。二是直接搜尋HDFS中的爬蟲資料。
這裡介紹如何使用nutch-1.0的WEB前端檢索本地爬蟲資料:
(1)Nutch的搜尋可以獨立於hadoop叢集,只要將爬蟲下來的資料copy到任何機器,在此機器上安裝一個tomcat,並運行nutch內建的WEB前端程式並做相應配置,就可實現搜尋。
(2)將使用命令bin/nutch crawl -dir data -depth 3 -topN 5爬蟲下下來的資料data放在本地某目錄下(如果是分布式爬蟲,可以使用命令" bin/hadoop dfs -copyFromLocal data 本地目錄" 將爬蟲資料data複製到本地目錄),例如將產生的data目錄複寫到/home/nutch/nutchinstall/crawltest/目錄下。(安全起見,請確保目錄路徑中沒有空格,這個可能有影響)。
說明:
data目錄是爬蟲產生的目錄,下面有這些子目錄:crawldb,index,indexes,linkdb,segments
(3)安裝tomcat,請確保安裝路徑沒有空格,這很重要,在windows上因為有空格導致搜尋結果始終為0.
(4)將Nutch主目錄下的WEB前端程式nutch-1.0.war複製到 /usr/program/apache-tomcat-6.0.18/webapps/目錄下(apache安裝目錄是/usr/program/apache-tomcat-6.0.18)
(5)瀏覽器中輸入http://localhost:8080/nutch-1.0,將自動解壓nutch-1.0.war。
(6)配置WEB前端程式中的nutch-site.xml檔案,配置完成後必須重啟tomcat(/usr/program/apache-tomcat-6.0.18/bin/shutdown.sh,然後在start.sh)。
nutch-site.xml在目錄/usr/program/apache-tomcat-6.0.18/webapps/nutch-1.0/WEB-INF/classes/下,
配置如下:
<property>
  <name>http.agent.name</name>   不可少,否則無搜尋結果
  <value>nutch-1.0</value>
  <description>HTTP 'User-Agent' request header.</description>
</property>

<property>
  <name>http.robots.agents</name>
  <value>nutch-1.0,*</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>

<property>
  <name>searcher.dir</name>
  <value>/home/nutch/nutchinstall/crawltest/data</value>   定位到爬蟲資料目錄,絕對路徑
  <description>if index in the hdfs ,the value is hdfs relative dir
  if index in the local dir,the value is local dir
  </description>
</property>
(7)重啟tomcat
(8)在http://localhost:8080/nutch-1.0下檢索關鍵字

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.