nutch采集部署

nutch的限制:
不能采集js动态加载页面内容和分页,对非动态js加载的分页,需要根据分页的情况,来进行设置爬取深度(分页与爬取深度存在关系)。这就限制了nutch全爬取存在很大的局限性,nutch本身要遵守robot协议,如果网址本身不允许被爬取,那么将不会被爬取。

nutch2.2.1部署

环境要求:
系统:Centos7.5
运行环境:java1.8
数据库:mysql5.7
编译环境:ant

下载nutch版本

http://archive.apache.org/dist/nutch/2.2.1/
nutch采集部署_第1张图片

编译nutch

修改${APACHE_NUTCH_HOME}/ivy/ivy.xml文件,将
default”/>
变成
default”/>
取消失gora-sql的注释
default” />
 取消mysql的注释
default”/>

创建数据库

#创建数据库(可以基于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;

修改${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

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

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

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




generate.batch.id

*



http.agent.name
spider
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.





http.robots.agents
spider,*
The agent strings we'll look for in robots.txt files,
  comma-separated, in decreasing order of precedence. You should
  put the value of http.agent.name as the first agent name, and keep the
  default * at the end of the list. E.g.: BlurflDev,Blurfl,*


存在的bug处理方式

进入nutch目录
ant

存在的bug处理方式

当爬取网上文档的时候:,不应该使用protocol-file,因为它是用于爬取本地文件的。如果你想爬取http、https,应当把plugin.includes 修改为httpclient。 

nutch采集部署_第2张图片

你可能感兴趣的:(爬取)