在Nutch2.x只后,Nutch存储映射使用apache的Gora(Gora是一个开源的ORM框架),为了了解Gora是个什么东西,我就从网上随便搜了一些Gora框架的介绍。
Gora就是一个大数据的表示与持久化框架,它有如下特点
数据持久化:它可以对列数据进行持久化,如HBase,Cassandra,Hypertable; key-value数据进行持久化,如Voldermort,Redis等,SQL数据库进行持久化,如MySQL,HSQLDB,也可以对文件进行HDFS存储 。
数据访问:可以使用Java API对数据进行轻松的访问
索引:可以持久化对象到Lucene或者Solr中去,可以使用Gora API来进行查询
分析:可以使用Apache Pig,Hive,cascading来对数据进行分析
MR的支持:原生支持Hadoop的MR框架,这个已经被用在Nutch 2.0上了
支持使用Pig,lucene,hive等针对数据进行持久化,索引和分析工作
目前除Nutch2外,在其他开源产品中使用Gora的好像没有看到
Nutch2系列通过gora对存储层进行了扩展,可以选择使用HBase、Accumulo、Cassandra 、MySQL 、DataFileAvroStore、AvroStore中任何一种来存储数据,但其中一些并不成熟。
目前gora还亟待改进。对于追求性能极致的朋友来说,nutch2.x还不稳定,建议使用nutch1.x,利用HDFS和MapReduce的数据本地化及天然的并行性,可以优化到非常快的速度。
Apache Gora介绍-阿里云开发者社区 (aliyun.com)
引用原文发布时间:2016-05-13
现在:2021-12-03(相隔了5年了,到现在了Gora还在跟新,看来Apache想对NoSQL数据库们提供一套通用的框架)
到Gora的0.9版本已经可以适配一下大数据框架了,我们这里可以看到Solr这些搜索引擎的适配
Gora 0.9 provides support for the following projects
- Apache Avro 1.8.2
- Apache HBase 2.1.1
- Apache Cassandra 3.11.0 (Datastax Java Driver 3.3.0)
- Apache Solr 8.0.0
- Apache Lucene 8.0.0
- MongoDB (Mongo Java Driver) 3.5.0
- Apache Accumlo 1.7.1
- Apache CouchDB 1.4.2
- Amazon DynamoDB (Amazon Java SDK) 1.10.55
- Infinispan 7.2.5.Final
- JCache 1.0.0 with JCache provider Hazelcast 3.6.4
- OrientDB 2.2.22
- Aerospike 4.2.2
- Apache Ignite 2.6.0
- Apache Pig 0.16.0
- Apache Flink 1.6.2
- Apache Hadoop 2.5.2
- Apache Spark 2.2.1
- Test containers 1.4.2
找到storage properties,可以看到如果我们不在nutch-site.xml中不配置storage.data.store.class这个property时,默认是会使用org.apache.gora.memory.store.MemStore作为存储方式
org.apache.gora.memory.store.MemStore
Gora class for storing data in a Memory based implementation for tests.
从这个可以知道这个默认存储方式的内存的,用于测试使用
<!-- storage properties -->
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.memory.store.MemStore</value>
<description>The Gora DataStore class for storing and retrieving data.
Currently the following stores are available:
org.apache.gora.sql.store.SqlStore
Default store. A DataStore implementation for RDBMS with a SQL interface.
SqlStore uses JDBC drivers to communicate with the DB. As explained in
ivy.xml, currently >= gora-core 0.3 is not backwards compatable with
SqlStore.
org.apache.gora.cassandra.store.CassandraStore
Gora class for storing data in Apache Cassandra.
org.apache.gora.hbase.store.HBaseStore
Gora class for storing data in Apache HBase.
org.apache.gora.accumulo.store.AccumuloStore
Gora class for storing data in Apache Accumulo.
org.apache.gora.memory.store.MemStore
Gora class for storing data in a Memory based implementation for tests.
org.apache.gora.mongodb.store.MongoStore
Gora class for storing data in MongoDB.
org.apache.gora.solr.store.SolrStore
Gora class for storing data in Apache Solr.
</description>
</property>
apache-nutch-2.4\runtime\local\conf
文件夹下面的nutch-site.xml
文件(源码经过ant编译后才有runtime目录)中添加以下配置<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.hbase.store.HBaseStore</value>
</property>
apache-nutch-2.4\runtime\local\conf
文件夹下面的gora.properties
文件(源码经过ant编译后才有runtime目录),根据HBaseStore properties注释,对hbase.site.xml
配置有效的hbase.zookeeper.quorum
属性,如果没配置就默认zookeeper的地址是localhost:2181。#########################
# HBaseStore properties #
#########################
# HBase requires that the Configuration has a valid "hbase.zookeeper.quorum"
# property. It should be included within hbase-site.xml on the classpath. When
# this property is omitted, it expects Zookeeper to run on localhost:2181.
# To greatly improve scan performance, increase the hbase-site Configuration
# property "hbase.
在apache-nutch-2.4\runtime\local\conf
中的hbase.site.xml
添加属性hbase.zookeeper.quorum
。
<property>
<name>hbase.zookeeper.quorum</name>
<!--更改为自己zookeeper的地址-->
<value>localhost</value>
</property>
在apache-nutch-2.4\runtime\local\conf
文件夹下面的nutch-site.xml
文件(源码经过ant编译后才有runtime目录)中添加以下配置
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.sql.store.SqlStore</value>
</property>
apache-nutch-2.4\runtime\local\conf
文件夹下面的gora.properties
文件(源码经过ant编译后才有runtime目录),添加以下配置。###############################
# MySQL properties #
###############################
gora.sqlstore.jdbc.driver=com.mysql.jdbc.Driver
gora.sqlstore.jdbc.url=jdbc:mysql://localhost:3306/nutch?useUnicode=true&character=utf8&useSSL=false&serverTimezone=UTC
gora.sqlstore.jdbc.user=xxxxx
gora.sqlstore.jdbc.password=xxxxx
Nutch是使用ivy实现jar包管理的,ivy是类似于maven的jar包管理工具,在使用ant编译源码前,对ivy的依赖配置进行修改。
打开apache-nutch-2.4\ivy
文件夹,找到ivy.xml
文件。
找到Hadoop Dependencies的依赖配置,可以根据自己的需要修改成自己hadoop版本的jar包。
<!-- Hadoop Dependencies -->
<dependency org="org.apache.hadoop" name="hadoop-common" rev="2.5.2" conf="*->default">
<exclude org="hsqldb" name="hsqldb" />
<exclude org="net.sf.kosmosfs" name="kfs" />
<exclude org="net.java.dev.jets3t" name="jets3t" />
<exclude org="org.eclipse.jdt" name="core" />
<exclude org="org.mortbay.jetty" name="jsp-*" />
<exclude org="ant" name="ant" />
</dependency>
<dependency org="org.apache.hadoop" name="hadoop-hdfs" rev="2.5.2" conf="*->default"/>
<dependency org="org.apache.hadoop" name="hadoop-mapreduce-client-core" rev="2.5.2" conf="*->default"/>
<dependency org="org.apache.hadoop" name="hadoop-mapreduce-client-jobclient" rev="2.5.2" conf="*->default"/>
<!-- End of Hadoop Dependencies -->
找到Gora的依赖配置
<!--================-->
<!-- Gora artifacts -->
<!--================-->
<!-- N.B. To use Gora SNAPSHOT's, replace the 'ref' value with the SNAPSHOT version
and add changing="true" alongside the dependency declaration.-->
<dependency org="org.apache.gora" name="gora-core" rev="0.8" conf="*->default"/>
把hbase的依赖的注释去掉
<dependency org="org.apache.gora" name="gora-hbase" rev="0.8" conf="*->default" />
<dependency org="org.apache.hbase" name="hbase-common" rev="1.4.8" conf="*->default" />
org.apache.gora.sql.store.SqlStore
Default store. A DataStore implementation for RDBMS with a SQL interface.
SqlStore uses JDBC drivers to communicate with the DB. As explained in
ivy.xml, currently >= gora-core 0.3 is not backwards compatable with
SqlStore.根据nutch-site.xml中关于SqlStore 的解析,需要gora-core的版本要在0.3以下。
<dependency org="org.apache.gora" name="gora-core" rev="0.2.1" conf="*->default"/>
并添加gora-sql的依赖和MySQL的驱动
<!--gora-sql依赖-->
<dependency org="org.apache.gora" name="gora-sql" rev="0.1.1-incubating" conf="*->default" />
<!--添加mysql驱动-->
<dependency org="mysql" name="mysql-connector-java" rev="5.1.18" conf="*->default"/>
使用Hbase时需要对数据列进行映射,
使用MySQL整合nutch2.4要给MySQL创建一个表,以存储爬取的数据。
CREATE DATABASE nutch DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
CREATE TABLE `webpage` (`id` varchar(767) CHARACTER SET latin1 NOT NULL,
`headers` blob,
`text` mediumtext DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`markers` blob,
`parseStatus` blob,
`modifiedTime` bigint(20) DEFAULT NULL,
`score` float DEFAULT NULL,
`typ` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
`baseUrl` varchar(512) CHARACTER SET latin1 DEFAULT NULL,
`content` mediumblob,
`title` varchar(2048) DEFAULT NULL,
`reprUrl` varchar(512) CHARACTER SET latin1 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 DEFAULT CHARSET=utf8;