分享

关于nutch的抓取策略问题

ximenchuixuesun 发表于 2015-9-8 10:51:03 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 5 11939
nutch的抓取调度策略是怎样的?是根据nutch-default.xml中的fecthInternal进行自动调度,还是需要用cron进行调度呢?请大牛们指导,谢谢!

已有(5)人评论

跳转到指定楼层
Alkaloid0515 发表于 2015-9-8 11:52:02
本帖最后由 Alkaloid0515 于 2015-9-8 11:55 编辑

fecthInternal这个是哪个参数,没有见过,楼主可否说下它的含义。或则说属于哪个参数。
下面是一些参数的含义:
nutch-default.xml


1.1   http.max.delays
  
<property>
  
   <name>http.max.delays</name>
  
   <value>100</value>
  
   <description>The number of times a thread will delay when trying  to
  
   fetch a page.  Each time it  finds that a host is busy, it will wait
  
   fetcher.server.delay.  After  http.max.delays attepts, it will give
  
   up on the page for now.</description>
  
</property>
  

爬虫的网络延时线程等待时间,以秒计时 , 默认的配时间是3秒,视网络状况而定。如果在爬虫运行的时候发现服务器返回了主机忙消息,则等待时间由fetcher.server.delay 决定,所以在网络状况不太好的情况下fetcher.server.delay 也设置稍大一点的值较好,此外还有一个http.timeout 也和网络状况有关系。
1.2   http.content.limit
  
<property>
  
   <name>http.content.limit</name>
  
   <value>65536</value>
  
   <description>The length limit for downloaded content, in bytes.
  
   If this value is nonnegative (>=0), content longer than it will be  truncated;
  
   otherwise, no truncation at all.
  
   </description>
  
</property>
  

描述爬虫抓取的文档内容长度的配置项。原来的值是 65536 , 也就是说抓取到的一个文档截取 65KB左右,超过部分将被忽略,对于抓取特定内容的搜索引擎需要修改此项,比如XML文档。
1.3   db.default.fetch.interval
  
<property>
  
   <name>db.default.fetch.interval</name>
  
   <value>30</value>
  
   <description>The default number of days between re-fetches of a  page.
  
   </description>
  
</property>
  

这个功能对定期自动爬取需求的开发有用,设置多少天重新爬一个页面。
1.4   fetcher.server.delay
  
<property>
  
   <name>fetcher.server.delay</name>
  
   <value>5.0</value>
  
   <description>The number of seconds the fetcher will delay  between
  
    successive requests to the same server.</description>
  
</property>
  
1.5   fetcher.threads.fetch
  
<property>
  
   <name>fetcher.threads.fetch</name>
  
   <value>10</value>
  
   <description>The number of FetcherThreads the fetcher should  use.
  
     This is also determines the maximum number of requests that are
  
     made at once (each FetcherThread handles one connection).</description>
  
</property>
  
最大抓取线程数量
1.6   fetcher.threads.per.host
  
<property>
  
   <name>fetcher.threads.per.host</name>
  
   <value>1</value>
  
   <description>This number is the maximum number of threads that
  
     should be allowed to access a host at one time.</description>
  
</property>
  
同一时刻同一网站最大抓取线程数量
1.7   fetcher.verbose
  
<property>
  
   <name>fetcher.verbose</name>
  
   <value>false</value>
  
   <description>If true, fetcher will log more  verbosely.</description>
  
</property>
  

如果是 true, 打印出更多详细信息
1.8   parser.threads.parse
0.9版本nutch-default.xml无此参数
  
<property>
    <name>parser.threads.parse</name>
    <value>10</value>
    <description>Number of ParserThreads ParseSegment should  use.</description>
  </property>
  
  

解析爬取到的文档线程数, 和爬虫线程对应,因为爬虫主要的处理类是有很多地方使用到了同步,所以此配置项和爬虫线程保持一直对处理有好处。
1.9   fs.default.name
0.9版本nutch-default.xml无此参数
  
<property>
    <name>fs.default.name</name>
    <value>local</value>
    <description>The name of the default file system.  Either  the
    literal string "local" or a host:port for  NDFS.</description>
  </property>
  

