troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm

KrbException: Cannot locate default realm

 

解决办法

1)拷贝需要组件的配置文件到项目中的 /resources/目录。如hadoop,目录/etc/hadoop/conf/

troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm_第1张图片

troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm_第2张图片

2)代码中写入如下代码

System.setProperty("java.security.krb5.conf", "D:\\work\\conf\\krb5.conf")
System.setProperty("HADOOP_USER_NAME", "chenweidong")
System.setProperty("user.name", "chenweidong");
UserGroupInformation.loginUserFromKeytab("[email protected]", "D:\\work\\conf\\cwd.keytab")
System.out.println(UserGroupInformation.getLoginUser())

异常日志

18/09/20 16:53:44 INFO SparkContext: Running Spark version 2.3.0
Exception in thread "main" java.lang.IllegalArgumentException: Can't get Kerberos realm
at org.apache.hadoop.security.HadoopKerberosName.setConfiguration(HadoopKerberosName.java:65)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:275)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:260)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:789)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:774)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:647)
at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2464)
at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2464)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.util.Utils$.getCurrentUserName(Utils.scala:2464)
at org.apache.spark.SparkContext.(SparkContext.scala:292)
at com.cm.data.dataproc.ETLTest$.main(ETLTest.scala:20)
at com.cm.data.dataproc.ETLTest.main(ETLTest.scala)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.security.authentication.util.KerberosUtil.getDefaultRealm(KerberosUtil.java:84)
at org.apache.hadoop.security.HadoopKerberosName.setConfiguration(HadoopKerberosName.java:63)
... 12 more
Caused by: KrbException: Cannot locate default realm
at sun.security.krb5.Config.getDefaultRealm(Config.java:1029)
... 18 more

Process finished with exit code 1

转载于:https://www.cnblogs.com/chwilliam85/p/9693257.html

你可能感兴趣的:(troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm)