nutch与起点R3集成之笔记(二)

         nutch与起点R3集成之笔记(一)中介绍了在起点R3中添加nutch要用到的索引字段,上述字段建好后,就可以通过nutch抓取一个或多个网站内容,并通过 bin/nutch solrindex 送到起点R3索引库中。

       三、nutch安装与配置

       1.安装nutch

       先从http://www.apache.org/dist//nutch/apache-nutch-1.3-bin.zip下载nutch1.3,展开。nutch可以在linux环境下运行,也可以在windows环境下运行,也可以导入到eclipse中运行。

       在linux环境下安装最简单,将展开后runtime/local目录下的内容上传到linux的一个目录下,如/opt/nutch1.3,同时将 /opt/nutch1.3/lib下的nutch-1.3.jar copy到  /opt/nutch1.3目录,并改名为 nutch-1.3.job,并chmod +x /opt/nutch1.3/bin。同时要有JDK环境,并在profile中设置JAVA_HOME,PATH中有JDK的bin路径。在 /opt/nutch1.3目录键入 bin/nutch ,出现如下提示:

 

[root@test nutch-1.3]# bin/nutch
Usage: nutch [-core] COMMAND
where COMMAND is one of:
  crawl             one-step crawler for intranets
  readdb            read / dump crawl db
  convdb            convert crawl db from pre-0.9 format
  mergedb           merge crawldb-s, with optional filtering
  readlinkdb        read / dump link db
  inject            inject new urls into the database
  generate          generate new segments to fetch from crawl db
  freegen           generate new segments to fetch from text files
  fetch             fetch a segment's pages
  parse             parse a segment's pages
  readseg           read / dump segment data
  mergesegs         merge several segments, with optional filtering and slicing
  updatedb          update crawl db from segments after fetching
  invertlinks       create a linkdb from parsed segments
  mergelinkdb       merge linkdb-s, with optional filtering
  index             run the indexer on parsed segments and linkdb
  solrindex         run the solr indexer on parsed segments and linkdb
  merge             merge several segment indexes
  dedup             remove duplicates from a set of segment indexes
  solrdedup         remove duplicates from solr
  plugin            load a plugin and run one of its classes main()
  server            run a search server
 or
  CLASSNAME         run the class named CLASSNAME
Most commands print help when invoked w/o parameters.

       表示安装成功。如果要安装成hadoop模式,还需要从网上将hadoop一些运行脚本拷贝到bin目录下。

        在windows环境下,必须安装linux运行模拟环境软件cygwin,从http://www.cygwin.org/cygwin/下载安装cygwin。在cygwin下运行nutch跟linux需要的配置时一样的,需要设置 java_home,path等等。

        在enlipse环境下,如何导入nutch1.3,网上有很多介绍,但很多是错的。其中一个重要的步骤是在构建路径时要将conf放在路径顺序中最前面,如下图:

并建立好主类为org.apache.nutch.crawl.Crawl的java运行应用程序,如下图:

 

对应的自变量设置为:

     2.配置nutch-site.xml

      无论是在linux下,在cygwin下,还是在eclipse环境里,首先需要修改conf中nutch-site.xml文件,在nutch-site.xml中加入:

 <property>
  <name>http.agent.name</name>
  <value>nutch-1.3</value>
 </property>

<property>
  <name>http.robots.agents</name>
  <value>nutch-1.3,*</value>
</property>


<property>
  <name>plugin.includes</name>
  <value>protocol-http|urlfilter-regex|parse-(html|tika|js|zip|swf|rss)|index-(basic|anchor|more)|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
</property>

      同时在在eclipse环境下,还需要在nutch-site.conf文件里加入:

 

<property>
  <name>plugin.folders</name>
  <value>./src/plugin</value>
  <description>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.</description>