分布式文件系统使用的配置项,默认的是 local 表示 使用本地文件系统,如果使用 host:port 的形式表示使用分布式文件系统NDFS,此处的文件系统地址是 nameserver ,也就是通过 bin/nutch namenode xxxx启动的 主机地址和端口号。
1.10     ndfs.name.dir
0.9版本nutch-default.xml无此参数
  
<property>
    <name>ndfs.name.dir</name>
    <value>/tmp/nutch/ndfs/name</value>
    <description>Determines where on the local filesystem the NDFS  name node
        should store the name  table.</description>
  </property>
  
  

分布式文件系统namenode使用的存放数据的目录 ,Namenode 会使用此项,另外在启动 namenode 或datanode的时候也可以加上路径作为参数也可以生效。
1.11     ndfs.data.dir
0.9版本nutch-default.xml无此参数

  
<property>
    <name>ndfs.data.dir</name>
    <value>/tmp/nutch/ndfs/data</value>
    <description>Determines where on the local filesystem an NDFS  data node
        should store its blocks.</description>
  </property>
  

分布式文件系统ndatanode使用的存放数据的目录 ,datanode 会使用此项,另外在启动 datanode的时候也可以加上 路径作为参数也可以生效。
1.12     indexer.max.tokens
  
<property>
  
   <name>indexer.max.tokens</name>
  
   <value>10000</value>
  
   <description>
  
   The maximum number of tokens that will be indexed for a single field
  
   in a document. This limits the amount of memory required for
  
   indexing, so that collections with very large files will not crash
  
   the indexing process by running out of memory.
  
  
   Note that this effectively truncates large documents, excluding
  
   from the index tokens that occur further in the document. If you
  
   know your source documents are large, be sure to set this value
  
   high enough to accomodate the expected size. If you set it to
  
   Integer.MAX_VALUE, then the only limit is your memory, but you
  
   should anticipate an OutOfMemoryError.
  
   </description>
  
</property>
  

这个配置项的功能是限制索引的时候每个文档的单个字段最大10000个Tokens,也就是说在采用默认的一元分词的 情况下,最大的文档字数限制是10000,如果采用其他中文非一元分词系统,则索引的单个文档单个字段将会超过10000个,对内存有影响。
1.13     indexer.mergeFactor
  
<property>
  
   <name>indexer.mergeFactor</name>
  
   <value>50</value>
  
   <description>The factor that determines the frequency of Lucene  segment
  
   merges. This must not be less than 2, higher values increase indexing
  
   speed but lead to increased RAM usage, and increase the number of
  
   open file handles (which may lead to "Too many open files"  errors).
  
   NOTE: the "segments" here have nothing to do with Nutch  segments, they
  
   are a low-level data unit used by Lucene.
  
   </description>
  
</property>
  

合并因子,在建立索引的时候用到,表示索引多少个文档的时候回写到存储设备。
1.14     indexer.minMergeDocs
  
<property>
  
   <name>indexer.minMergeDocs</name>
  
   <value>50</value>
  
   <description>This number determines the minimum number of Lucene
  
   Documents buffered in memory between Lucene segment merges. Larger
  
   values increase indexing speed and increase RAM usage.
  
   </description>
  
</property>
  

这 个配置项对内存影响巨大,功能是在建立索引的时候最小的合并文档数量,这个值设置太小一个会影响索引速度,另外一个在需要索引的文档数量很大的时候会出现 Too Many Open files 的错误,这个时候需要调整此配置项,有试验表明1000的时候会有比较快的索引速度,但我把此项值调整到10000 , 索引的时候最高内存占用到1.8G,索引创建速度是25page/sec , 并且多次索引的时候有一个衰减。不过对查询的相应时间有很大提升,如果内存足够的话修改较大的值比较好。
1.15     indexer.maxMergeDocs
  
