2016-09-22 1 views
0

サーバーのKerberosプリンシパル名を指定することができませんでした:は:Kerberosを使用してのHBaseに接続するために私のコードです。ここ

Configuration conf = HBaseConfiguration.create(); 

conf.set("hbase.zookeeper.quorum", "20.20.100.1"); 
conf.set("hbase.zookeeper.property.clientPort", "2181"); 

final String USER_KEY = "appuser.principal"; 
final String KEYTAB_KEY = "appuser.keytab.filename"; 
final String Key_user = Config.getProperties().getString("kerberos_keyuser"); 
final String Key_tab = Config.getProperties().getString("kerberos_keytab"); 
conf.set("hadoop.security.authentication", "kerberos"); 
conf.set("hbase.security.authentication", "kerberos"); 
conf.set(USER_KEY, Key_user); 
conf.set(KEYTAB_KEY, Key_tab); 
SecurityUtil.login(conf, KEYTAB_KEY, USER_KEY); 


Connection connection = ConnectionFactory.createConnection(conf); 
try (Table table = connection.getTable(TableName.valueOf("newssentiment:test"))) { 
    Scan scan = new Scan(); 
    ResultScanner scanner = table.getScanner(scan); 
    Iterator<Result> iterator = scanner.iterator(); 
    System.out.println(); 
    while(iterator.hasNext()) { 
     System.out.println(iterator.next()); 
    } 
} 
catch (Exception e){ 
    System.out.print(e.getMessage()); 
} 


HBaseAdmin.checkHBaseAvailable(conf); 
connection.close(); 
System.out.println("HBase is running!"); 

しかし、私は次のエラーを取得:

org.apache.hadoop.security.UserGroupInformation - PriviledgedActionException as:u8000 (auth:SIMPLE) cause:java.io.IOException: Failed to specify server's Kerberos principal name 
org.apache.hadoop.hbase.ipc.AbstractRpcClient - Exception encountered while connecting to the server : java.io.IOException: Failed to specify server's Kerberos principal name 
org.apache.hadoop.security.UserGroupInformation - PriviledgedActionException as:u8000 (auth:SIMPLE) cause:java.io.IOException: java.io.IOException: Failed to specify server's Kerberos principal name 

同じコードをLinux上で正常に実行することはできますが、Windowsでは常に失敗します。

+0

core-site.xmlとhbase-site.xmlをresourcesディレクトリに置くと修正できることがわかりました。しかし、私はこれらの2つのファイルをプロジェクトに追加したくありません。だから、私はWindows上でHBaseConfigurationでより多くのパラメータを設定する必要があると思う。 –

+0

これはWindows上では奇妙です。 core-site.xmlとhbase-site.xmlの内容でJava APIを使用して同じパラメータを設定しても、それでも失敗しました。だから私は2つのxmlファイルを私のWindowsに置かなければならない。 –

答えて

1

だけで簡単にするために

UserGroupInformation.setConfiguration(conf); 
UserGroupInformation.loginUserFromKeytab("USER_KEY", KEYTAB_KEY); 

SecurityUtil.login(conf, KEYTAB_KEY, USER_KEY);を交換するには、以下のようにコードを書くことができます:上記のコードは正常に実行され

Configuration conf = HBaseConfiguration.create(); 

conf.addResource(new Path("D:\\core-site.xml"); 
conf.addResource(new Path("D:\\hbase-site.xml"); 

System.setProperty("java.security.krb5.conf", "D:\\krb5.conf"); 
// give the path of krb5.conf file 

UserGroupInformation.setConfiguration(conf); 
UserGroupInformation.loginUserFromKeytab("[email protected]", "D:\\farooque.keytab"); 
// [email protected] is the principal name, give the path of keytab file 


Connection connection = ConnectionFactory.createConnection(conf); 
try (Table table = connection.getTable(TableName.valueOf("newssentiment:test"))) { 
    Scan scan = new Scan(); 
    ResultScanner scanner = table.getScanner(scan); 
    Iterator<Result> iterator = scanner.iterator(); 
    System.out.println(); 
    while(iterator.hasNext()) { 
     System.out.println(iterator.next()); 
    } 
} 
catch (Exception e){ 
    System.out.print(e.getMessage()); 
} 


HBaseAdmin.checkHBaseAvailable(conf); 
connection.close(); 
System.out.println("HBase is running!"); 

場合は、変数を固定値に置き換えることができます。

関連する問題