hdfs inotify和kerberos身份验证

3htmauhk  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(469)

我使用的是来自internet的示例:hdfs inotify示例,构建完成时没有错误,但执行结束时有错误:

Exception in thread "main" org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): SIMPLE authentication is not enabled.  Available:[TOKEN, KERBEROS]

kerberos系统正在工作,我有一个新的kerberos票证,它工作得非常好。所以我不确定这是否是kerberos的问题。我还设置了以下环境变量:

export HADOOP_CONF_DIR=/etc/hadoop/conf

指向core-site.xml,其中安全设置afaik是正确的:

<property>
    <name>hadoop.security.authentication</name>
  <value>kerberos</value>
  </property>
  <property>
     <name>hadoop.security.authorization</name>
  <value>true</value>
  </property>
  <property>
     <name>hadoop.rpc.protection</name>
  <value>authentication</value>
 </property>

怎么了?每一个建议都很感激。
我使用的是hadoop2.6.0-cdh5.10.1

ecfsfe2w

ecfsfe2w1#

最后,我找到了解决问题的方法:
这是我添加到hdfs inotify示例中的补丁

diff --git a/src/main/java/com/onefoursix/HdfsINotifyExample.java b/src/main/java/com/onefoursix/HdfsINotifyExample.java
index 97ac409..32321b1 100644
--- a/src/main/java/com/onefoursix/HdfsINotifyExample.java
+++ b/src/main/java/com/onefoursix/HdfsINotifyExample.java
@@ -11,6 +11,7 @@ import org.apache.hadoop.hdfs.inotify.Event.CreateEvent;
 import org.apache.hadoop.hdfs.inotify.Event.UnlinkEvent;
 import org.apache.hadoop.hdfs.inotify.EventBatch;
 import org.apache.hadoop.hdfs.inotify.MissingEventsException;
+import org.apache.hadoop.security.UserGroupInformation;

 public class HdfsINotifyExample {

@@ -21,10 +22,20 @@ public class HdfsINotifyExample {
                if (args.length > 1) {
                        lastReadTxid = Long.parseLong(args[1]);
                }
-
+        
+                System.out.println("com.onefoursix.HdfsINotifyExample.main()");
                System.out.println("lastReadTxid = " + lastReadTxid);
-
-               HdfsAdmin admin = new HdfsAdmin(URI.create(args[0]), new Configuration());
+                Configuration config = new Configuration();
+                
+                config.set("hadoop.security.authentication", "kerberos");
+                config.set("hadoop.security.authorization", "true");
+                config.set("dfs.namenode.kerberos.principal", "hdfs/_HOST@AD.XXXXX.COM");
+                config.set("dfs.namenode.kerberos.principal.pattern", "hdfs/*@AD.XXXXX.COM");
+                
+                UserGroupInformation.setConfiguration(config);
+                System.out.println("Security enabled " + UserGroupInformation.isSecurityEnabled());
+                
+               HdfsAdmin admin = new HdfsAdmin(URI.create(args[0]), config);

                DFSInotifyEventInputStream eventStream = admin.getInotifyEventStream(lastReadTxid);

认证工作正常。最后我得到:

Exception in thread "main" org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.AccessControlException): Access denied for user xxxxxxxx. Superuser privilege is required

这意味着当前用户无法看到datanode中发生的事情,但这是另一个历史。

2w3kk1z5

2w3kk1z52#

补充ozw1z5rd的答案:
请登录超级用户(hdfs)并在那里执行程序。

$ sudo -i -u hdfs
$ cp shaded-fat-jar.jar /home/hdfs

并运行从jar文件复制到hdfs home的程序。

相关问题