您好,登錄后才能下訂單哦!
SparkSQL怎么連接開啟Kerberos認證的Phoenix,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
SparkSQL可以與HBase交互,比如說通過jdbc,但是實際使用時,一般是利用Phoenix操作HBase,由于我們這里HDP集群開啟了Kerberos安全認證,網上也沒有連接代碼實例,這里我整理了一個完整的實戰代碼給大家分享一下經驗:
組件版本信息:
spark2.2.0
phoenix4.10.0
票據和krb5.conf信息根據自己的集群去修改,代碼如下:
package com.hadoop.ljs.spark220.security;import org.apache.spark.SparkConf;import org.apache.spark.sql.Dataset;import org.apache.spark.sql.Row;import org.apache.spark.sql.SQLContext;import org.apache.spark.sql.SparkSession;import java.util.Properties;/** * @author: Created By lujisen * @company ChinaUnicom Software JiNan * @date: 2020-03-04 10:41 * @version: v1.0 * @description: com.hadoop.ljs.spark220.security */public class SparkKerberosPhoenix { public static final String krb5Conf="D:\\kafkaSSL\\krb5.conf"; public static final String zookeeperQuorum="salver158.hadoop.unicom,salver31.hadoop.unicom,salver32.hadoop.unicom"; public static final String zookeeperZnode="/hbase-secure"; public static final String zookeeperPort="2181"; public static final String userTicket="hbase-unicomhdp98@CHINAUNICOM"; public static final String userKeytab="D:\\kafkaSSL\\hbase.headless.keytab"; public static final String hbaseMasterPrincipal="hbase/_HOST@CHINAUNICOM"; public static final String hbaseRegionserverPrincipal="hbase/_HOST@CHINAUNICOM"; public static final String phoenixKerbersURL="jdbc:phoenix:" +zookeeperQuorum+":"+zookeeperPort+":" +zookeeperZnode+":"+userTicket+":"+userKeytab; public static void main(String[] args) { // 初始化配置文件 System.setProperty("java.security.krb5.conf",krb5Conf); SparkConf conf = new SparkConf().setAppName("PhoenixSparkDemo") .setMaster("local[*]") .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); SparkSession sparkSession = SparkSession.builder().config(conf).getOrCreate(); Properties props=new Properties(); props.setProperty("phoenix.schema.isNamespaceMappingEnabled", "true"); props.setProperty("phoenix.schema.mapSystemTablesToNamespace", "true"); props.setProperty("hbase.security.authentication", "kerberos"); props.setProperty("hadoop.security.authentication", "kerberos"); props.setProperty("hadoop.security.authorization", "true"); props.setProperty("hbase.security.authorization", "true"); props.setProperty("hbase.zookeeper.quorum", zookeeperQuorum); props.setProperty("zookeeper.znode.parent", zookeeperZnode); props.setProperty("hbase.zookeeper.property.clientPort", zookeeperPort); props.setProperty("hbase.master.kerberos.principal", hbaseMasterPrincipal); props.setProperty("hbase.regionserver.kerberos.principal", hbaseRegionserverPrincipal); Dataset<Row> df = sparkSession .read() .jdbc(phoenixKerbersURL,"LUJS.TBL_ORDER",props); df.createOrReplaceTempView("TBL_ORDER"); SQLContext sqlCtx = new SQLContext(sparkSession); df = sqlCtx.sql("select * from TBL_ORDER limit 10"); df.show(); sparkSession.stop(); }}
補充:
后面如果需要通過spark-submit提交phoenix代碼,需要配置以下幾項,這里可以參考phoenix官網:
1.做了HA的yarn集群這個配置有時候沒修改過來,確認yarn-site.xml中的配置:
yarn.client.failover-proxy-provider=org.apache.hadoop.yarn.client.RequestHedgingRMFailoverProxyProvider
修改為:
yarn.client.failover-proxy-provider=org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider
2.提交命令中指定以下兩個配置項,或者配置到spark2-defaults.conf配置文件中
spark.driver.extraClassPath=/usr/hdp/current/phoenix-client/phoenix-4.10.0-HBase-1.2-client.jarspark.executor.extraClassPath=/usr/hdp/current/phoenix-client/phoenix-4.10.0-HBase-1.2-client.jar
或者提交任務手動指定即可:
spark.driver.extraClassPath
spark.executor.extraClassPath
/usr/hdp/2.6.3.0-235/spark2/bin/spark-submit --class com.hadoop.ljs.spark.SparkOnPhoenix --conf spark.driver.extraClassPath=/usr/hdp/current/phoenix-client/phoenix-4.10.0-HBase-1.2-client.jar --conf spark.executor.extraClassPath=/usr/hdp/current/phoenix-client/phoenix-4.10.0-HBase-1.2-client.jar --jars /usr/hdp/2.6.3.0-235/phoenix/phoenix-4.10.0-HBase-1.2-client.jar spark220Scala-1.0-SNAPSHOT.jar
關于SparkSQL怎么連接開啟Kerberos認證的Phoenix問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。