</property>

   3.配置solrindex-mapping.xml

    同时,修改nutch1.3confsolrindex-mapping.xml文件,把nutch的索引字段与起点R3的定义的索引字段进行映射。内容如下:

 

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<mapping>
	<!-- Simple mapping of fields created by Nutch IndexingFilters
	     to fields defined (and expected) in Solr schema.xml.

             Any fields in NutchDocument that match a name defined
             in field/@source will be renamed to the corresponding
             field/@dest.
             Additionally, if a field name (before mapping) matches
             a copyField/@source then its values will be copied to 
             the corresponding copyField/@dest.

             uniqueKey has the same meaning as in Solr schema.xml
             and defaults to "id" if not defined.
         -->
	<fields>
		<field dest="title" source="title"/>
		<field dest="text" source="content"/>
		<field dest="lastModified" source="lastModified"/>	
		<field dest="type" source="type"/>	
		<field dest="site" source="site"/>
		<field dest="anchor" source="anchor"/>
		<field dest="host" source="host"/>		
		<field dest="segment" source="segment"/>
		<field dest="boost" source="boost"/>
		<field dest="tstamp" source="tstamp"/>
		<field dest="url" source="url"/>
		<field dest="id" source="digest"/>
		<copyField source="digest" dest="digest"/>
	</fields>
	<uniqueKey>id</uniqueKey>
</mapping>

     4.配置 regex-urlfilter.xml

      修改url过滤器,保证你要采集的网站,能不会被url过滤器给过滤掉,如要抓取新浪网站内容 ,所以在nutch的conf的regex-urlfilter.xml里加入一条:

+^http://www.sina

 regex-urlfilter.xml内容如下:

 

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# The default url filter.
# Better for whole-internet crawling.

# Each non-comment, non-blank line contains a regular expression
# prefixed by '+' or '-'.  The first matching pattern in the file
# determines whether a URL is included or ignored.  If no pattern
# matches, the URL is ignored.

# skip file: ftp: and mailto: urls
-^(file|ftp|mailto):

# skip image and other suffixes we can't yet parse
#-\.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$
-\.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|mpg|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$

# skip URLs containing certain characters as probable queries, etc.
#-[?*!@=]

# skip URLs with slash-delimited segment that repeats 3+ times, to break loops
-.*(/[^/]+)/[^/]+\1/[^/]+\1/

# accept anything else
+^http://www.sina.
-.

        5.在nutch1.3目录下建一个 url目录(url目录与conf是统计目录),然后在url目录里建一个url.txt文件,url.txt文件内容为http://www.sina.com.cn 。

       

 

 

 


转自:http://my.oschina.net/sprint/blog/28717
2019-03-27 01:21

知识点

相关教程

更多

nutch与起点R3集成之笔记(一)

