前言:本文主要講述瞭如何使用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工做筆記】