nutch2.x相对于nutch1.x最大的差别即增加了Gora模块,使存储多样简洁化。因为以前构建过nutch1.2、nutch1.6,因为这此构建会相对容易些,但出忽意料的也废了1天的时间,很是有点小郁闷,现将各关键点总结如下。
1、将nutch2.2.1从官网中下载下来,得到的是源码包,需要自己去ant或是maven。
2、进行ant之前,先确定自己要存储的数据库,是sql型还是nosql型,这里会有相对的不少配置文件的改动,因为其天然的更支持nosql型,所以问题会少些。由于个人原因选择的mysql作为db,其中遇到不少意外情况。
3、以mysql为例,修改gora.properties如下:
首先注释掉默认的
1
2
3
4
5
6
7
8
9
10
|
###############################
#Default MySQL properties #
###############################
gora.datastore.default=org.apache.gora.sql.store.SqlStore
gora.datastore.autocreateschema=true
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=jdbc:
gora.sqlstore.jdbc.user=root
gora.sqlstore.jdbc.password=rootpassword
|
修改nutch-site.xml中的数据如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?
xml
version
=
"1.0"
?>
<?
xml-stylesheet
type
=
"text/xsl"
href
=
"configuration.xsl"
?>
<!-- Put site-specific property overrides in this file. -->
<
configuration
>
<
property
>
<
name
>http.robots.agents</
name
>
<
value
>zel1,zel2</
value
>
<
description
></
description
>
</
property
>
<
property
>
<
name
>http.agent.description</
name
>
<
value
>zel_desc</
value
>
<
description
></
description
>
</
property
>
<
property
>
<
name
>http.accept.language</
name
>
<
value
>ja-jp,en-us,en-gb,en;q=0.7,*;q=0.3</
value
>
<
description
>Value of theAccept-Language request header field.
This
allows selecting non-Englishlanguage as default one to retrieve.
It is
a useful setting for search enginesbuild for certain national
group.
</
description
>
</
property
>
<
property
>
<
name
>storage.data.store.class</
name
>
<
value
>org.apache.gora.sql.store.SqlStore</
value
>
<
description
>TheGora DataStore class for storing and retrieving data.
Currently the following stores areavailable:.
</
description
>
</
property
>
<
property
>
<
name
>parser.character.encoding.default</
name
>
<
value
>utf-8</
value
>
</
property
>
<!-- 为解决utf-8类中的空指针问题 -->
<
property
>
<
name
>generate.batch.id</
name
>
<
value
>*</
value
>
</
property
>
<
property
>
<
name
>http.agent.name</
name
>
<
value
>zel1</
value
>
<
description
></
description
>
</
property
>
</
configuration
>
|
4、修改编译时的ant脚本部分,使编译出来的jar包,符合实际需要。
修改ivy文件夹下的ivy.xml文件,找到gora的jar包相关部分,改成如下:主要原因在于gora0.3是不支持mysql存储的,只能选择0.2.1版本,并将与该版本对应的sql的jar包解掉注释即可,这样会在ant完成后出现gora0.2.1-core和gora-sql-0.1.1-incubating.jar再结合前几步,就可以完成编译后的布署nutch2.2.1爬虫了。
1
2
3
4
5
6
7
8
9
10
11
12
|
<!--================-->
<!-- Gora artifacts -->
<!--================-->
<
dependency
org
=
"org.apache.gora"
name
=
"gora-core"
rev
=
"0.2.1"
conf="*->default"/>
<!-- Uncomment this to use SQL as Gora backend. It should be noted that the
gora-sql 0.1.1-incubating artifact is NOT compatable with gora-core 0.3. Users should
downgrade to gora-core 0.2.1 in order to use SQL as a backend. -->
<
dependency
org
=
"org.apache.gora"
name
=
"gora-sql"
rev
=
"0.1.1-incubating"
conf="*->default" />
<!-- Uncomment this to use MySQL as database with SQL as Gora store. -->
<
dependency
org
=
"mysql"
name
=
"mysql-connector-java"
rev
=
"5.1.18"
conf="*->default"/>
|
前边的四步是完成自编译以及完成的项目布署,往往还需要二次开发才可以。这时要导入myeclipse8.5,步骤如下:
1、导入步骤往上有很多,大多是可行的,即在下载源码-->在myeclipse中新建项目--》选择已存在项目--》选择nutch2.2.1源码--》在order and export中设置conf选中并top到顶端,即可完成导入。
2、此时会有n多的错误,看到相应的错误导入所需的包即可,其包即是在自行ant编译时的build文件的local中找到,还有因为找不到的一些jar包的小叉号的源码部分多为plugin部分,此时即可支掉该部分源码即可,保证先跑通项目,个别的plugin可以日后再追加即可。估计这个过程会有n多人遇n种不同的情况,可以留言交流。
如果你是在cygwin的windows的环境下模拟linux,还会遇到最为典型的第3个问题如下:
3、我是在cgywin的win7环境下搭建的,所以要将hadoop1.2.0的源码导入并修改即注释其FileUtil.java源码的那个权限验证方法即可。或是将改完的hadoop1.2.0的源码导成jar包加入到nutch2.2.1中亦可。
下班时间有点紧张,写的微微有点快了,不清楚之处欢迎交流,