该部分是基于安装完hadoop+hbase的基础之上的,如果还未安装,请参照:hadoop+hbase 伪分布式安装与配置(for linux)
1. 下载安装
去官网http://www.fayea.com/apache-mirror/nutch/下载一个版本的源码吧,我下载的是 apache-nutch-2.1-src.tar.gz,然后解压到一个特定目录。
2. 配置
进入根目录,你会发现如下两个文件夹:ivy/和conf/下面的配置主要针对这两个路径下面的文件进行进行。
最简单、最基本的配置过程你可以参考官网的说明:here
下面我讲的配置将在学习nutch使用的过程中逐步完善:
2.1 ivy文件的配置
在ivy/路径下仅需要配置ivy.xml一个文件,该文件的作用是用来管理依赖项的库,在这里要确定打开gora-hbase项,只有这样,在ant编译的过程中才会下载对应的hbase依赖所需的库文件。
2.2 conf文件的配置
此部分是重点,进入conf/文件,你会发现有很多配置文件。而且你会发现,当ant编译该工程之后,conf/下的所有文件都会被原样拷贝到runtime/local/conf/下面,所以,ant一次之后,如果需要修改conf/里的文件,可直接到runtime/local/conf/里面对应文件进行修改,当然也无需再重新ant编译。
这些插件的配置文件在加载插件的时候由插件自行加载,而配置文件的加载顺序决定了配置文件的优先级,先加载的配置文件优先级低,后加载的配置文件优先级高,优先级低的配置会被优先级高的配置覆盖。因此,了解Nutch配置文件加载的顺序对学习使用Nutch是非常必要的。例如在addNutchResources(conf)方法中可以发现先加载nutch-default.xml文件,后加载nutch-site.xml文件。所以nutch-site.xml中的配置会覆盖nutch-default.xml中的配置。这部分介绍你可以参考这里。
2.2.1 gora.properties 文件
设置HBaseStore为默认存储。
- /** Ensure that HBaseStroe is set as the default datastore in gora.properties. */
- gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
2.2.2 nutch-site.xml 文件
指定默认存储数据类
- <property>
- <name>storage.data.store.class</name>
- <value>org.apache.gora.hbase.store.HBaseStore</value>
- <description>Default class for storing data</description>
- </property>
设定http.agent.name,如果此部分不设定,则在运行nutch crawl时会抛出Fetcher: No agents listed in 'http.agent.name' property异常:
- <property>
- <name>http.agent.name</name>
- <value>HD nutch agent</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>
3. 测试
3.1 ant编译
以上工作都完成后,进入根目录ant编译,没有安装ant,请参考:ant安装(for linux)
耐心等待编译完成(该过程可能有点长,需要从网上下载一些资源,我的大约等待了10分钟),你会发现生成一个runtime/文件,里面是编译之后生成的结果。
3.2 测试
现在你可以里用如下命令进行测试了:
浙公网安备 33010602011771号