一. 安装docker单机hbase
docker pull harisekhon/hbase
docker run -d -h hadoop100 -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 --name hbase docker.io/harisekhon/hbase
二. 现状
- 连接可以通过,但是java-api无法读写hbase数据
- 持续连接
org.apache.hbase.thirdparty.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information
三. 解决
排查了一下午人都晕了......
没有对外暴露 16020端口
docker run -d -h hadoop100 -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 16020:16020 -p 16301:16301 --name hbase docker.io/harisekhon/hbase
其他问题参考:Java API远程连接服务器hbase报错:Connection refused: no further information: localhost/127.0.0.1:16000
四. 测试
读
public class Hbase_demo2 {
public static void main(String[] args) throws IOException {
System.setProperty("hadoop.home.dir", "F:\\hadoop\\hadoop-2.2.0-bin-master");
Connection hbaseConnection = ConnectionUtils.getHbaseConnection();
System.out.println("------");
Table table = hbaseConnection.getTable(TableName.valueOf("profile"));
System.out.println(table);
//Scan所有数据
Scan scan = new Scan();
ResultScanner rss = table.getScanner(scan);
System.out.println(rss);
for (Result r : rss) {
System.out.println("----");
System.out.println("\n row: " + new String(r.getRow()));
}
}
}
写
public class UserProfileDataGen {
public static void main(String[] args) throws IOException {
System.setProperty("hadoop.home.dir", "F:\\hadoop\\hadoop-2.2.0-bin-master");
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum", "192.168.10.100:2181");
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf("profile_test"));
ArrayList<Put> puts = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
// 生成一个用户的画像标签数据
String deviceId = StringUtils.leftPad(i + "", 6, "0");
Put put = new Put(Bytes.toBytes(deviceId));
for (int k = 1; k <= 100; k++) {
String key = "tag" + k;
String value = "v" + RandomUtils.nextInt(1, 3);
put.addColumn(Bytes.toBytes("f"), Bytes.toBytes(key), Bytes.toBytes(value));
}
// 将这一条画像数据,添加到list中
puts.add(put);
// 攒满100条一批
if(puts.size()==100) {
table.put(puts);
puts.clear();
}
}
// 提交最后一批
if(puts.size()>0) table.put(puts);
conn.close();
}
}
五. 待解决
- 虚拟机挂起,重启,hbase无法连接的问题
网友评论