HBase Docker环境搭建

获取docker-compse文件

docker脚本可以从链接获取

修改docker-compse.xml文件,注意端口映射

version: "2"
services:

  zookeeper-1:
    container_name: zookeeper-1
    networks: ["vnet"]
    hostname: zookeeper-1.vnet
    image: smizy/zookeeper:3.4-alpine
    ports:  ["2181:2181"]
    environment:
      - SERVICE_2181_NAME=zookeeper
      - SERVICE_2888_IGNORE=true
      - SERVICE_3888_IGNORE=true

    command: -server 1 1 vnet

  namenode-1:
    container_name: namenode-1
    networks: ["vnet"]
    hostname: namenode-1.vnet
    image: smizy/hadoop-base:2.7.6-alpine
    expose: ["8020"]
    ports:  ["50070:50070","8020:8020"]
    environment:
      - SERVICE_8020_NAME=namenode
      - SERVICE_50070_IGNORE=true
      - HADOOP_ZOOKEEPER_QUORUM=zookeeper-1.vnet:2181
      - HADOOP_HEAPSIZE=1000
      - HADOOP_NAMENODE_HA=

    entrypoint: entrypoint.sh
    command: namenode-1

  datanode-1:
    container_name: datanode-1
    networks: ["vnet"]
    hostname: datanode-1.vnet
    image: smizy/hadoop-base:2.7.6-alpine
    expose: ["50010", "50020", "50075"]
    environment:
      - SERVICE_50010_NAME=datanode
      - SERVICE_50020_IGNORE=true
      - SERVICE_50075_IGNORE=true
      - HADOOP_ZOOKEEPER_QUORUM=zookeeper-1.vnet:2181
      - HADOOP_HEAPSIZE=1000
      - HADOOP_NAMENODE_HA=

    entrypoint: entrypoint.sh
    command: datanode

  hmaster-1:
    container_name: hmaster-1
    networks: ["vnet"]
    hostname: hmaster-1.vnet
    image: smizy/hbase:1.2.6.1-alpine
    expose: [16000]
    ports:  ["16010:16010","16000:16000"]
    depends_on: ["zookeeper-1"]
    environment:
      - SERVICE_16000_NAME=hmaster
      - SERVICE_16010_IGNORE=true
      - HBASE_ZOOKEEPER_QUORUM=zookeeper-1.vnet:2181

    volumes_from:
      - namenode-1
    command: hmaster-1

  regionserver-1:
    container_name: regionserver-1
    networks: ["vnet"]
    hostname: regionserver-1.vnet
    image: smizy/hbase:1.2.6.1-alpine
    expose: [16020, 16030]
    ports: ["16020:16020", "16030:16030"]
    depends_on: ["zookeeper-1"]
    environment:
      - SERVICE_16020_NAME=regionserver
      - SERVICE_16030_IGNORE=true
      - HBASE_ZOOKEEPER_QUORUM=zookeeper-1.vnet:2181

    command: regionserver

networks:
  vnet:
    external:
      name: vnet

运行Hadoop和Hbase

# docker-machine default
docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox default

# load default env as needed
eval $(docker-machine env default)

# network
docker network create vnet

# make docker-compose.yml with small size (no redudency)
zookeeper=1 namenode=1 datanode=1 ./make_docker_compose_yml.sh hdfs hbase > docker-compose.yml

# or with default size(zookeeper=3, namenode=2, journalnode=3, datanode=3, hmaster=2, regionserver=3)
./make_docker_compose_yml.sh hdfs hbase > docker-compose.yml

# hadoop+hbase startup
docker-compose up -d

# tail logs for a while
docker-compose logs -f

# check ps
docker-compose ps

     Name                   Command               State                  Ports
---------------------------------------------------------------------------------------------
datanode-1       entrypoint.sh datanode           Up      50010/tcp, 50020/tcp, 50075/tcp
hmaster-1        entrypoint.sh hmaster-1          Up      16000/tcp, 0.0.0.0:32771->16010/tcp
namenode-1       entrypoint.sh namenode-1         Up      0.0.0.0:32770->50070/tcp, 8020/tcp
regionserver-1   entrypoint.sh regionserver       Up      16020/tcp, 16030/tcp
zookeeper-1      entrypoint.sh -server 1 1 vnet   Up      2181/tcp, 2888/tcp, 3888/tcp

# check stats
docker ps --format {{.Names}} | xargs docker stats

# hbase shell
docker exec -it -u hbase regionserver-1 hbase shell
hbase(main):001:0> create 'test', 'cf'
hbase(main):002:0> list 'test'
hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
hbase(main):006:0> scan 'test'
hbase(main):007:0> get 'test', 'row1'
hbase(main):008:0> disable 'test'
hbase(main):009:0> drop 'test'
hbase(main):010:0> exit

# hadoop/hbase shutdown
docker-compose stop

# cleanup container
docker-compose rm -v
文章目录
  1. 获取docker-compse文件
  2. 运行Hadoop和Hbase