1. 官網資料html
Use JDBC to get a connection to an HBase cluster like this:node
Connection conn = DriverManager.getConnection("jdbc:phoenix:server1,server2:3333",props);
where props are optional properties which may include Phoenix and HBase configuration properties, and the connection string which is composed of:apache
jdbc:phoenix [ :<zookeeper quorum> [ :<port number> [ :<root node> [ :<principal> [ :<keytab file> ] ] ] ] ]
For any omitted parts, the relevant property value, hbase.zookeeper.quorum, hbase.zookeeper.property.clientPort, and zookeeper.znode.parent will be used from hbase-site.xml configuration file. The optional principal and keytab file may be used to connect to a Kerberos secured cluster. If only principal is specified, then this defines the user name with each distinct user having their own dedicated HBase connection (HConnection). This provides a means of having multiple, different connections each with different configuration properties on the same JVM.ide
For example, the following connection string might be used for longer running queries, where the longRunningProps specifies Phoenix and HBase configuration properties with longer timeouts:oop
Connection conn = DriverManager.getConnection(「jdbc:phoenix:my_server:longRunning」, longRunningProps);
Connection conn = DriverManager.getConnection("jdbc:phoenix:my_server:shortRunning", shortRunningProps);
Please read the relevant FAQ entry for example URLs.this
2. 源碼其餘配置方法spa
通過查看phoenix源代碼,發現
getConnection還有一個帶properties的接口,應該是鏈接屬性,code
properties.setProperty("hbase.zookeeper.quorum", "172.16.31.165,172.16.31.166,172.16.31.167"); properties.setProperty("hbase.master.kerberos.principal", "hadoop/_HOST@BONC"); properties.setProperty("hbase.regionserver.kerberos.principal", "hadoop/_HOST@BONC"); properties.setProperty("phoenix.queryserver.kerberos.principal", "hadoop/_HOST@BONC"); properties.setProperty("hbase.security.authentication", "kerberos"); properties.setProperty("hadoop.security.authentication", "kerberos"); properties.setProperty("zookeeper.znode.parent", "/hbase"); con = DriverManager.getConnection("jdbc:phoenix:172.16.31.165,172.16.31.166,172.16.31.167:2181:/hbase:"+principal+":"+keytab, properties);