赞
踩
docker pull harisekhon/hbase:1.3
docker run -d -h hbaseTag -p 2181:2181 -p 8080:8080 -p 8085:8085 -p 9090:9090 -p 9095:9095 -p 16000:16000 -p 16010:16010 -p 16201:16201 -p 16301:16301 -p 16020:16020 -p 16030:16303 --name hbase1.3 harisekhon/hbase:1.3
sudo vi /etc/hosts
添加: 服务器IP hostname
C:\Windows\System32\drivers\etc
添加: 服务器IP hostname
进入hbase容器
docker exec -it 容器id bash
cd /hbase/conf
vi habse-env.sh
# 释放128行 使用zk,true为使用HBase自带的zk
export HBASE_MANAGES_ZK=true
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.client.*; import java.io.IOException; //连接有问题优先排查host、端口 public class Test { public static Configuration configuration; // 管理Hbase的配置信息 public static Connection connection; // 管理Hbase连接 public static Admin admin; // 管理Hbase数据库的信息 public static void main(String[] args) throws IOException { // TODO Auto-generated method stub System.out.println("shit"); init(); String colF[] = {"score"}; createTable("stu41", colF); insertData("stu41", "zhangsan", "score", "English", "69"); insertData("stu41", "lisi", "score", "English", "69"); getData("stu41", "zhangsan", "score", "English"); close(); } public static void init() { configuration = HBaseConfiguration.create(); configuration.set("hbase.zookeeper.quorum", "服务器ip"); configuration.set("hbase.zookeeper.property.clientPort", "2181"); try { connection = ConnectionFactory.createConnection(configuration); admin = connection.getAdmin(); } catch (IOException e) { e.printStackTrace(); } } public static void createTable(String myTableName, String[] colFamily) throws IOException { TableName tableName = TableName.valueOf(myTableName); boolean b = admin.tableExists(tableName); if (admin.tableExists(tableName)) { System.out.println("Table exists"); } else { HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName); for (String str : colFamily) { HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(str); hTableDescriptor.addFamily(hColumnDescriptor); } admin.createTable(hTableDescriptor); } } // 添加单元格数据 /* * @param tableName 表名 * @param rowKey 行键 * @param colFamily 列族 * @param col 列限定符 * @param val 数据 * @thorws Exception * */ public static void insertData(String tableName, String rowKey, String colFamily, String col, String val) throws IOException { Table table = connection.getTable(TableName.valueOf(tableName)); Put put = new Put(rowKey.getBytes()); put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes()); table.put(put); table.close(); } //浏览数据 /* * @param tableName 表名 * @param rowKey 行 * @param colFamily 列族 * @param col 列限定符 * @throw IOException * */ public static void getData(String tableName, String rowKey, String colFamily, String col) throws IOException { Table table = connection.getTable(TableName.valueOf(tableName)); Get get = new Get(rowKey.getBytes()); get.addColumn(colFamily.getBytes(), col.getBytes()); Result result = table.get(get); System.out.println(new String(result.getValue(colFamily.getBytes(), col == null ? null : col.getBytes()))); table.close(); } // 操作数据库之后,关闭连接 public static void close() { try { if (admin != null) { admin.close(); // 退出用户 } if (null != connection) { connection.close(); // 关闭连接 } } catch (IOException e) { e.printStackTrace(); } } //删除表 public static void deleteTable(String tableName) { try { TableName tablename = TableName.valueOf(tableName); admin = connection.getAdmin(); admin.disableTable(tablename); admin.deleteTable(tablename); } catch (IOException e) { e.printStackTrace(); } } }
<--依赖-->
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.4.13</version>
</dependency>
需要把驱动放在C盘用户目录下的 .hbase-gui-conf 例:C:\Users\56594.hbase-gui-conf
https://gitee.com/youxuehu/HbaseGUI?_from=gitee_search
软件、驱动下载
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。