docker创建MySQl容器

启动mysql的dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
version: '3'
services:
hk-mysql:
container_name: hk-mysql
image: mysql/mysql-server:5.7
environment:
MYSQL_DATABASE: testdb
MYSQL_ROOT_PASSWORD: hellokoding
MYSQL_ROOT_HOST: '%'
ports:
- "3306:3306"
restart: always

启动hbase

docker run -d -h myhbase -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 hbase1.3 harisekhon/hbase –net=host

参考 https://github.com/tanwenliang/spring-boot-hbase-example

这样启动的话没有nginx,每个单独的容器是相互分离的。

问题记录

这一块的问题属于运维的,无需太关心这个问题。

hbase容器启动后,ip地址无法ping通
导致springboot无法连接 hbase,控制台提示错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2019-09-04 13:32:37.240 INFO 57045 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-09-04 13:32:37.254 INFO 57045 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn : Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x16cfab6764d0007, negotiated timeout = 90000
2019-09-04 13:32:38.099 INFO 57045 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Ma


2019-09-04 13:42:32.376 INFO 57045 --- [ared--pool2-t10] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=10, retries=35, started=38320 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:42:42.388 INFO 57045 --- [ared--pool2-t10] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=11, retries=35, started=48332 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:43:30.859 INFO 57045 --- [ared--pool2-t11] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=10, retries=35, started=38399 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:43:40.930 INFO 57045 --- [ared--pool2-t11] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=11, retries=35, started=48470 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:44:29.359 INFO 57045 --- [ared--pool2-t12] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=10, retries=35, started=38405 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:44:39.461 INFO 57045 --- [ared--pool2-t12] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=11, retries=35, started=48507 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0
2019-09-04 13:45:38.022 INFO 57045 --- [ared--pool2-t13] o.a.h.hbase.client.RpcRetryingCaller : Call exception, tries=10, retries=35, started=38380 ms ago, cancelled=false, msg=Connection refused row 'h_file,1000000000000000,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=myhbase,16020,1567574361014, seqNum=0

正确的hbase配置

package com.example.config;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.; import org.apache.hadoop.hbase.client.; import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

/**

  • @author allen

  • / @org.springframework.context.annotation.Configuration
    public class Hbase {
    @Bean
    public Connection getHbaseConnect() throws IOException {

    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "myhbase");
    conf.set("hbase.zookeeper.property.clientPort", "2181");
    conf.set("log4j.logger.org.apache.hadoop.hbase", "WARN");
    Connection connection = ConnectionFactory.createConnection(conf);
    return connection;

    }

    @Bean
    public Admin getHbaseAdmin(Connection connection) throws IOException{

    Admin admin = connection.getAdmin();
    return admin;

    }

}