百度、google帮我们找Internet的信息,但对于一个行业内部网(intranet)来说,百度、google就无法帮忙了。并且,对一个行业来说,更多的信息都是放在行业内部网上,并且采用网页、office文档、图片、视频、音频等格式存放。如何方便,快捷,安全地获取行业内部的信息内容,建立一个行业内部网的搜索引擎就显得尤为重要。  佛山起点软件(http://www.rivues.com)推出了

nutch与起点R3集成之笔记(四)

通过“nutch与起点R3集成之笔记(一、二、三)”中的步骤,我们可以建立起一个行业内部网的搜索引擎,但搜索引擎一个最重要的功能,就是必须能搜索到网络中最新的内容。这就要求nutch能及时采集到网络中的最新网页信息,同时将这些新采集到的信息更新到solr索引库中。故本篇介绍如何实现索引的更新和去重问题。  我们随时可以使用nutch的crawl命令来爬行网站,例如,今天上午8:00采集一次新浪网站

nutch与起点R3集成之笔记(三)

四、抓取网页,建立solr索引 在抓取网页前,要保证起点R3处在运行状态。即 在浏览器中键入 http://127.0.0.1:880/后,会出现如下窗口:  在linux或cygwin中运行nutch抓取网页命令为 :bin/nutch crawl url -solr http://127.0.0.1:880 -dir test -depth 3 -topN ,其dir、depth、topN参数

荐 《Nutch笔记》Nutch-1.7+solr-4.7集成

一、下载安装nutch   下载地址  http://apache.fayea.com/apache-mirror/nutch/1.7/apache-nutch-1.7-bin.tar.gz  安装  [root@centos data]# cd /data/[root@centos data]# mkdir nutch[root@centos data]# tar -zxvf apache-nu

Nutch1.3集成Solr3.4网页快照功能实现(二)

FileInputFormat.addInputPath(job, new Path(segment, ParseText.DIR_NAME));中仅处理了Segment文件夹下“parse_data”与“parse_text”中的内容,对于原始的网页快照文件夹(“content”)并没有进行处理,Segment文件夹结构如下所示:

请问起点R3能否做到完全支持MultiCore?

在RivuSchema类中实现了从数据库获取数据类型和索引结构表中的数据构建Schema.xml,但这仿佛只能构建solr.xml中指定的core=search,想请教的是如何能做到完全支持MultiCore功能的实现,即自定义构建多个Core。 转自:http://my.oschina.net/u/134152/blog/17021

Nutch1.3集成Solr网页快照功能实现(一)

Nutch1.3版本以后使用了Solr作为索引功能的提供者,在索引效率、集群功能方面做了很大改进,但与Nutch1.2版本相比,Solr缺失了网页快照的功能,按官方手册中集成配置后,每次查询返回的结果中仅包含解析处理过的HTML正文部分,如下图所示:

nutch1.3与solr3.4集成部署在eclipse上之——运行的输出日志

nutch1.3与solr3.4集成部署在eclipse上成功 在eclipse上运行参数是: crawl urls -solr http://localhost:8080/l-nutch-solr -depth 3 -topN 10 运行时输出日志: crawl started in: crawl-20111107123624rootUrlDir = urlsthreads = 10depth

Nutch1.3集成Solr3.4网页快照功能实现(三)

修改Reduce方法,如下: 至此,代码部分修改完成,接下来需要修改配置文件  本文出自 “果壳中的宇宙” 博客,转载请与作者联系! 转自:http://williamx.blog.51cto.com/3629295/722719

Nutch1.3集成Solr3.4网页快照功能实现(四)

在工程中找到“solrindex-mapping.xml”修改如下: 在Solr应用中修改“schema.xml”添加对应的Field,如下: 重启服务,大功告成,solr查询返回结果如下所示:                                                                                        本文出自 “果壳中的宇宙” 博

起点R3企业级搜索引擎发布5.1版本,支持实时搜索

R3是一个强大的,高性能的JAVA企业级搜索引擎产品,R3构建于Solr和Lucene之上,集成了POI、PDFBox和Apache Tika等第三方开源项目,在R3企业级搜索平台上,你可以搜索出你企业所有相关的内容包括网站、邮箱、ECM, CRM。 更新内容: 1、支持实时搜索,集成了Zoie 2、修改Solr的版本为1.4.2 3、升级到Tomcat7 4、增加hazelcast.xml,使得

Apache SOLR and Carrot2集成

1.环境   下载软件      2.启动Solr   使用Jetty启动solr      访问http://localhost:8983/solr/#/    3.导入数据   使用solr-docs中post.jar向solr中导入数据        4.聚类集成到Solr中     carrot2提供的solrconfig.xml中的对搜索结果进行了配置          配置  conf

Apache Nutch 1.3 学习笔记二

1. Nutch 1.3 运行命令的一些介绍   要看Nutch的命令说明,可执行如下命令bin/nutch          Usage:nutch[-core]COMMAND           whereCOMMANDisoneof:           crawlone-stepcrawlerforintranets           readdbread/dumpcrawldb

nutch学习笔记(二)入门篇

上一篇博客中叙述了如何利用nutch爬取网页的过程。本篇则讲述建立逆向索引以及与solr结合展示结果的方法。 1. 建立逆向索引   所谓的逆向索引,其实就是从词(字符串)到文本的映射。一般而言,在爬取网页后,我们会自然而然的会得到一种索引——从文本到词的映射,即查询条件为文本,查询结果为该文本中包含哪些词(字符串)。但是在实际应用中,这种索引的价值不高,因为让用户记住一个文本的链接或者标题什么的

集成Nutch和Solr

两年前集成Nutch 和Solr 这两个Apache Lucene 项目组下的子项目实在是件困难的事情,需要打很多补丁(patches),为他们的联姻搜寻各种必需的组件(required components)。今非昔比,时下,在Solr4.0 也即将浮出水面的时候,两者的结合变的相对容易。 今年早些时候发布的Nutch 1.0包含了"开盒即用"的原装的(out of the

最新教程

更多

java线程状态详解(6种)

java线程类为:java.lang.Thread,其实现java.lang.Runnable接口。 线程在运行过程中有6种状态,分别如下: NEW:初始状态,线程被构建,但是还没有调用start()方法 RUNNABLE:运行状态,Java线程将操作系统中的就绪和运行两种状态统称为“运行状态” BLOCK:阻塞状态,表示线程阻塞

redis从库只读设置-redis集群管理

默认情况下redis数据库充当slave角色时是只读的不能进行写操作,如果写入,会提示以下错误:READONLY You can't write against a read only slave.  127.0.0.1:6382> set k3 111  (error) READONLY You can't write against a read only slave. 如果你要开启从库

Netty环境配置

netty是一个java事件驱动的网络通信框架,也就是一个jar包,只要在项目里引用即可。

Netty基于流的传输处理

​在TCP/IP的基于流的传输中,接收的数据被存储到套接字接收缓冲器中。不幸的是,基于流的传输的缓冲器不是分组的队列,而是字节的队列。 这意味着,即使将两个消息作为两个独立的数据包发送,操作系统也不会将它们视为两个消息,而只是一组字节(有点悲剧)。 因此,不能保证读的是您在远程定入的行数据

Netty入门实例-使用POJO代替ByteBuf

使用TIME协议的客户端和服务器示例,让它们使用POJO来代替原来的ByteBuf。

Netty入门实例-时间服务器

Netty中服务器和客户端之间最大的和唯一的区别是使用了不同的Bootstrap和Channel实现

Netty入门实例-编写服务器端程序

channelRead()处理程序方法实现如下

Netty开发环境配置

最新版本的Netty 4.x和JDK 1.6及更高版本

电商平台数据库设计

电商平台数据库表设计:商品分类表、商品信息表、品牌表、商品属性表、商品属性扩展表、规格表、规格扩展表

HttpClient 上传文件

我们使用MultipartEntityBuilder创建一个HttpEntity。 当创建构建器时,添加一个二进制体 - 包含将要上传的文件以及一个文本正文。 接下来,使用RequestBuilder创建一个HTTP请求,并分配先前创建的HttpEntity。

MongoDB常用命令

查看当前使用的数据库    > db    test  切换数据库   > use foobar    switched to db foobar  插入文档    > post={"title":"领悟书生","content":"这是一个分享教程的网站","date":new

快速了解MongoDB【基本概念与体系结构】

什么是MongoDB MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era. MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。

windows系统安装MongoDB

安装 下载MongoDB的安装包:mongodb-win32-x86_64-2008plus-ssl-3.2.10-signed.msi,按照提示步骤安装即可。 安装完成后,软件会安装在C:\Program Files\MongoDB 目录中 我们要启动的服务程序就是C:\Program Files\MongoDB\Server\3.2\bin目录下的mongod.exe,为了方便我们每次启动,我

Spring boot整合MyBatis-Plus 之二:增删改查

基于上一篇springboot整合MyBatis-Plus之后,实现简单的增删改查 创建实体类 添加表注解TableName和主键注解TableId import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baom

分布式ID生成器【snowflake雪花算法】

基于snowflake雪花算法分布式ID生成器 snowflake雪花算法分布式ID生成器几大特点: 41bit的时间戳可以支持该算法使用到2082年 10bit的工作机器id可以支持1024台机器 序列号支持1毫秒产生4096个自增序列id 整体上按照时间自增排序 整个分布式系统内不会产生ID碰撞 每秒能够产生26万ID左右 Twitter的 Snowflake分布式ID生成器的JAVA实现方案