版本hadoop3.x,spark3.x
有两种方式:一种是本地shell,kinit认证kerberos之后访问;另一种是spark-shell中添加--keytab方式
spark任务中统一的访问方式:
conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, hbaseZookeeperPort) conf.set(HConstants.ZOOKEEPER_QUORUM, hbaseZookeeperQuorum) conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, hbaseZookeeperZnodeParent) conf.set(HConstants.HBASE_RPC_TIMEOUT_KEY, "600000") conf.set(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, "600000") conf.set(HBASE_SECURITY_AUTHENTICATION, "simple") conf.setBoolean(HBASE_SECURITY_AUTHORIZATION, false) conf.setBoolean(HBASE_IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED, true) //设置查询的表名 conf.set(TableInputFormat.INPUT_TABLE, sourceTableName) val rdd = spark.sparkContext.newAPIHadoopRDD(conf, classOf[TableInputFormat], classOf[ImmutableBytesWritable], classOf[Result])
对上上面说的第一种情况,直接就可以访问了。
但是对于上面说的第二种情况,使用--keytab,虽然被访问集群没有启用kerberos认证,但是还是需要修改hadoop关于kerberos的配置:
hadoop.security.auth_to_local RULE:[1:$1@$0](.*@KEYTAB.COM)s/@.*// DEFAULT
注:KEYTAB.COM为keytab用户后缀