1. 下载phoenix
查看hbase版本:1.2.6
比对版本,下载相关的Phoenix。
2.
tar zxvf apache-phoenix-4.14.1-HBase-1.2-bin.tar.gz
mv apache-phoenix-4.14.1-HBase-1.2-bin phoenix
3.配置phoenix
3.1
cp phoenix-4.14.1-HBase-1.2-server.jar phoenix-core-4.14.1-HBase-1.2.jar /data/bigdata/hbase/lib/
3.2
cp /data/bigdata/hbase/conf/hbase-site.xml bin/
增加如下几项
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
<property>
<name>hbase.region.server.rpc.scheduler.factory.class</name>
<value>org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory</value>
</property>
cp /data/bigdata/hadoop/etc/hadoop/core-site.xml bin/
cp /data/bigdata/hadoop/etc/hadoop/hdfs-site.xml bin/
3.3
重启hbase
cd /data/bigdata/hbase
kill掉hbase进程
bin/start-hbase.sh
4. shell执行sql
4.1 使用psql.py
4.1.1 us_population.sql
内容:
CREATE TABLE IF NOT EXISTS us_population (
"state" CHAR(2) NOT NULL,
"city" VARCHAR(18) NOT NULL,
"info"."population" BIGINT,
CONSTRAINT my_pk PRIMARY KEY ("state", "city")
);
upsert into "US_POPULATION"("state","city","population") values('NY','New York',8143197);
upsert into "US_POPULATION"("state","city","population") values('CA','Los Angeles',3844829);
upsert into "US_POPULATION"("state","city","population") values('IL','Chicago',2842518);
upsert into "US_POPULATION"("state","city","population") values('TX','Houston',2016582);
upsert into "US_POPULATION"("state","city","info"."population") values('PA','Philadelphia',1463281);
upsert into "US_POPULATION"("state","city","info"."population") values('AZ','Phoenix',1461575);
upsert into "US_POPULATION"("state","city","info"."population") values('TX','San Antonio',1256509);
upsert into "US_POPULATION"("state","city","info"."population") values('CA','San Diego',1255540);
upsert into "US_POPULATION"("state","city","info"."population") values('TX','Dallas',1213825);
upsert into "US_POPULATION"("state","city","info"."population") values('CA','San Jose',912332);
执行命令:
bin/psql.py 10.88.0.54 /home/glsong/us_population.sql
4.1.2 us_population_queries.sql
SELECT "state" as "State",count("city") as "City Count",sum("population") as "Population Sum" FROM us_population GROUP BY "state" ORDER BY sum("population") DESC;
执行命令:
bin/psql.py 10.88.0.54 /home/glsong/us_population_queries.sql
4.2 使用
table.sql
内容:
create table sample(id integer primary key,t1 varchar,t2 varchar);
执行命令文件 table.sh
table.sh
!#/bin/bash
cd /home/glsong/phoenix/bin
./sqlline.py 10.10.1.1:2181 /home/glsong/table.sql
执行命令:
./table.sh