Jak połączyć się ze zdalnym HBase w Javie?

Mam samodzielny serwer HBase. To moja baza hbase.xml:

<configuration>
 <property>
    <name>hbase.rootdir</name>
    <value>file:///hbase_data</value>
  </property>
</configuration>

Próbuję napisać program Java do manipulowania danymi w HBase.

Jeśli uruchamiam program na serwerze HBase, działa dobrze. Ale nie wiem jak to skonfigurować dla zdalnego dostępu.

  Configuration config = HBaseConfiguration.create();
   HTable table = new HTable(config, "test");
   Scan s = new Scan();

Próbowałem dodać IP i Port, nie działa:

config.set("hbase.master", "146.169.35.28:60000")
Czy ktoś może mi powiedzieć jak to zrobić? Dzięki!
 36
Author: leon, 2011-07-07

5 answers

Oto fragment z systemu, którego używamy do tworzenia tabeli HTable, której używamy do łączenia się z bazą HBase

Configuration hConf = HBaseConfiguration.create(conf);
hConf.set(Constants.HBASE_CONFIGURATION_ZOOKEEPER_QUORUM, hbaseZookeeperQuorum);
hConf.setInt(Constants.HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT, hbaseZookeeperClientPort);

HTable hTable = new HTable(hConf, tableName);

HTH

EDIT: przykładowe wartości:

public static final String HBASE_CONFIGURATION_ZOOKEEPER_QUORUM                     = "hbase.zookeeper.quorum";
public static final String HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT                 = "hbase.zookeeper.property.clientPort";
...
hbaseZookeeperQuorum="PDHadoop1.corp.CompanyName.com,PDHadoop2.corp.CompanyName.com";
hbaseZookeeperClientPort=10000;
tableName="HBaseTableName";
 27
Author: QuinnG,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-21 15:13:12

hbase.master jest @ Deprecated. Klienci używają Zookeeper, aby uzyskać aktualną nazwę hosta / port swoich serwerów HBase.

@Deprecated
config.set("hbase.master", "146.169.35.28:60000")

Hadoop i HBase są bardzo wrażliwe na konfigurację DNS i /etc/hosts. Upewnij się, że Twoja nazwa hosta nie wskazuje na 127.0.0.1, w przeciwnym razie uruchomi wiele usług nasłuchujących tylko na localhost. Staraj się nie używać adresów IP w dowolnym miejscu w Ustawieniach.

Mój /etc/hosts:

192.168.2.3     cloudera-vm     # Added by NetworkManager
127.0.0.1       localhost.localdomain   localhost
127.0.1.1       cloudera-vm-local localhost

/etc/hbase/hbase-site.xml powinien mieć ustawienia set distributed=false (ponieważ używasz tego do testowania tylko):

<property>
  <name>hbase.cluster.distributed</name>
  <value>false</value>
</property>

/etc/zookeeper/zoo.cfg

# the port at which the clients will connect
clientPort=2181
server.0=cloudera-vm:2888:3888

Lista moich procesów Java:

root@cloudera-vm:~# jps
1643 TaskTracker
1305 JobTracker
1544 SecondaryNameNode
2037 Bootstrap
9622 DataNode
10144 Jps
9468 NameNode
1948 RunJar
9746 HMaster
 11
Author: vladaman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-07 05:08:36

W skrócie to jest to, czego używam:

    Configuration hBaseConfig =  HBaseConfiguration.create();
    hBaseConfig.setInt("timeout", 120000);
    hBaseConfig.set("hbase.master", "*" + hbaseHost + ":9000*");
    hBaseConfig.set("hbase.zookeeper.quorum",zookeeperHost);
    hBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");

Dla hBaseHost i zookeeperHost po prostu przekazuję adres ip komputera klastra, który ma zainstalowany zookeeper. Oczywiście możesz też sparametryzować numery portów. Nie jestem w 100% pewien, że jest to najlepszy sposób na zapewnienie udanego połączenia, ale do tej pory działa bez żadnych problemów.

 7
