java能否實現訪問kerberos和simple安全級別的兩個叢集
阿新 • • 發佈:2018-12-11
走過路過的java/hadoop大神,幫忙給看看。現在我的java程式,需要同時實現對多個叢集的讀寫,這些叢集分別由kerberos和simple這樣不同的安全級別,我是在方法中用分支實現的,但是訪問時,總是會出現互相影響的情況,基本有兩種異常。
如果simple叢集訪問成功,kerberos叢集會失敗,異常資訊:
org.apache.hadoop.security.AccessControlException: SIMPLE authentication is not enabled. Available:[TOKEN, KERBEROS]
如果kerberos叢集訪問成功,simple叢集會失敗,異常資訊:
server asks to fall back to simple auth but this client is configured to only allow secure connections
我連線的java程式碼如下:
import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; public FileSystem getHdfsStream(Boolean iskerberos, uri) { Configuration conf = new Configuration(); if (iskerberos) { System.setProperty("java.security.krb5.conf", "D:\\krb5.conf"); conf.set("hadoop.security.authentication", "kerberos"); conf.set("hadoop.security.authorization", true); try { UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab(USER_KEY, KEY_TAB_PATH); FileSystem fs = FileSystem.get(URI.create(uri), conf); return fs; } catch (IOException e) { e.printStackTrace(); } } else { UserGroupInformation.setConfiguration(conf); FileSystem fs = FileSystem.get(URI.create(uri), conf); return fs; } return null; }
最近被這個問題困擾了很久,一直沒找到解決辦法。還煩請給指點一二!