nutch 2.2.1 mysql_Windows7环境下MyEclipse+Nutch2.2.1+Mysql搭建

问题导读

1.Windows7环境下MyEclipse+Nutch2.2.1+Mysql搭建包含哪些步骤?

2.如何从eclipse中下载nutch?

3.如何解决eclipse编码问题?

thread-12534-1-1.html

一、环境准备

首先肯定是配置开发环境,这里暂时不作详细描述。

二、从svn检出项目

6cbb977928e529ff6f0e46249f365cb1.gif

1.png (38.36 KB, 下载次数: 5)

2015-4-14 01:09 上传

6cbb977928e529ff6f0e46249f365cb1.gif

2.png (51.98 KB, 下载次数: 5)

2015-4-14 01:09 上传

6cbb977928e529ff6f0e46249f365cb1.gif

3.png (33.42 KB, 下载次数: 5)

2015-4-14 01:10 上传

6cbb977928e529ff6f0e46249f365cb1.gif

4.png (42.33 KB, 下载次数: 5)

2015-4-14 01:10 上传

Finish完成导入。

三、  修改ivy目录

修改ivy目录下的ivysetting.xml地址http://mirrors.ibiblio.org/maven2/(只有这个地址访问是正常的,其余的地址我尝试访问不了)

6cbb977928e529ff6f0e46249f365cb1.gif

5.png (18.81 KB, 下载次数: 5)

2015-4-14 01:10 上传

四、  修改ivy目录下的ivy.xml(增加mysql访问依赖java包)

修改gora-core版本为0.2.1,并解除注释gora-sql和mysql-connector-java

6cbb977928e529ff6f0e46249f365cb1.gif

6.png (24.35 KB, 下载次数: 5)

2015-4-14 01:10 上传

五、  Cd 到目录执行Ant eclipse(直接在Eclipse下ant build貌似有问题)

6cbb977928e529ff6f0e46249f365cb1.gif

7.png (37.66 KB, 下载次数: 5)

2015-4-14 01:10 上传

六、  回到Eclipse工程,刷新项目,会发现目录结构已经发生变化

6cbb977928e529ff6f0e46249f365cb1.gif

8.png (23.24 KB, 下载次数: 5)

2015-4-14 01:10 上传

七、编码问题

看到还有一个错误,是编码的问题,工程右键Properties -> Resource ->utf-8

6cbb977928e529ff6f0e46249f365cb1.gif

9.png (53.39 KB, 下载次数: 5)

2015-4-14 01:10 上传

八、  选中Conf

工程右键Build Path->Config Build Path->Order and Export下选中Conf 文件夹置顶

6cbb977928e529ff6f0e46249f365cb1.gif

10.png (78.93 KB, 下载次数: 4)

2015-4-14 01:12 上传

九、  修改Conf文件夹下gora.properties配置mysql

#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:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull

gora.sqlstore.jdbc.user=root

gora.sqlstore.jdbc.password=123456复制代码

十、工程目录下新建文件夹urls

工程目录下新建文件夹urls,urls目录下新建一个文件url,里面输入要爬取的root_url,比如http://www.qq.com

十一、配置conf目录下nutch-site.xml

http.agent.name

YourNutchSpider

http.accept.language

ja-jp, en-us,en-gb,en,zh-cn,zh-tw;q=0.7,*;q=0.3

Value of the “Accept-Language” request header field.

This allows selecting non-English language as default one to retrieve.

It is a useful setting for search engines build for certain national group.

parser.character.encoding.default

utf-8

The character encoding to fall back to when no other information

is available

plugin.folders

src/plugin

Directories where nutch plugins are located. Each

element may be a relative or absolute path. If absolute, it is used

as is. If relative, it is searched for on the classpath.

 
 

        generate.batch.id

        *

storage.data.store.class

org.apache.gora.sql.store.SqlStore

The Gora DataStore class for storing and retrieving data.

Currently the following stores are available: ….

复制代码

十二、运行Run Configuration

配置完上述步骤后配置命令运行Run Configuration选择org.apache.nutch.crawl.Crawler,参数设置urls -depth 3 -topN 5和-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log

6cbb977928e529ff6f0e46249f365cb1.gif

11.png (77.94 KB, 下载次数: 5)

2015-4-14 01:12 上传

这时运行会遇到错误Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-Administrator\mapred\staging\Administrator606301699\.staging to 0700

6cbb977928e529ff6f0e46249f365cb1.gif

12.png (42.64 KB, 下载次数: 5)

2015-4-14 01:13 上传

十三、修改CheckReturnValue方法

上述错误一般只是windows下才会遇到的,所以我们一般的做法是找到Hadoop-core-1.2.0源码中的org.apache.hadoop.fs下的FileUtil.java修改其中的CheckReturnValue方法,注释掉其中的内容

private static void checkReturnValue(boolean rv, File p,

FsPermission permission

) throws IOException {

//    if (!rv) {

//      throw new IOException("Failed to set permissions of path: " + p +

//                            " to " +

//                            String.format("%04o", permission.toShort()));

//    }

}复制代码

然后编译成java包替换我们工程build/lib下的hadoop-core-1.2.0.jar。

另外一种方法是找到FileUtil.java编译过后的class文件,替换掉jar包中相应的class文件FileUtil.clas和FileUtil$CygPathCommand.clas(用压缩软件打开就行)

十四、接下来再运行就没有问题

6cbb977928e529ff6f0e46249f365cb1.gif

13.png (32.67 KB, 下载次数: 5)

2015-4-14 01:13 上传

6cbb977928e529ff6f0e46249f365cb1.gif

14.png (105.7 KB, 下载次数: 8)

2015-4-14 01:13 上传

这里注意,你会发现mysql数据库中很多记录除了id,status这几个基本字段有数据外其他值都是null,这是正常情况,请注意status字段,

status    记录抓取状态

1     unfetched (links not yet fetched due to limits set in regex-urlfilter.txt, -TopN crawl parameters, etc.)

2     fetched (page was successfully fetched)

3     gone (that page no longer exists)

4     redir_temp (temporary redirection — see reprUrl below for more details)

5     redir_perm (permanent redirection — see reprUrl below for more details)

34     retry

38     not modified

这是因为我们的topN设置太小,所以很多url被限制抓取了(当然还有可能是url被regex-urllfilter过滤了),自己注意一下就好了。

Good Job,到此我们就完成了整个流程的配置和运行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值