nutch 初体验

来源:互联网 发布:舞台灯光编程 编辑:程序博客网 时间:2024/06/05 05:00

因为nutch中就有Hadoop,所以在其中配置Hadoop和原本的Hadoop配置几乎相同。

唯一不同的就是要配置

1.所有节点的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>nutch-1.0</value>

  <description>爬虫和搜索此参数必须配置</description>

</property>

</configuration>
 

2.配置所有节点上的conf/crawl-urlfilter.txt文件

# skip file:, ftp:, & mailto: urls

-^(file|ftp|mailto):

# skip image and other suffixes we can't yet parse

-/.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$

# skip URLs containing certain characters as probable queries, etc.

-[?*!@=]

# skip URLs with slash-delimited segment that repeats 3+ times, to break loops

-.*(/[^/]+)/[^/]+/1/[^/]+/1/

# accept hosts in MY.DOMAIN.NAME

# 允许下载所有

+^

# skip everything else

-.

 

然后

bin/hadoop dfs -put crawltest/urls urls(crawltest/urls 是自己定义的种子)

bin/nutch crawl urls -dir data -depth 3 -topN 10 (爬虫将全部数据爬到data中)

 

爬完之后

bin/hadoop  fs –get data data(竟然还要下载到本地!!!!!)

 

安装tomcat

 

将Nutch主目录下的WEB前端程序nutch-1.0.war复制到 ***/ tomcat/webapps/目录下。

 

浏览器中输入http://localhost:8080/nutch-1.0,将自动解压nutch-1.0.war,在webapps下生成nutch-1.0目录。

 

配置WEB前端程序中的nutch-site.xml文件,该文件所在目录是***/tomcat/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>searcher.dir</name>

  <value>D:/data< alue>  data是爬虫生成的索引数据目录。参数值请使用绝对路径

  <description>Path to root of crawl.</description>

</property>
 

(6)重启tomcat。更改配置文件后必须重启tomcat,否则不会生效。

(7)在http://localhost:8080/nutch-1.0下检索关键字。

 

 

貌似有分布式检索的方法,下一步再研究

 

原创粉丝点击