Phoenix,通过hbase建立二级索引的,百万级数据能在毫秒返回。RT是在秒级以内。
(所有安装注意版本是否兼容)
安装HBase,见。spring cloud 分布式Hadoop三部曲之HBase_lvhao2813的博客-CSDN博客
下载phoenix
官网下载地址:http://phoenix.apache.org/download.html
hadoop-3.2.1 + hbase-2.2.4 + phoenix-5.1.2
解压
tar -zxvf phoenix-hbase-2.2-5.1.2-bin.tar.gz
将phoenix-server-hbase-2.2-5.1.2.jar 复制到Hbase的安装目录下
HBASE_HOME/lib目录下(3台集群都移动)
cp PHOENIX_HOME/phoenix-server-hbase-2.2-5.1.2.jar HBASE_HOME/lib/phoenix-server-hbase-2.2-5.1.2.jar
cp /myfiles/phoenix/phoenix-server-hbase-2.2-5.1.2.jar /myfiles/hbase/hbase-2.2.4/lib/phoenix-server-hbase-2.2-5.1.2.jar
配置
配置HBASE_HOME/conf/hbase-site.xml
1.如果需要运用到NameSpace(相当于DB中数据库概念)需要加入配置,不配置默认为default库
<property>
<name>phoenix.schema.isNamespaceMappingEnabled</name>
<value>true</value>
</property>
2.使用二级索引需要加上
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
重启Hbase
stop-hbase.sh
start-hbase.sh
Phoenix在linux安装,可以通过命令写sql查询
如果需要使用phoenix shell操作需要
将以下3个文件拷贝到 PHOENIX_HOME/bin目录下:
HADOOP_HOME/etc/hadoop/hdfs-site.xml
HADOOP_HOME/etc/hadoop/core-site.xml
HBASE_HOME/conf/hbase-site.xml
- 需要保证配置文件一致
在PHOENIX_HOME/bin进入phoenix
./sqlline.py hostname:2181
或
./sqlline.py hostname1,hostname2,hostname3:2181
在windows安装DBeaver连接Phoenix,可以通过命令写sql查询,以及可视化编辑(类似于navicat)
通过上面下载phoenix包中的phoenix-client-hbase-2.2-5.1.2.jar加到里面,注意版本一致。
如果配置了NameSpace,需要在DBeaver中也配置一下
<property>
<name>phoenix.schema.isNamespaceMappingEnabled</name>
<value>true</value>
</property>
旁边为数据库导航,如果没有重启DBeaver或者刷新
SpringBoot集成HBase
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>2.2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>5.1.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-hbase-compat-2.2.5</artifactId>
<version>5.1.2</version>
</dependency>
spring:
datasource:
driver-class-name: org.apache.phoenix.jdbc.PhoenixDriver
url: jdbc:phoenix:node01,node02,node03:2181
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
max-active: 100
max-wait: 60000
min-evictable-idle-time-millis: 600000
min-idle: 1
test-on-borrow: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
mybatis:
mapperLocations: classpath:mybatis/*.xml
将HBASE_HOME/conf/hbase-site.xml和HADOOP_HOME/etc/hadoop/core-site.xml复制到项目resources目录下
问题记录
hbase表与zookeeper记录不一致导致启动异常
使用zkCli.sh进入zookeeper
zkCli.sh
1
通过ls 命令查看hbase节点
通过命令删除该节点(会导致数据丢失)
deleteall /hbase
1
regionserver.HRegionServer: Failed construction RegionServer
将HBASE_HOME/lib/client-facing-thirdparty复制到HBASE_HOME/lib