mysql nutch_nutch2.2+mysql部署

安装MySQL( 在此不做陈述,MySQL数据库可能是在windows,可能是在linux下,以下配置以linux为例)

配置MySQL默认值(/etc/mysql/my.cnf [mysqld] )

innodb_file_format=barracuda

innodb_file_per_table=true

innodb_large_prefix=true

character-set-server=utf8mb4

collation-server=utf8mb4_unicode_ci

max_allowed_packet=500M

#创建数据库(可以基于navicat等可视化管理工具)

CREATE DATABASE nutch DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;

#选择数据库

use nutch;

#创建表:

#注意此处的id长度,官方文档貌似也是767,但是我创建的时候出错了。默认编码格式是utf8mb4占四个字节,767/4 大致是190左右;

#如果是ut8则可设置到255,但是在使用ut8的时候,采集发生了错误。可能是字符集范围的关系吧。

CREATE TABLE `webpage` (

`id` varchar(190) NOT NULL,

`headers` blob,

`text` longtext DEFAULT NULL,

`status` int(11) DEFAULT NULL,

`markers` blob,

`parseStatus` blob,

`modifiedTime` bigint(20) DEFAULT NULL,

`prevModifiedTime` bigint(20) DEFAULT NULL,

`score` float DEFAULT NULL,

`typ` varchar(32) CHARACTER SET latin1 DEFAULT NULL,

`batchId` varchar(32) CHARACTER SET latin1 DEFAULT NULL,

`baseUrl` varchar(767) DEFAULT NULL,

`content` longblob,

`title` varchar(2048) DEFAULT NULL,

`reprUrl` varchar(767) DEFAULT NULL,

`fetchInterval` int(11) DEFAULT NULL,

`prevFetchTime` bigint(20) DEFAULT NULL,

`inlinks` mediumblob,

`prevSignature` blob,

`outlinks` mediumblob,

`fetchTime` bigint(20) DEFAULT NULL,

`retriesSinceFetch` int(11) DEFAULT NULL,

`protocolStatus` blob,

`signature` blob,

`metadata` blob,

PRIMARY KEY (`id`)

) ENGINE=InnoDB

ROW_FORMAT=COMPRESSED

DEFAULT CHARSET=utf8mb4;

#nutch2.2部署

1.从官网下载压缩包 如果想导入到eclipse中的话建议下载apache-nutch-2.2-src.tar.gz包(先不要编译)

2.修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件,

将 default”/>

变成default”/>

至于原因,xml文件内有说明。

取消失gora-sql的注释

default” />

取消mysql的注释

default”/>

3.修改${APACHE_NUTCH_HOME}/conf/gora.properties文件

注释掉原来Default SqlStore Properties采用的配置规则;

新增mysql配置项

###############################

# MySQL properties #

###############################

gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver

gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?createDatabaseIfNotExist=true

gora.sqlstore.jdbc.user=xxxxx

gora.sqlstore.jdbc.password=xxxxx

4.修改${APACHE_NUTCH_HOME}/conf/gora-sql-mapping.xml文件

将primarykey 的length属性修改为 190(原本为512) 和建立的数据库内长度对应

5.修改nutch-site.xml 添加必要配置

http.agent.name

YourNutchSpider

http.accept.language

ja-jp, en-us,en-gb,zh-cn,en;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

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: ….

6.使用ant进行编译吧 到此部署结束了,如果你不是第一次使用nutch 那就开始测试吧,nutch2.2仍然支持bin/nutch crawl 命令 2.3就不行啦

(采集页面过大时候,放大http.content.limit属性值,比如京东首页...)

附:测试实例(此处只大致列出命令 不做具体说明了)

cd ${APACHE_NUTCH_HOME}/runtime/local

mkdir -p urls

echo http://nutch.apache.org/ > urls/seed.txt

bin/nutch crawl urls/ -threads 1 -depth 2

好了应该呼呼的跑起来了吧。(注意mysql服务是否开启)

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值