一责嚷、Phoenix簡介
Phoenix是一個HBase的開源SQL引擎跑揉。你可以使用標準的JDBC API代替HBase客戶端API來創(chuàng)建表惨好,插入數(shù)據(jù)啃勉,查詢你的HBase數(shù)據(jù)忽舟。
Phoenix是構建在HBase之上的SQL引擎。你也許會存在“Phoenix是否會降低HBase的效率淮阐?”或者“Phoenix效率是否很低叮阅?”這樣的疑慮,事實上并不會泣特,Phoenix通過以下方式實現(xiàn)了比你自己手寫的方式相同或者可能是更好的性能(更不用說可以少寫了很多代碼):
編譯你的SQL查詢?yōu)樵鶫Base的scan語句
檢測scan語句最佳的開始和結束的key
精心編排你的scan語句讓他們并行執(zhí)行
讓計算去接近數(shù)據(jù)通過
推送你的WHERE子句的謂詞到服務端過濾器處理
執(zhí)行聚合查詢通過服務端鉤子(稱為協(xié)同處理器)
除此之外浩姥,Phoenix還做了一些有趣的增強功能來更多地優(yōu)化性能:
實現(xiàn)了二級索引來提升非主鍵字段查詢的性能
統(tǒng)計相關數(shù)據(jù)來提高并行化水平,并幫助選擇最佳優(yōu)化方案
跳過掃描過濾器來優(yōu)化IN状您,LIKE勒叠,OR查詢
優(yōu)化主鍵的來均勻分布寫壓力
二、下載CDH版Phoenix
1膏孟、下載
https://github.com/chiastic-security/phoenix-for-cloudera/tree/4.8-HBase-1.2-cdh5.8
2眯分、編譯(編譯時間較長,耐心等待)
mvn clean package -DskipTests
3、解壓
將編譯好的phoenix-4.8.0-cdh5.8.0.tar.gz解壓出來
[root@master1 phoenix]#tar -zxvf phoenix-4.8.0-cdh5.8.0.tar.gz
[root@master1 phoenix]# cd phoenix-4.8.0-cdh5.8.0
[root@master1 phoenix-4.8.0-cdh5.8.0]# ll
total 166152
drwxr-xr-x 2 root root 4096 Apr 18 16:41 bin
-rw-r--r-- 1 root root 1930 Aug 8 2016 build.txt
drwxr-xr-x 3 root root 4096 Aug 8 2016 dev
drwxr-xr-x 2 root root 4096 Aug 8 2016 docs
drwxr-xr-x 3 root root 4096 Aug 8 2016 examples
drwxr-xr-x 2 root root 4096 Apr 18 16:40 lib
-rw-r--r-- 1 root root 113247548 Apr 18 14:43 phoenix-4.8.0-cdh5.8.0-client.jar
-rw-r--r-- 1 root root 6619716 Apr 18 14:30 phoenix-4.8.0-cdh5.8.0-queryserver.jar
-rw-r--r-- 1 root root 22498517 Apr 18 14:43 phoenix-4.8.0-cdh5.8.0-server.jar
-rw-r--r-- 1 root root 27739579 Apr 18 14:29 phoenix-4.8.0-cdh5.8.0-thin-client.jar
4柒桑、將phoenix-4.8.0-cdh5.8.0-server.jar拷貝到每一個RegionServer下
[root@slave1 ~]# find / -name 'phoenix-4.8.0-cdh5.8.0-server.jar'
/soft/bigdata/clouderamanager/cloudera/parcels/CDH-5.10.0-1.cdh5.10.0.p0.41/lib/hbase/lib/phoenix-4.8.0-cdh5.8.0-server.jar
5弊决、增加hbase-site.xml 配置
<property>
<name>hbase.table.sanity.checks</name>
<value>false</value>
</property>
CDH修改方法:
在集群管理頁面點擊Hbase,進入Hbase管理界面
點擊配置
選擇高級
增加如下配置
6、重啟Hbase
7幕垦、登錄phoenix
進入phoenix-4.8.0-cdh5.8.0/bin目錄執(zhí)行
[root@master1 phoenix-4.8.0-cdh5.8.0]# cd /soft/phoenix/phoenix-4.8.0-cdh5.8.0/bin/
[root@master1 bin]# ll
total 140
-rwxr-xr-x 1 root root 32440 Aug 8 2016 daemon.py
-rwxr-xr-x 1 root root 1881 Aug 8 2016 end2endTest.py
-rw-r--r-- 1 root root 1621 Aug 8 2016 hadoop-metrics2-hbase.properties
-rw-r--r-- 1 root root 3056 Aug 8 2016 hadoop-metrics2-phoenix.properties
-rw-r--r-- 1 root root 1084 Aug 8 2016 hbase-site.xml
-rw-r--r-- 1 root root 2583 Aug 8 2016 log4j.properties
-rwxr-xr-x 1 root root 5128 Aug 8 2016 performance.py
-rwxr-xr-x 1 root root 3249 Aug 8 2016 pherf-cluster.py
-rwxr-xr-x 1 root root 2729 Aug 8 2016 pherf-standalone.py
-rwxr-xr-x 1 root root 9354 Aug 8 2016 phoenix_utils.py
-rw-r--r-- 1 root root 6082 Apr 18 16:41 phoenix_utils.pyc
-rwxr-xr-x 1 root root 2739 Aug 8 2016 psql.py
-rwxr-xr-x 1 root root 7659 Aug 8 2016 queryserver.py
-rw-r--r-- 1 root root 1820 Aug 8 2016 readme.txt
-rwxr-xr-x 1 root root 4315 Aug 8 2016 sqlline.py
-rwxr-xr-x 1 root root 5426 Aug 8 2016 sqlline-thin.py
-rw-r--r-- 1 root root 6895 Aug 8 2016 tephra
-rwxr-xr-x 1 root root 2037 Aug 8 2016 tephra-env.sh
-rwxr-xr-x 1 root root 6884 Aug 8 2016 traceserver.py
[root@master1 bin]# ./sqlline.py slave1:2181
Setting property: [incremental, false]
Setting property: [isolation, TRANSACTION_READ_COMMITTED]
issuing: !connect jdbc:phoenix:slave1:2181 none none org.apache.phoenix.jdbc.PhoenixDriver
Connecting to jdbc:phoenix:slave1:2181
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/soft/phoenix/phoenix-4.8.0-cdh5.8.0/phoenix-4.8.0-cdh5.8.0-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/soft/bigdata/clouderamanager/cloudera/parcels/CDH-5.10.0-1.cdh5.10.0.p0.41/jars/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
17/04/18 20:48:14 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Connected to: Phoenix (version 4.8)
Driver: PhoenixEmbeddedDriver (version 4.8)
Autocommit status: true
Transaction isolation: TRANSACTION_READ_COMMITTED
Building list of tables and columns for tab-completion (set fastconnect to true to skip)...
264/264 (100%) Done
Done
sqlline version 1.1.9
0: jdbc:phoenix:slave1:2181>
8、簡單測試
三傅联、squirrel安裝(windows上phoneix可視化工具)
1先改、下載
下載地址:http://www.squirrelsql.org/
下載所需版本
2、安裝
cmd進入命令行
在jar包存放路徑下輸入
java -jar squirrel-sql-snapshot-20170312_2141-standard.jar
一路next就安裝完畢
3蒸走、配置連接phoneix
在squirrel的lib下添加幾個jar包
雙擊squirrel安裝目錄下squirrel-sql.bat
點擊Drivers然后點擊+號
Name自己起,填寫url,
class name填寫org.apache.phoenix.jdbc.PhoenixDriver
然后點擊OK
點擊Aliases,然后點擊+號
Name自己起,選擇剛才配置的Driver
點擊OK連接成功
就可以看到phoenix的table了