Hbase单机部署&phoenix引入

Hbase搭建

单机版本搭建Hbase可以无需使用hadoop,直接使用文件系统存储(本文方式)。也可以使用hadoop hdfs进行存储。
安装环境:centos7
软件版本:jdk1.8.0 hbase2.0.0 phoenix5.0

下载hbase-2.0.0-bin.tar.gz
解压:
tar -xvf hbase-2.0.0-bin.tar.gz
配置:
vi hbase-2.0.0/conf/hbase-env.sh 
配置java_home
export JAVA_HOME=/usr/java/jdk1.8.0_211-amd64
使用默认zk
export HBASE_MANAGES_ZK=true

vi hbase-2.0.0/conf/hbase-site.xml
添加内容:

<configuration>
        <property>
                <name>hbase.rootdir</name>
                <value>file:/home/XXX/hbase_data/hbase</value>
        </property>
        
</configuration>

引入phoenix

注意:使用phoenix要对应hbase的版本,根据phoenix命名对应
35EEF795-4708-4050-BC88-A259F949E68A.png
刚开始我使用了hbase2.0.5 phoenix5.0,创建索引正常,但是插入数据就会报错:
Failed 1 action: org.apache.phoenix.hbase.index.builder.IndexBuildingFailureException: Failed to build index for unexpected reason!
后面将hbase2.0.5换成hbase2.0.0,可以解决此问题。

开始安装:
下载apache-phoenix-5.0.0-HBase-2.0-bin.tar.gz
解压
tar -xvf apache-phoenix-5.0.0-HBase-2.0-bin.tar.gz
将phoenix-5.0.0-HBase-2.0-server.jar复制到hbase-2.0.0/lib/下
cp apache-phoenix-5.0.0-HBase-2.0-bin/phoenix-5.0.0-HBase-2.0-server.jar hbase-2.0.0/lib/

vi hbase-2.0.0/conf/hbase-site.xml
configuration标签中添加内容:

<property>
                <name>hbase.regionserver.wal.codec</name>
                <value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
        </property>

启动

启动hbase:
hbase-2.0.0/bin/start-hbase.sh
进入hbase控制台:
hbase shell

进入phoenix控制台:
sqlline.py localhost:2181

1.建表
create table if not exists equip_status(id bigint not null,equip_id integer,create_time date,status tinyint constraint my_pk primary key(id));

2.创建自增序列
CREATE SEQUENCE equip_sequence START WITH 10000 INCREMENT BY 1 CACHE 1;

3.插入测试数据
upsert into equip_status values (1,1, TO_DATE('2019-06-05 09:00:02'),0);

UPSERT INTO equip_status(id, equip_id, create_time,status) VALUES( NEXT VALUE FOR equip_sequence,1, TO_DATE('2019-06-05 09:00:03'),0)

4.创建二级索引
CREATE INDEX time_index ON equip_status(create_time desc);

可异步创建索引:
CREATE INDEX time_index ON equip_status(create_time desc) ASYNC;

删除索引:
drop index time_index ON equip_status;

5.使用二级索引查询
select create_time from equip_status order by create_time desc limit 1;

6.使用索引与不使用索引查询耗时对比
数据量:83万条数据
查询语句:
select * from equip_status where equip_id=1 order by create_time desc limit 1;
查询设备id为1最近一条的设备状态数据

不使用索引耗时:5.439 seconds
63D3732C-2BC0-4E0D-B8FD-CFB326B36E62.png

创建索引:
CREATE INDEX equip_index ON equip_status(equip_id,create_time desc,status);
查询耗时:0.036 seconds
027A1B17-D21D-4B84-91CD-74423F76A84F.png

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Kubernetes上部署HBase单机版,可以使用StatefulSet。以下是一个简单的步骤: 1. 创建一个配置文件hbase-config.yaml: ``` apiVersion: v1 kind: ConfigMap metadata: name: hbase-config data: hbase-site.xml: | <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hbase.rootdir</name> <value>file:///hbase</value> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>hbase-zookeeper-0.hbase-zookeeper.default.svc.cluster.local,hbase-zookeeper-1.hbase-zookeeper.default.svc.cluster.local,hbase-zookeeper-2.hbase-zookeeper.default.svc.cluster.local</value> </property> </configuration> ``` 2. 创建一个Headless Service: ``` apiVersion: v1 kind: Service metadata: name: hbase-headless spec: clusterIP: None selector: app: hbase ports: - name: thrift port: 9090 - name: rest port: 8080 ``` 3. 创建一个StatefulSet: ``` apiVersion: apps/v1 kind: StatefulSet metadata: name: hbase spec: serviceName: hbase-headless replicas: 1 selector: matchLabels: app: hbase template: metadata: labels: app: hbase spec: containers: - name: hbase image: hbase:2.2.4 command: - sh - -c - "echo 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' >> /etc/apt/sources.list && apt-get update && apt-get install -y netcat && /opt/hbase/bin/start-hbase.sh && tail -f /opt/hbase/logs/*" ports: - containerPort: 9090 name: thrift - containerPort: 8080 name: rest volumeMounts: - name: hbase-data mountPath: /hbase - name: hbase-config mountPath: /opt/hbase/conf/hbase-site.xml subPath: hbase-site.xml volumes: - name: hbase-data persistentVolumeClaim: claimName: hbase-data - name: hbase-config configMap: name: hbase-config ``` 4. 创建一个PersistentVolumeClaim: ``` apiVersion: v1 kind: PersistentVolumeClaim metadata: name: hbase-data spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi ``` 上述配置文件中,假设已经有一个Zookeeper集群,名称为hbase-zookeeper,并且已经部署在Kubernetes中。在上述配置文件中,使用HBase 2.2.4版本的镜像。在容器启动时,首先安装netcat,然后启动HBase,并保持日志输出。注意,hbase-site.xml文件被挂载到容器中。 以上是一个简单的部署HBase单机版的示例。根据实际情况,可能需要进行一些修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值