关于Apache Phoenix和Cloudera结合

1. 安装:

phoenix的官网最新版4.13.2是有parcle版本的,并不需要从cloudera的labs(实验室)中下载。

安装完成后,可以运行一下phoenix的shell来简单验证一下:/opt/cloudera/parcels/APACHE_PHOENIX/bin

2. 在实际的应用中:

  Caused by: java.lang.ClassNotFoundException: org.apache.http.config.Lookup

  添加了httpcore的jar的最新版本的引用;

  NoClassDefFoundError: org/apache/http/protocol/HttpContext

  发现不能使用最新版本(4.4.9),需要使用4.4版本,问题解决

  java.net.SocketTimeoutException: callTimeout=60000, callDuration=68229: row 'SYSTEM:CATALOG,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=slave3,60020,1517911366463, seqNum=0

  重启了Zookeeper和HBase问题解决

  Exception in thread "main" java.sql.SQLException: ERROR 2006 (INT08): Incompatible jars detected between client and server. Ensure that phoenix.jar is put on the classpath of HBase in every region server: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator

  这个问题没有解决,网调原因是调用端的guava的版本和服务器的版本不一致;但是我尝试了几个版本的guava都没有成功;于是切换到了高版本的phoenix,使用thin-client来进行处理。thin-client非常小,几百K,但是如果想要用原生的jdbc客户端,你需要引用整个phoenix包,100M;thin-client的引用可能就是这个原因吧。但是想要使用thin-client需要启动thin-server。

3. 关于使用thin-client:

步骤如下:

  第一步要启动thin-server,可以通过lsof -i:8765来判断是否启动成功(不过queryserver的路径比较深:/opt/cloudera/parcels/APACHE_PHOENIX/lib/phoenix/bin);

   ./queryserver.py start

  注意,如果重复启动,将会碰到Address已经被占用的异常;

  第二步,设置maven引用:

 1 <dependency>
 2     <groupId>org.apache.phoenix</groupId>
 3     <artifactId>phoenix-queryserver-client</artifactId>
 4     <version>4.13.2-cdh5.11.2</version>
 5 </dependency>
 6 <dependency>
 7     <groupId>org.apache.httpcomponents</groupId>
 8     <artifactId>httpclient</artifactId>
 9     <version>4.5.2</version>
10 </dependency>
11 <dependency>
12     <groupId>org.apache.httpcomponents</groupId>
13     <artifactId>httpcore</artifactId>
14     <version>4.4</version>
15 </dependency>

  第三步jdbc代码实现访问:

String testSQL = "select * from HBASE_TEST";
try {
    Class.forName("org.apache.phoenix.queryserver.client.Driver");
} catch (ClassNotFoundException e1) {
    System.out.println("org.apache.phoenix.queryserver.client.Driver未找到");
}
List<String> resList = new ArrayList<String>();
Connection con1 = DriverManager
        .getConnection("jdbc:phoenix:thin:url=http://10.1.108.65:8765;serialization=PROTOBUF", "", "");
Statement stmt = con1.createStatement();
ResultSet rset = stmt.executeQuery(testSQL);
while (rset.next()) {
    String msg = String.format("S1:%s; S2:%s; S3:%s; S4:%s", rset.getString("S1"), rset.getString("S2"),
            rset.getString("S3"), rset.getString("S4"));
    System.out.println(msg);
}

stmt.close();
con1.close();