1. 程式人生 > >hadoop 使用eclipse plugin執行存在許可權讀寫問題

hadoop 使用eclipse plugin執行存在許可權讀寫問題

在開發過程中使用1.1.2在eclipse中執行,出現

org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.security.AccessControlException: Permission denied: user=admin, access=WRITE, inode="example":root:supergroup:rwxr-xr-x

在之前使用的0.20.2版本中,我修改hadoop.job.ugi的引數即可解決,而在1.1.2中,怎麼也找不到該屬性,查詢各方資料之後,得出如下幾種解決方案:

1、修改dfs.permissions 引數值為false

2、通過hadoop fs -chown 777修改檔案的許可權。

但是上面兩種方法,我都不認為是好的解決方案,因為它需要修改hadoop本身的配置資訊和安全級別。

在我的堅持不懈之下,終於找到我認為最合情理的一種方案:使用hadoop提供的UserGroupInformation類。

該類存在兩種解決方式,一種是使用遠端使用者,即

UserGroupInformation info = UserGroupInformation.createRemoteUser("hadoop");
info.doAs(new PrivilegedAction(){....});

使用這種方式就是制定hadoop為當前執行的遠端賬戶,即解決了上述問題。

同時系統會產生另外一個許可權問題,它與mapred有關,我們需要在configuration中設定如下屬性即可:

conf.set("mapred.job.tracker","server:2000");

另外一種,就是利用UserGroupInformation加上之前hadoop提供的一個開源包oozie

UserGroupInformation info = UserGroupInformation.createProxyUser(user,UserGroupInformation.getLoginUser());
info.doAs(.....);

從上述程式碼可以看出,他需要使用一個代理,所以需要配置如下配置資訊:
<property>
<name>hadoop.proxyuser.oozie.groups</name>
<value>group1,group2</value>
Secure Impersonation using UserGroupInformation.doAs
Page 2
Copyright © 2008 The Apache Software Foundation. All rights reserved.<description>Allow the superuser oozie to impersonate any
members of the group group1 and group2</description>
</property>
<property>
<name>hadoop.proxyuser.oozie.hosts</name>
<value>host1,host2</value>
<description>The superuser can connect only from host1 and
host2 to impersonate a user</description>
</property>
該方法更多請參考:http://archive.cloudera.com/cdh/3/hadoop/Secure_Impersonation.pdf