phoenix 3.1 + hbase 0.94.21 的安装和使用

本文介绍如何在HBase 0.94.21上安装和配置Apache Phoenix 3.1,并演示了基本的SQL操作。首先下载Phoenix 3.1的压缩包并解压,接着将phoenix-core-3.1.0.jar添加到HBase regionserver的lib目录中,更新客户端的CLASSPATH,最后重启HBase服务。通过sqlline.py连接到Phoenix,创建表、插入数据并查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Apache Phoenix 是 HBase 的 SQL 驱动。Phoenix 使得 HBase 支持通过 JDBC 的方式进行访问,并将你的 SQL 查询转成 HBase 的扫描和相应的动作。

兼容性:

  • Phoenix 2.x - HBase 0.94.x

  • Phoenix 3.x - HBase 0.94.x

  • Phoenix 4.x - HBase 0.98.1+


1:hbase 0.94.21 的安装

参考http://blog.csdn.net/wind520/article/details/38614315


2:下载phoenix 3.1

[plain]  view plain  copy
  1. [jifeng@jifeng02 ~]# wget http://mirrors.hust.edu.cn/apache/phoenix/phoenix-3.1.0/bin/phoenix-3.1.0-bin.tar.gz  
  2. --2014-09-12 22:03:44--  http://mirrors.hust.edu.cn/apache/phoenix/phoenix-3.1.0/bin/phoenix-3.1.0-bin.tar.gz  
  3. 正在解析主机 mirrors.hust.edu.cn... 202.114.18.160  
  4. 正在连接 mirrors.hust.edu.cn|202.114.18.160|:80... 已连接。  
  5. 已发出 HTTP 请求,正在等待回应... 200 OK  
  6. 长度:55480477 (53M) [application/octet-stream]  
  7. 正在保存至: “phoenix-3.1.0-bin.tar.gz”  
  8. 2014-09-12 22:16:29 (70.8 KB/s) - 已保存 “phoenix-3.1.0-bin.tar.gz” [55480477/55480477])  

3:解压

[plain]  view plain  copy
  1. [jifeng@jifeng02 ~]$ tar zxf phoenix-3.1.0-bin.tar.gz   
  2. [jifeng@jifeng02 ~]$ cd phoenix-3.1.0-bin  
  3. [jifeng@jifeng02 phoenix-3.1.0-bin]$ ls  
  4. CHANGES  common  examples  hadoop1  hadoop2  LICENSE  NOTICE  README  

4:配置

参考:http://phoenix.apache.org/download.html

我这里使用的是Phoenix 3.x

To install a pre-built phoenix, use these directions:

  • Download and expand the latest phoenix-[version]-bin.tar. Use either hadoop1 and hadoop2 artifacts which match your HBase installation.
  • 下载,根据安装的HBase选择hadoop1或hadoop2
  • Add the phoenix-[version]-server.jar to the classpath of every HBase region server and remove any previous version. An easy way to do this is to copy it into the HBase lib directory (use phoenix-core-[version].jar for Phoenix 3.x)
  • 把phoenix-core-3.1.0.jar复制到所有HBase region server的lib目录
  • Restart all region servers.
  • 重启所有的Hbase region servers.
  • Add the phoenix-[version]-client.jar to the classpath of any Phoenix client.
  • Phoenix client服务器的CLASSPATH加上phoenix-3.1.0-client-hadoop1.jar
[plain]  view plain  copy
  1. [jifeng@jifeng02 phoenix-3.1.0-bin]$ cd common  
  2. [jifeng@jifeng02 common]$ ls  
  3. phoenix-3.1.0-client-minimal.jar  phoenix-3.1.0-client-without-hbase.jar  phoenix-core-3.1.0.jar  
  4. [jifeng@jifeng02 common]$ cp ./phoenix-core-3.1.0.jar /home/jifeng/hbase-0.94.21/lib  
  5. [jifeng@jifeng02 common]$ scp ./phoenix-core-3.1.0.jar jifeng@jifeng01:/home/jifeng/hbase-0.94.21/lib  
  6. phoenix-core-3.1.0.jar             100% 2178KB   2.1MB/s   00:00      
  7. [jifeng@jifeng02 common]$ cd ..  


在配置文件/home/jifeng/.bash_profile中

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:/home/jifeng/phoenix-3.1.0-bin/hadoop1/phoenix-3.1.0-client-hadoop1.jar

然后重启HBase

