开发基于 Hbase的 应用 链接 Hbase 服务器 demo
一个网站的数据的增加是非常迅速的。。
要保存这些数据 在 mysql 数据库里面 是最好的办法。
如果这些数据 超过了一定的规模。比如 上 亿的历史数据。。查询起来可就比较麻烦了。。
而且如果要进行 统计分析。。分析用户的行为啥的。。还需要这些日志。
就连 用户的访问记录保留也是很有用的。。就像豆瓣的喜欢和垃圾桶功能也很重要。
通过这个就可以推算出你喜欢哪首歌曲。
别的就不废话了。相信你对大数据存储也很头疼。
下面介绍使用的技术。
首先你要有一个 hadoop的环境。
要使用 64bit的centos 6 使用 cloudera 的hadoop 和hbase 通过 yum 一并安装了。
具体安装配置 已经是很简化的了。。最简单的了。。
http://toeo.iteye.com/blog/1243592
然后你需要知道 我们 链接 hbase 就像链接 jpa 一样的。有这样的框架。
总之吧 hbase 的字段 都映射成 POJO 是很好的事情。
使用 datanucleus 进行封装对象:
地址:http://www.datanucleus.org/
如果要是可以把程序调通。写 hbase 程序就像和 写 JPA的程序一样了。
开始创建工程:
从官网下载一个 demo
http://sourceforge.net/projects/datanucleus/files/datanucleus-samples/
DataNucleus 最新版本是 3.0.4
同时DataNucleus 还支持其他 云数据的链接。比如 Google的 bigTable 。
大名鼎鼎的 google Appengine 也是使用 DataNucleus 中间件链接的。
所以不用怀疑可靠性。
首要要解决的就是jar包的依赖问题。
demo 里面居然把hbase 的groupId 写错了
应该是:
<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase</artifactId> <version>0.90.4</version> </dependency>
修修改改jar 总是是对了。。然后就是漫长的jar包下载。
要使用 datanucleus 必须安装 eclipse 插件:
因为需要在编译的时候 自动 enhanced 当然你也可以 手动 enhanced 比较麻烦
安装 eclipse 插件:
http://www.datanucleus.org/downloads/eclipse-update/
安装成功重启
启用 enhanced 在 build 的时候 就可以看到 enhanced 的过程了。。
enhanced 2 个 class。
如果不安装 则代码 运行不了:
报错:
Persisting Account+Login Exception in thread "main" org.datanucleus.api.jdo.exceptions.ClassNotPersistenceCapableException: The class "org.datanucleus.samples.jdo.hbase.Account" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:351) at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:745) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:765) at org.datanucleus.samples.jdo.hbase.Main.main(Main.java:46) NestedThrowablesStackTrace: The class "org.datanucleus.samples.jdo.hbase.Account" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. org.datanucleus.exceptions.ClassNotPersistableException: The class "org.datanucleus.samples.jdo.hbase.Account" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found. at org.datanucleus.ObjectManagerImpl.assertClassPersistable(ObjectManagerImpl.java:5330) at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1704) at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1647) at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1512) at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:740) at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:765) at org.datanucleus.samples.jdo.hbase.Main.main(Main.java:46)
确认 hbase 已经启动:zookeeper 已经启动:
否则会报链接错误:
11/12/23 16:36:15 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.SocketException: Address family not supported by protocol family: connect at sun.nio.ch.Net.connect(Native Method) at sun.nio.ch.SocketChannelImpl.connect(Unknown Source) at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1050) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1077) 11/12/23 16:36:15 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181 11/12/23 16:36:16 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused: no further information at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
编译的时候添加 :
<dependency> <groupId>org.datanucleus</groupId> <artifactId>datanucleus-enhancer</artifactId> <version>3.0.1</version> </dependency>
否则会报找不到 jar:
java.lang.NoClassDefFoundError: org/datanucleus/enhancer/DataNucleusEnhancer
查看zookeeper 启动:
附件代码:暂时没有跑通。因为hbase 安装在虚拟机上面
以后陆续补上。也可能是hbase 没有配置对。

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
debian 系统安装 hadoop 和hbase 环境。
由于 自己使用的电脑 是debian 系统。所以 也想在自己的电脑上面安装一个 hbase 的环境。 笔记本 是64 bit 的但好像不可以,虚拟 64bit的系统。 所以干脆 装一个 环境算了。。 参考文档: https://ccp.cloudera.com/display/CDHDOC/CDH3+Installation https://ccp.cloudera.com/display/DOC/Documentation 1,下载 all.deb 安装包 wgethttp://archive.cloudera.com/one-click-install/squeeze/cdh3-repository_1.0_all.deb sudo dpkg -i cdh3-repository_1.0_all.deb 2,增加 一个 source 源 sudo vi/etc/apt/sources.list.d/cloudera.list 添加如下内容: debhttp://archive.cloudera.com/debian<RELEASE>-cdh3 co...
- 下一篇
CentOS 安装 hadoop hbase 使用 cloudera 版本。(一)
使用Virtualbox安装系统和 hadoop ,hbase 参考安装: cloudera 的hadoop 只支持 64bit的版本.而要用虚拟机安装 64bit 的要满足 4个条件. 1, 64bit的cpu 3, 64bit的操作系统 3, 64bit的VirtualBox 4, 必须允许硬件虚拟化(需要到 bios 里面打开virtualization的一项) Debian 64bit install VirtualBox. #修改apt source 权限。 sudo chmod +w /etc/apt/sources.list 添加一行。 sudo vi /etc/apt/sources.list #virtual box. deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free #再把权限修改回去。 sudo chmod -w /etc/apt/sources.list #添加key wget -q http://download.virtualbox....
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS7安装Docker,走上虚拟化容器引擎之路
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS8安装Docker,最新的服务器搭配容器使用
- Hadoop3单机部署,实现最简伪集群
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS8编译安装MySQL8.0.19