小标
2018-10-12
来源 :
阅读 2033
评论 0
摘要:本文主要向大家介绍关于Java语言/Scala访问启用kerberos验证的Hadoop集群的代码实例了,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
本文主要向大家介绍关于Java语言/Scala访问启用kerberos验证的Hadoop集群的代码实例了,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
通过keytab的方式访问HDFS
Configuration config = new Configuration();
FileSystem hdfs = null;
try {
if (isKerberosEnable){
System.setProperty("java.security.krb5.conf", "./config/kerberos/krb5.conf");
config.set("hadoop.security.authentication","kerberos");
config.addResource("./config/cluster/hadoop/core-site.xml");
config.addResource("./config/cluster/hadoop/hdfs-site.xml");
UserGroupInformation.setConfiguration(config);
UserGroupInformation.loginUserFromKeytab(kerberosLoginUser, "./config/kerberos/hdfs.keytab");
UserGroupInformation userGroupInformation = UserGroupInformation.getLoginUser();
}
hdfs = FileSystem.get(URI.create(hdfsUri), config);
FSDataOutputStream outputStream = hdfs.create(new Path(hdfsFile), true);
IOUtils.copyBytes(inputStream, outputStream, 4096, true);
通过keytab方式访问HBASE
def setKerberosConf(conf: Configuration, sparkConf: SparkConf): Unit = {
conf.set("hbase.zookeeper.quorum", s"${zkaddress}")
conf.setInt("hbase.zookeeper.property.clientPort", 2181)
conf.set("zookeeper.znode.parent", "/hbase")
System.setProperty("java.security.krb5.conf", "conf/kerberos/krb5.conf")
conf.set("hadoop.security.authentication", "kerberos")
conf.set("hbase.security.authentication", "kerberos")
conf.set("keytab.file", Contants.HBASE_KERBEROS_KEYTAB_FILE)
conf.set("kerberos.principal",
sparkConf.get("hbase.kerberos.principal", Contants.HBASE_KERBEROS_PRINCIPAL))
conf.set("hbase.master.kerberos.principal",
sparkConf.get("hbase.master.kerberos.principal", Contants.HBASE_MASTER_KERBEROS_PRINCIPAL))
conf.set("hbase.regionserver.kerberos.principal",
sparkConf.get("hbase.regionserver.kerberos.principal", Contants.HBASE_REGIONSERVER_KERBEROS_PRINCIPAL))
UserGroupInformation.setConfiguration(conf)
UserGroupInformation.loginUserFromKeytab(
sparkConf.get("hbase.kerberos.user", Contants.HBASE_KERBEROS_USER),
Contants.HBASE_KERBEROS_KEYTAB_FILE)
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注编程语言JAVA频道!
喜欢 | 2
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号