[plain]  view plain  copy
  1. [jifeng@jifeng01 hbase-0.94.21]$ bin/stop-hbase.sh  
  2. stopping hbase................  
  3. jifeng01: stopping zookeeper.  
  4. jifeng02: stopping zookeeper.  
  5. [jifeng@jifeng01 hbase-0.94.21]$ bin/start-hbase.sh  
  6. jifeng01: starting zookeeper, logging to /home/jifeng/hbase-0.94.21/bin/../logs/hbase-jifeng-zookeeper-jifeng01.out  
  7. jifeng02: starting zookeeper, logging to /home/jifeng/hbase-0.94.21/bin/../logs/hbase-jifeng-zookeeper-jifeng02.out  
  8. starting master, logging to /home/jifeng/hbase-0.94.21/logs/hbase-jifeng-master-jifeng01.out  
  9. jifeng01: starting regionserver, logging to /home/jifeng/hbase-0.94.21/bin/../logs/hbase-jifeng-regionserver-jifeng01.out  
  10. jifeng02: starting regionserver, logging to /home/jifeng/hbase-0.94.21/bin/../logs/hbase-jifeng-regionserver-jifeng02.out  


5:启动和简单操作

[plain]  view plain  copy
  1. [jifeng@jifeng02 bin]$ sqlline.py localhost  
  2. Setting property: [isolation, TRANSACTION_READ_COMMITTED]  
  3. issuing: !connect jdbc:phoenix:localhost none none org.apache.phoenix.jdbc.PhoenixDriver  
  4. Connecting to jdbc:phoenix:localhost  
  5. Connected to: Phoenix (version 3.1)  
  6. Driver: org.apache.phoenix.jdbc.PhoenixDriver (version 3.1)  
  7. Autocommit status: true  
  8. Transaction isolation: TRANSACTION_READ_COMMITTED  
  9. Building list of tables and columns for tab-completion (set fastconnect to true to skip)...  
  10. 59/59 (100%) Done  
  11. Done  
  12. sqlline version 1.1.2  
  13. 0: jdbc:phoenix:localhost> select * from b_month  
  14. . . . . . . . . . . . . .> ;  
  15. Error: ERROR 1012 (42M03): Table undefined. tableName=B_MONTH (state=42M03,code=1012)  
  16. 0: jdbc:phoenix:localhost> create table test (a integer primary key, b integer) ;  
  17. No rows affected (1.534 seconds)  
  18. 0: jdbc:phoenix:localhost> UPSERT INTO TEST VALUES (1, 1);  
  19. 1 row affected (0.018 seconds)  
  20. 0: jdbc:phoenix:localhost> UPSERT INTO TEST VALUES (2, 12);  
  21. 1 row affected (0.01 seconds)  
  22. 0: jdbc:phoenix:localhost> select * from test;  
  23. +------------+------------+  
  24. |     A      |     B      |  
  25. +------------+------------+  
  26. | 1          | 1          |  
  27. | 2          | 12         |  
  28. +------------+------------+  
  29. 2 rows selected (0.056 seconds)  
  30. 0: jdbc:phoenix:localhost>   


6:查看hbase中的表test


[plain]  view plain  copy
  1. [jifeng@jifeng01 hbase-0.94.21]$ hbase shell  
  2. HBase Shell; enter 'help<RETURN>' for list of supported commands.  
  3. Type "exit<RETURN>" to leave the HBase Shell  
  4. Version 0.94.21, r83b4a1ee9b9a2fa4c7ae1739259e041cabe8edc2, Fri Jun 27 16:14:16 UTC 2014  
  5.   
  6. hbase(main):001:0> list  
  7. TABLE                                                                                                                                 
  8. SYSTEM.CATALOG                                                                                                                        
  9. SYSTEM.SEQUENCE                                                                                                                       
  10. TEST                                                                                                                                  
  11. b_month                                                                                                                               
  12. mytable                                                                                                                               
  13. 5 row(s) in 0.6250 seconds  
  14.   
  15. hbase(main):003:0> scan 'TEST'  
  16. ROW                                COLUMN+CELL                                                                                        
  17.  \x80\x00\x00\x01                  column=0:B, timestamp=1410534991931, value=\x80\x00\x00\x01                                        
  18.  \x80\x00\x00\x01                  column=0:_0, timestamp=1410534991931, value=                                                       
  19.  \x80\x00\x00\x02                  column=0:B, timestamp=1410535001115, value=\x80\x00\x00\x0C                                        
  20.  \x80\x00\x00\x02                  column=0:_0, timestamp=1410535001115, value=                                                       
  21. 2 row(s) in 0.0770 seconds  
  22.   
  23. hbase(main):004:0>   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值