前言:本文主要讲述了如何使用Docker快速上手HBase,省去繁杂的安装部署环境,直接上手,小白必备。适合HBase入门学习及简单代码测试。html
参考地址:java
https://yeasy.gitbook.io/docker_practice/install
支持经常使用的操做系统:Centos / ubuntu / Windows / macos 等。node
镜像地址:git
https://hub.docker.com/r/harisekhon/hbase/tags
这里推荐使用harisekho
,支持多个版本(最新支持HBase2.1.3
),star数也最多,你们也能够在镜像库中搜索其余镜像。github
如下前提:第一步Docker安装完成。web
docker pull harisekhon/hbase:latest
docker pull harisekhon/hbase:1.4
Docker安装成功后,直接运行如下命令。docker
docker run -d -h docker-hbase \ -p 2181:2181 \ -p 8080:8080 \ -p 8085:8085 \ -p 9090:9090 \ -p 9000:9000 \ -p 9095:9095 \ -p 16000:16000 \ -p 16010:16010 \ -p 16201:16201 \ -p 16301:16301 \ -p 16020:16020\ --name hbase \ harisekhon/hbase
配置服务器hosts文件,添加以下配置:shell
127.0.0.1 docker-hbase
配置本地hosts文件,添加以下配置:macos
服务器ip docker-hbase
http://docker-hbase:16010/master-status
查看正在运行的容器:apache
docker ps
找到容器id,进入容器:
docker exec -it <container ID前缀> bash
访问HBase Shell,进入容器后直接输入:
bash-4.4# hbase shell 2020-05-20 03:59:26,228 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable HBase Shell Use "help" to get list of supported commands. Use "exit" to quit this interactive shell. For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell Version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019 Took 0.0049 seconds hbase(main):001:0>
Shell 测试:
hbase(main):001:0> create 'test-docker','f' Created table test-docker Took 1.4964 seconds => Hbase::Table - test-docker hbase(main):002:0> list TABLE test-docker 3 row(s) Took 0.0281 seconds => ["test-docker"] hbase(main):003:0>
输入exit
退出容器。并执行如下命令进入zk:
bash-4.4# hbase zkcli
查看zk节点:
ls / [zookeeper, hbase]
public class HBaseHelper { public static String ZK_QUORUM = "docker-hbase"; public static String ZK_ZNODE = "/hbase"; public static String ZK_PORT = "2181"; public static String SUPER_USER = "hbase"; // 配置链接信息 public Configuration getConfiguration() { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", ZK_QUORUM); conf.set("zookeeper.znode.parent", ZK_ZNODE); conf.set("hbase.zookeeper.property.clientPort", ZK_PORT); return conf; } ... ... ... }
想查看完整Demo代码能够访问Github地址:
https://github.com/zhoupengbo/demos-bigdata/tree/master/hbase/hbase-docker-demo
转载请注明出处!欢迎关注本人微信公众号【HBase工做笔记】