目前是根據platform選擇使用不同的集群配置連接到不同的集群
public Configuration getConf(int platform) throws IOException {
if (platform == 1 || platform == 3) {
return initConfiguration(A_CLUSTER_CONFIG_PATH);
} else {
return initConfiguration(B_CLUSTER_CONFIG_PATH);
}
}
private Configuration initConfiguration(String clusterConfigPath) {
System.setProperty("java.security.krb5.conf", clusterConfigPath + "krb5.conf");
conf = new Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
conf.addResource(new Path(clusterConfigPath + "core-site.xml"));
conf.addResource(new Path(clusterConfigPath + "hdfs-site.xml"));
conf.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
conf.setBoolean("fs.hdfs.impl.disable.cache", true);
kerberosAuthentication(conf, clusterConfigPath + "hiveConfig.properties", clusterConfigPath + "bd_user.keytab");
return conf;
}
private void kerberosAuthentication(Configuration conf, String propPath, String keytabPath) {
try {
UserGroupInformation.setConfiguration(conf);
PropertiesUtil.loadFromFileSystem(propPath);
UserGroupInformation.loginUserFromKeytab(PropertiesUtil.getString("hadoop.kerberos.principal"), keytabPath);
} catch (IOException e) {
LogBetter.instance(LOGGER).setLevel(LogLevel.ERROR).setMsg("[ClusterConnectionManager]:Hadoop認證失敗").setException(e).log();
}
}
但是實際的情況是只能連接到一個集群,另外一個集群一直認證失敗
uj5u.com熱心網友回復:
集群a(可以連接),集群b(不能連接)運行代碼的主機C,C的/etc/krb5.conf中的default_realm 與代碼用到的A的krb5.conf一樣,與B不一樣?
uj5u.com熱心網友回復:
大佬,解決了嗎?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/225631.html
標籤:Web 開發
上一篇:如何成為Java技術牛人
