java development can not connect hbase Master Service

It is a problem for a long time, know the hosts cause, that is, change to change to change the wrong piece of information is relatively small, so hope to have issued encounter can refer to.

First check linux server / etc / hostname configuration file, the / etc / hosts file 127.0.0.1 localhost commented, change ip hostname. Finished processing on the server side

windows client modifies the hosts for the linux server ip linux server hostname (domain name to be mapped)

Start hbase, browser access to view the master address, before my master address 127.0.0.1 has been or localhost, so not visit, by the configuration described above, master address is the hostname, the following test code can be measured through.


The following is the client test code:

public static void main(String[] args) throws IOException {

                Configuration conf = new Configuration();  
conf.set ( "hbase.zookeeper.quorum", "hostname "); // this sentence is very important, this relationship can not be connected to HBase
HBaseConfiguration  cfg = new new HBaseConfiguration (conf); 

                String tablename = "test";
String[] columns = new String[] { "id", "age", "name" };
HBaseAdmin admin = new HBaseAdmin(cfg);

if (admin.tableExists(tablename)) {
System.out.println ( "table already exists");
} else {
HTableDescriptor tableDesc = new HTableDescriptor(tablename);
for (int i = 0; i < columns.length; i++) {
tableDesc.addFamily(new HColumnDescriptor(columns[i]));
}
admin.createTable(tableDesc);
System.out.println ( "create table success!.");
}
}


Released seven original articles · won praise 2 · Views 5167

Guess you like

Origin blog.csdn.net/u010715243/article/details/53484144