Java连接HBase问题

qq_22884313 2017-05-16 10:28:48
我用windows上的maven工程连接虚拟机上的hbase时报错
Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
看网上有人说这个问题是配置问题 我已经把HBase集群的主机名和ip都加到hosts里面了 还是没有作用 以下是hbase-site 和core-site的配置 跪求大神帮忙啊


...全文
435 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_22884313 2017-05-16
  • 打赏
  • 举报
回复
引用 3 楼 qq_30831935 的回复:
Configuration config = HBaseConfiguration.create(); config .set("hbase.zookeeper.quorum", zookeeper地址) 我用的0.96版本 是要在config里set一下zookeeper的地址
这个在1.2.5的版本不行
鱿鱼ing 2017-05-16
  • 打赏
  • 举报
回复
Configuration config = HBaseConfiguration.create(); config .set("hbase.zookeeper.quorum", zookeeper地址) 我用的0.96版本 是要在config里set一下zookeeper的地址
qq_22884313 2017-05-16
  • 打赏
  • 举报
回复
引用 1 楼 qq_30831935 的回复:
贴操作hbase的代码看看 configuration.set("hbase.zookeeper.quorum", zookeeper地址)
package com.qu; /** * Created by 野象 on 2017/5/16. */ import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; public class Example { private static final String TABLE_NAME = "MY_TABLE_NAME_TOO"; private static final String CF_DEFAULT = "DEFAULT_COLUMN_FAMILY"; public static void createOrOverwrite(Admin admin, HTableDescriptor table) throws IOException { if (admin.tableExists(table.getTableName())) { admin.disableTable(table.getTableName()); admin.deleteTable(table.getTableName()); } admin.createTable(table); } public static void createSchemaTables(Configuration config) throws IOException { try (Connection connection = ConnectionFactory.createConnection(config); Admin admin = connection.getAdmin()) { HTableDescriptor table = new HTableDescriptor(TableName.valueOf(TABLE_NAME)); table.addFamily(new HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.NONE)); System.out.print("Creating table. "); createOrOverwrite(admin, table); System.out.println(" Done."); } } public static void modifySchema (Configuration config) throws IOException { try (Connection connection = ConnectionFactory.createConnection(config); Admin admin = connection.getAdmin()) { TableName tableName = TableName.valueOf(TABLE_NAME); if (!admin.tableExists(tableName)) { System.out.println("Table does not exist."); System.exit(-1); } HTableDescriptor table = admin.getTableDescriptor(tableName); // Update existing table HColumnDescriptor newColumn = new HColumnDescriptor("NEWCF"); newColumn.setCompactionCompressionType(Algorithm.GZ); newColumn.setMaxVersions(HConstants.ALL_VERSIONS); admin.addColumn(tableName, newColumn); // Update existing column family HColumnDescriptor existingColumn = new HColumnDescriptor(CF_DEFAULT); existingColumn.setCompactionCompressionType(Algorithm.GZ); existingColumn.setMaxVersions(HConstants.ALL_VERSIONS); table.modifyFamily(existingColumn); admin.modifyTable(tableName, table); // Disable an existing table admin.disableTable(tableName); // Delete an existing column family admin.deleteColumn(tableName, CF_DEFAULT.getBytes("UTF-8")); // Delete a table (Need to be disabled first) admin.deleteTable(tableName); } } public static void main(String... args) throws IOException { Configuration config = HBaseConfiguration.create(); //Add any necessary configuration files (hbase-site.xml, core-site.xml) // config.addResource(new Path(System.getenv("HBASE_CONF_DIR"), "hbase-site.xml")); // config.addResource(new Path(System.getenv("HADOOP_CONF_DIR"), "core-site.xml")); config.addResource(new Path("E:\\workplaceidea\\mvnstudy\\conf\\hbase-site.xml")); config.addResource(new Path("E:\\workplaceidea\\mvnstudy\\conf\\core-site.xml")); createSchemaTables(config); modifySchema(config); } } 我是在官网上看到这段代码的 因为用的HBase版本是1.2.5 所以好像跟之前的版本写代码有点不一样
鱿鱼ing 2017-05-16
  • 打赏
  • 举报
回复
贴操作hbase的代码看看 configuration.set("hbase.zookeeper.quorum", zookeeper地址)

20,808

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