一.將kerberos相關認證檔案放到專案目錄下:
xxxx.keytab,krb5.conf

二.pom.xml引入包:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.3</version>
</dependency>
三.驗證方法:
private static void authKerberos(Configuration conf) throws IOException {
// kerberos組態檔路徑,
String krb5File = "D:/code/maventest/src/main/resources/local/krb5.conf";
System.setProperty("java.security.krb5.conf", krb5File);
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
// 用戶驗證,第一參是執行用戶,第二參是keytab檔案路徑,
UserGroupInformation.loginUserFromKeytab("dw"
, "D:/code/maventest/src/main/resources/local/dw_host.keytab");
}
public static void main(String[] args) throws IOException {
// 創建組態檔
Configuration conf = new Configuration();
// kerberos認證,如果不需要kerberos可以注掉,我的集群是需要的
authKerberos(conf);
FileSystem fs = FileSystem.get(conf);
}
四.Hadoop怎么連,JAVA API代碼看這個:
【大資料筆記】- Hadoop HDFS API_foxofwind的博客-CSDN博客
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/355240.html
標籤:其他
上一篇:BUUCTF--[GWCTF 2019]re3學習記錄
下一篇:一次授權測驗引起的全域名淪陷
