Apache Phoenix介绍&安装

混江龙づ霸主 提交于 2020-01-18 08:15:27

概述

Phoenix是构建在HBase上的一个SQL层,能让我们用标准的JDBC APIs而不是HBase客户端APIs来创建表,插入数据和对HBase数据进行查询。Phoenix完全使用Java编写,作为HBase内嵌的JDBC驱动。Phoenix查询引擎会将SQL查询转换为一个或多个HBase扫描,并编排执行以生成标准的JDBC结果集。下载apache-phoenix-4.10.0-HBase-1.2-bin.tar.gz,注意下载的Phoenix版本必须和hbase目标版本保持一致。更多版本 http://archive.apache.org/dist/phoenix

安装

  • 安装好HDFS,并且保证HDFS正常运行
  • 必须配置HADOOP_HOME,因为HBase需要通过该变量定位HADOOP服务
  • 安装Zookeeper(存储集群的元数据信息HMaster和HRegionServer)
[root@CentOS ~]# tar -zxf zookeeper-3.4.6.tar.gz  -C /usr/
[root@CentOS ~]# mkdir zkdata
[root@CentOS ~]# touch /usr/zookeeper-3.4.6/conf/zoo.cfg
[root@CentOS ~]# vi /usr/zookeeper-3.4.6/conf/zoo.cfg
tickTime=2000
dataDir=/root/zkdata
clientPort=2181
[root@CentOS ~]# /usr/zookeeper-3.4.6/bin/zkServer.sh start zoo.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@CentOS ~]# /usr/zookeeper-3.4.6/bin/zkServer.sh status zoo.cfg
JMX enabled by default
Using config: /usr/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
  • 安装配置hbase
[root@CentOS ~]# tar -zxf hbase-1.2.4-bin.tar.gz -C /usr/
[root@CentOS ~]# cd /usr/hbase-1.2.4/
[root@CentOS hbase-1.2.4]# vi conf/hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
                <name>hbase.rootdir</name>
                <value>hdfs://CentOS:9000/hbase</value>
    </property>
    <property>
                <name>hbase.cluster.distributed</name>
                <value>true</value>
    </property>
    <property>
                <name>hbase.zookeeper.quorum</name>
                <value>CentOS</value>
    </property>
    <property>
                <name>hbase.zookeeper.property.clientPort</name>
                <value>2181</value>
    </property>
    
    <property>
		<name>hbase.table.sanity.checks</name>
		<value>false</value>
	</property>
</configuration>
[root@CentOS hbase-1.2.4]#  vi conf/regionservers
CentOS
[root@CentOS ~]# vi .bashrc
JAVA_HOME=/usr/java/latest
HADOOP_HOME=/usr/hadoop-2.9.2
HBASE_HOME=/usr/hbase-1.2.4
ZOOKEEPER_HOME=/usr/zookeeper-3.4.6
PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$ZOOKEEPER_HOME/bin
CLASSPATH=.
export JAVA_HOME
export HADOOP_HOME
export HBASE_HOME
export PATH
export CLASSPATH
export ZOOKEEPER_HOME
[root@CentOS ~]# source .bashrc
[root@CentOS hbase-1.2.4]# vi conf/hbase-env.sh
export HBASE_MANAGES_ZK=false
  • 解压Phoenix安装包
[root@CentOS ~]# tar -zxf apache-phoenix-4.10.0-HBase-1.2-bin.tar.gz -C /usr/
[root@CentOS apache-phoenix-4.10.0-HBase-1.2-bin]# cp phoenix-4.10.0-HBase-1.2-server.jar /usr/hbase-1.2.4/lib
[root@CentOS apache-phoenix-4.10.0-HBase-1.2-bin]# cp phoenix-4.10.0-HBase-1.2-server.jar /usr/hbase-1.2.4/lib
[root@CentOS hbase-1.2.4]# ls -l lib/phoenix-4.10.0-HBase-1.2-*
-rw-r--r--. 1 root root 85701658 1月  10 13:50 lib/phoenix-4.10.0-HBase-1.2-client.jar
-rw-r--r--. 1 root root 25013545 1月  10 13:50 lib/phoenix-4.10.0-HBase-1.2-server.jar
  • 启动Hbase服务
[root@CentOS ~]# cd /usr/hbase-1.2.4/
[root@CentOS hbase-1.2.4]#  ./bin/start-hbase.sh
[root@CentOS hbase-1.2.4]#  jps
93714 QuorumPeerMain
3764 SecondaryNameNode
3572 DataNode
94759 HMaster
24342 NodeManager
24248 ResourceManager
3421 NameNode
95294 Jps

基本使用

1、链接Phoenix

[root@CentOS ~]# cd /usr/apache-phoenix-4.10.0-HBase-1.2-bin/
[root@CentOS apache-phoenix-4.10.0-HBase-1.2-bin]# ./bin/sqlline.py CentOS
SLF4J: Found binding in [jar:file:/usr/apache-phoenix-4.10.0-HBase-1.2-bin/phoenix-4.10.0-HBase-1.2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hadoop-2.9.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
20/01/10 14:37:07 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Connected to: Phoenix (version 4.10)
Driver: PhoenixEmbeddedDriver (version 4.10)
Autocommit status: true
Transaction isolation: TRANSACTION_READ_COMMITTED
Building list of tables and columns for tab-completion (set fastconnect to true to skip)...
98/98 (100%) Done
Done
sqlline version 1.2.0
0: jdbc:phoenix:CentOS>
create table t_user(
  id integer primary key,
  name varchar(32),
  age integer,
  sex boolean
)
0: jdbc:phoenix:CentOS> upsert into t_user values(1,'jiangzz',18,false);
0: jdbc:phoenix:CentOS> upsert into t_user values(2,'zhansgan',20,false);
0: jdbc:phoenix:CentOS> select * from t_user;
+-----+-----------+------+--------+
| ID  |   NAME    | AGE  |  SEX   |
+-----+-----------+------+--------+
| 1   | jiangzz   | 18   | false  |
| 2   | zhansgan  | 20   | false  |
+-----+-----------+------+--------+
2 rows selected (0.059 seconds)
0: jdbc:phoenix:CentOS> select sex,count(*) from t_user group by sex;
+--------+-----------+
|  SEX   | COUNT(1)  |
+--------+-----------+
| false  | 2         |
+--------+-----------+
1 row selected (0.068 seconds)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!