<property>
  
   <name>indexer.maxMergeDocs</name>
  
   <value>2147483647</value>
  
   <description>This number determines the maximum number of Lucene
  
   Documents to be merged into a new Lucene segment. Larger values
  
   increase batch indexing speed and reduce the number of Lucene  segments,
  
   which reduces the number of open file handles; however, this also
  
   decreases incremental indexing performance.
  
   </description>
  
</property>
  

这个好像不需要设置,因为默认的值是 Integer.MAX_VALUE , 不会比这个更大了。
1.16     searcher.summary.context
  
<property>
  
   <name>searcher.summary.context</name>
  
   <value>5</value>
  
   <description>
  
   The number of context terms to display preceding and following
  
   matching terms in a hit summary.
  
   </description>
  
</property>
  

这个比较有用,在前面的文章里有介绍。
1.17     searcher.summary.length
  
<property>
  
   <name>searcher.summary.length</name>
  
   <value>20</value>
  
   <description>
  
   The total number of terms to display in a hit summary.
  
   </description>
  
</property>
  

在前面的文章里也有介绍。
1.18      plugin.folders
  
<property>
  
   <name>plugin.folders</name>
  
   <value>plugins</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>
  
  
配置插件功能的配置项 ,plugin.folders制定插件加载路径
1.19     plugin.includes
  
<property>
  
   <name>plugin.includes</name>
  
   <value>protocol-http|urlfilter-regex|parse-(text|html|js)|index-basic|query-(basic|site|url)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
  
   <description>Regular expression naming plugin directory names to
  
   include.  Any plugin not  matching this expression is excluded.
  
   In any case you need at least include the nutch-extensionpoints  plugin. By
  
   default Nutch includes crawling just HTML and plain text via HTTP,
  
  and  basic indexing and search plugins. In order to use HTTPS please enable
  
   protocol-httpclient, but be aware of possible intermittent problems  with the
  
   underlying commons-httpclient library.
  
   </description>
  
</property>
  

配置插件功能的配置项 , plugin.includes表示需要加载的插件列表
1.20      parser.character.encoding.default
  
<property>
  
   <name>parser.character.encoding.default</name>
  
   <value>windows-1252</value>
  
   <description>The character encoding to fall back to when no  other information
  
   is available</description>
  
</property>
  

解析文档的时候使用的默认编码windows-1252好像比较少用到的一种编码,我不太熟悉。
1.21     parser.html.impl
  
<property>
  
   <name>parser.html.impl</name>
  
   <value>neko</value>
  
   <description>HTML Parser implementation. Currently the following  keywords
  
   are recognized: "neko" uses NekoHTML, "tagsoup"  uses TagSoup.
  
   </description>
  
</property>
  

制定解析HTML文档的时候使用的解析器, NEKO功能比较强大,后面会有专门的文章介绍Neko 从HTML到 TEXT以及html片断的解析等功能做介绍。
1.22     extension.clustering.hits-to-cluster
  
<property>
  
   <name>extension.clustering.hits-to-cluster</name>
  
   <value>100</value>
  
   <description>Number of snippets retrieved for the clustering  extension
  
   if clustering extension is available and user requested results
  
   to be clustered.</description>
  
</property>
  
聚合功能,对搜索结果有聚合需求的应用可能会用到。
1.23     extension.ontology.extension-name
  
<property>
  
   <name>extension.ontology.extension-name</name>
  
   <value></value>
  
   <description>Use the specified online ontology extension. If  empty,
  
   the first available extension will be used. The "name" here  refers to an 'id'
  
   attribute of the 'implementation' element in the plugin descriptor XML
  
   file.</description>
  
</property>
  


人工智能,这个功能在我以后的开发过程中会逐步深入,等我有相关的经验以后在给大家介绍。◎_◎
1.24     query.url.boost
  
<property>
  
   <name>query.url.boost</name>
  
   <value>4.0</value>
  
   <description> Used as a boost for url field in Lucene query.
  
   </description>
  
</property>
  
  
<property>
  
   <name>query.anchor.boost</name>
  
   <value>2.0</value>
  
   <description> Used as a boost for anchor field in Lucene query.
  
   </description>
  
</property>
  
  
<property>
  
   <name>query.title.boost</name>
  
   <value>1.5</value>
  
   <description> Used as a boost for title field in Lucene query.
  
   </description>
  
