2016-09-22 3 views
0

Вот мой код для подключения к HBase с использованием протокола Kerberos:Подключение к керберизованным HBase из Windows: Не удалось указать Kerberos основное имя сервера

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 

The тот же код может успешно работать в Linux, но он всегда проигрывал Windows.

+0

Я нахожу, что он может быть исправлен, когда я кладу core-site.xml и hbase-site.xml в каталог ресурсов. Но я не хочу добавлять эти два файла в свой проект. Поэтому, я думаю, мне нужно установить больше параметров в HBaseConfiguration в Windows. –

+0

Это странно в Windows. Несмотря на то, что я установил те же параметры с помощью Java API с содержимым в core-site.xml и hbase-site.xml, он все равно не удался. Поэтому я должен поместить два xml-файла в свою Windows. –

ответ

1

Просто замените SecurityUtil.login(conf, KEYTAB_KEY, USER_KEY); с

UserGroupInformation.setConfiguration(conf); 
UserGroupInformation.loginUserFromKeytab("USER_KEY", KEYTAB_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!"); 

Если выше код работает успешно, вы можете заменить фиксированные значения с переменными.

 Смежные вопросы

  • Нет связанных вопросов^_^