Author: Marquez,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-02 14:44:13

Z tego co wiem, Jeśli chcesz połączyć się ze zdalnym serwerem hbase nie działa zwykły klient Javy, w którym po prostu deklarujemy konfigurację i próbujemy połączyć się ze zdalnym hbase jak wspomniano w precious answers.

Próbowałem tego powyżej rzeczy, ale nigdy nie udało się. Zamiast tego użyłem Thrift API do łączenia się ze zdalnym serwerem,

Ten link jest najlepszym przykładem wykorzystania Javy Thrift API client.It na pewno działa.Używam tego samego. Ale przed użyciem ostrożnie przejrzyj kod i emituj te elementy, których nie potrzebujesz. Podaję również przykładowy kod dla tego samego, który z powodzeniem działa.

public class ThriftClient 
{

    port = 9090;
    //Connection to hbase
    TTransport transport = new TSocket(hostname, port);
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);

    transport.open();

    int z=Link.length();
    byte[] tablename = bytes("YOUR TABLE NAME");

    // Create the demo table with two column families, entry: and unused:
    ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
    ColumnDescriptor col = null;
    col = new ColumnDescriptor();
    col.name = ByteBuffer.wrap(bytes("YOUR_COLUMN_FAMILY_NAME"));
    col.maxVersions = 10;
    columns.add(col);

    System.out.println("creating table: " + utf8(tablename));
    try 
    {
        client.createTable(ByteBuffer.wrap(tablename), columns);
    } 
    catch (AlreadyExists ae) 
    {
        System.out.println("WARN: " + ae.message);
    }

    Map<ByteBuffer, ByteBuffer> dummyAttributes = null;
    boolean writeToWal = false;
    // Test UTF-8 handling
    byte[] invalid = {(byte) 'f', (byte) 'o', (byte) 'o', (byte) '-',
        (byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1};
    byte[] valid = {(byte) 'f', (byte) 'o', (byte) 'o', (byte) '-',
        (byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83,
        (byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3,
        (byte) 0x83, (byte) 0xAB};


    ArrayList<Mutation> mutations;

    // Run some operations on a bunch of rows

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(10);
    nf.setGroupingUsed(false);
    byte[] row=bytes("YOUR ROW NAME");

    mutations = new ArrayList<Mutation>();
    mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("YOUR_COLUMN_FAMILY_NAME:YOUR_COLUMN_NAME")), ByteBuffer.wrap(bytes("YOUR_ROW_VALUE")), writeToWal));
    client.mutateRow(ByteBuffer.wrap(tablename), ByteBuffer.wrap(row), mutations, dummyAttributes);

    transport.close();

    // Helper to translate byte[]'s to UTF8 strings
private static String utf8(byte[] buf) {
    try {
        return decoder.decode(ByteBuffer.wrap(buf)).toString();
    } catch (CharacterCodingException e) {
        return "[INVALID UTF-8]";
    }
}

// Helper to translate strings to UTF8 bytes
private static byte[] bytes(String s) {
    try {
        return s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}
}
 1
Author: ashubhargave,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-04 12:00:42

W moim przypadku po wielu grach z /etc / hosts znalazłem w pliku dziennika "hbase-bgi-master-servername.log " następujący wiersz:

"2017-11-21 19:56:32,999 INFO [RS:0;servername: 45553] regionserver.HRegionServer: służy jako nazwa serwera.lokalne.lan,45553,1511290584538, RpcServer on servername.lokalne.lan/172.0.1.2:45553, sessionid=0x15fdff039790002"

Zawsze upewnij się, że pełna nazwa hosta ("servername.lokalne.lan" w moim przypadku) faktycznie wskazuje na IP serwera zarówno po stronie klienta jak i serwera.

 0
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-21 17:05:41