</property>
  
  
<property>
  
   <name>query.host.boost</name>
  
   <value>2.0</value>
  
   <description> Used as a boost for host field in Lucene query.
  
   </description>
  
</property>
  
  
<property>
  
   <name>query.phrase.boost</name>
  
   <value>1.0</value>
  
   <description> Used as a boost for phrase in Lucene query.
  
   Multiplied by boost for field phrase is matched in.
  
   </description>
  
</property>
  

以上的几个关于搜索结果排序的分值计算因子在以后的搜索结果排序会专门做介绍,这几个项对垂直搜索的用处不太大。
1.25     lang.analyze.max.length
  
<property>
  
   <name>lang.analyze.max.length</name>
  
   <value>2048</value>
  
   <description> The maximum bytes of data to uses to indentify
  
   the language (0 means full content analysis).
  
   The larger is this value, the better is the analysis, but the
  
   slowest it is.
  
   </description>
  
</property>
  

和语言有关系,分词的时候会用到,不过我没用过这个配置项。
还有几个重要的配置项在nutch-site.xml里面配置。
1.26     searcher.dir
  
<property>
  
   <name>searcher.dir</name>
  
   <value>crawl</value>
  
   <description>
  
   Path to root of crawl.  This  directory is searched (in
  
   order) for either the file search-servers.txt, containing a list of
  
   distributed search servers, or the directory "index"  containing
  
   merged indexes, or the directory "segments" containing  segment
  
   indexes.
  
   </description>
  
</property>
  

可以有两种方式 ,如果指向的目录下面有 search-servers.txt 文件 ,那么优先处理 search-servers.txt文件中的内容 ,并解析其中复合hostname port格式的内容(即分布式查询请求),解析到后就想该服务器发送查询请求,如果没有则查找 segements 目录 ,segments 是本地索引文件。
如果两个都没有找到,她就要报错了。
search-servers.txt
内容很简单  例如:
127.0.0.1 9999
不过需要注意的是 ,这个 9999的端口 启动的 是查询服务器  ,是用 bin/nutch server 9999 的命令启动的,
和 namenode 启动比较相似 ,我当初接触的时候就以为是 namenode 的地址,郁闷的很久。
namenode  和 searchserver结合不太好 ,没有提供直接从 namenode 到searchserver 的 文件访问接口,需要自己开发,如果大
家知道有可以直接从namenode 到searchserver 的方法或者现成的程序,请告诉我一下,我需要,要是实在找不到,那就没办法了,自己写。
我现在从namenode 到 searchserver的方法比较原始,不值得推荐,所以就不作介绍了。

回复

使用道具 举报

ximenchuixuesun 发表于 2015-9-8 11:53:51
db.default.fetch.interval就是这个参数,貌似没有按照间隔时间进行自动抓取啊
回复

使用道具 举报

Alkaloid0515 发表于 2015-9-8 12:01:45
ximenchuixuesun 发表于 2015-9-8 11:53
db.default.fetch.interval就是这个参数,貌似没有按照间隔时间进行自动抓取啊

配置文件参数影响到了注入方式:

db.default.fetch.interval:按天设置爬取间隔,默认值30.0f。


参数作用是这个,看看是不是其它影响这个参数。
回复

使用道具 举报

ximenchuixuesun 发表于 2015-9-8 14:36:33
是不是这样的,我第一次运行bin/crawl urls innoway http://192.168.30.142:8080/solr 3这个命令之后,初始抓取网页之后,下一次就会根据 db.default.fetch.interval的爬取间隔进行爬取了呢,不需要我再进行cron调度了吧
回复

使用道具 举报

ximenchuixuesun 发表于 2015-9-8 14:39:33
那是不是就是这样的流程:我首次执行完bin/crawl urls innoway http://192.168.30.142:8080/solr 3这条命令进行首次页面抓取之后,下一次就是自动按照 db.default.fetch.interval的爬取间隔进行自动抓取网页了呢,还需要我用cron去设置抓取调度么?谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条