关于分布式:分布式-DBLE-docker-部署遇到的简单问题修复过程

1次阅读

共计 4422 个字符,预计需要花费 12 分钟才能阅读完成。

作者:杨涛涛

资深数据库专家,专研 MySQL 十余年。善于 MySQL、PostgreSQL、MongoDB 等开源数据库相干的备份复原、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相干技术支持、MySQL 相干课程培训等工作。

本文起源:原创投稿

* 爱可生开源社区出品,原创内容未经受权不得随便应用,转载请分割小编并注明起源。


首先阐明如果齐全依照官网文档来操作,必定是没有问题的,DBLE 官网文档曾经写的很具体了。

刚好我环境中有最新的 MySQL docker 镜像(MySQL 8.0.29),我偷懒把 DBLE 后盾 MySQL 版本换成 8.0.29,子网换成 172.20.0.0/16(我本机已有其余 docker 容器占用默认子网运行)。

装完 DBLE 后,呈现了两个小问题:
  1. 因为 IP 地址和 DOCKER 镜像打包的配置不一样,后续的初始化也就没胜利。
  2. 在批改完 IP 地址后,一个逻辑库提醒管理员没有权限创立。
那接下来咱们来修复这两个小问题。
  1. 先拉下来 DBLE 最新版本。
   root@ytt-large:/home/ytt# docker image ls | grep -E '^action|^mysql'
   mysql                8.0.29    b2500a44757f   8 days ago     524MB
   actiontech/dble      latest    9988614a8e4b   6 months ago   755MB
  1. 创立 docker 网络环境,买通后盾 MySQL 和 DBLE。
   root@ytt-large:/home/ytt# docker network create \
   >  -o "com.docker.network.bridge.name"="dble-net" \
   >   --subnet 172.20.0.0/16 dble-net
   360a9408c35cd8b8d49ad2e58ca447d5518dbea2d954badc0e618ad5d0c072a1
  1. 创立两个后端 MySQL 服务,版本为 MySQL 8.0.29,映射端口 3306 别离为 33061、33062。
root@ytt-large:/home/ytt# docker run --name backend-mysql1 \

>  --ip 172.20.0.2 -e MYSQL_ROOT_PASSWORD=123456  \
>  -p 33061:3306 --network=dble-net  \
>  -d mysql:8.0.29 --server-id=1
54505aeca71ae7c4553a0fa98e705ee302cdfc08c2b472768afc6170dddf6d37

root@ytt-large:/home/ytt#  docker run --name backend-mysql2 \
>   --ip 172.20.0.3 -e MYSQL_ROOT_PASSWORD=123456 \
>  -p 33062:3306 --network=dble-net \
>  -d mysql:8.0.29 --server-id=2 
5f907b977fc242be35dc01840a5393f2ee754572dd1d59e2fb072032df1ed8d0
  1. 等 MySQL 初始化大概 30 秒实现后,启动 DBLE。
root@ytt-large:/home/ytt# docker run -d -i -t --name dble-server \

>  --ip 172.20.0.5 -p 8066:8066 -p 9066:9066 \
>  --network=dble-net actiontech/dble:latest
df80d0e2451c237afb4792f93e29738579f125288daf0dfee4484ddca8350110
  1. DBLE 失常初始化须要依据配置文件加载分片节点,导入样例库表文件 /opt/dble/conf/template_table.sql。查看 DBLE 启动日志,报错内容为:连贯服务端口 8066 失败,应该是配置文件里 IP 地址没同步改过来。
   root@ytt-large:/home/ytt# docker logs dble-server
   dble init&start in docker
   Starting dble-server...
   wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
   wait-for-it.sh: 127.0.0.1:8066 is available after 6 seconds
   init shardingNode and execute template_table.sql
   ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104
   ERROR 2003 (HY000): Can't connect to MySQL server on'127.0.0.1' (111)
   dble init finish
  1. 用 docker cp 在宿主环境批改 db.xml 后拷贝到容器或者进入容器环境间接批改 db.xml 里的 url 值为正确的 IP 地址,之后再退出容器重启 dble-server。
   root@ytt-large:/home/ytt# docker exec -it dble-server /bin/bash
   
   [root@df80d0e2451c /]# cat /opt/dble/conf/db.xml | grep 172
           <dbInstance name="instanceM1" url="172.20.0.2:3306" user="root" password="123456" maxCon="300" minCon="10"
           <dbInstance name="instanceM2" url="172.20.0.3:3306" user="root" password="123456" maxCon="300" minCon="10"
           
   root@ytt-large:/home/ytt# docker restart dble-server
   dble-server
   
  1. 再次查看 DBLE 日志。有新的报错内容:提醒服务账户对数据库 testdb2 没权限拜访。
   [root@df80d0e2451c /]# dble init&start in docker
   Starting dble-server...
   wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
   wait-for-it.sh: 127.0.0.1:8066 is available after 2 seconds
   init shardingNode and execute template_table.sql
   ERROR 1044 (HY000) at line 200 in file: '/opt/dble/conf/template_table.sql': Access denied for user 'root' to database 'testdb2'
   ERROR 1146 (42S02) at line 202 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test1' doesn't exist in the config of sharding
   ERROR 1146 (42S02) at line 207 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test1' doesn't exist
   ERROR 1146 (42S02) at line 210 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test2' doesn't exist in the config of sharding
   ERROR 1146 (42S02) at line 215 in file: '/opt/dble/conf/template_table.sql': Table 'testdb.tb_test2' doesn't exist
   dble init finish
  1. 连贯 DBLE 查看,发现权限是够的。那应该是用户配置文件里没把这个逻辑库增加进去。
root@ytt-large:/home/ytt# mysql -uroot -p123456 -P8066 -h 127.0.0.1 -e "show grants for root" -s |grep 'CREATE'
mysql: [Warning] Using a password on the command line interface can be insecure.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE,... ON *.* TO `root`@`%` WITH GRANT OPTION
  1. 相似步骤 6,增加逻辑库 testdb2 到 DBLE 配置文件 user.xml,完了退出容器并重启 dble-server。
[root@df80d0e2451c ~]# cat /opt/dble/conf/user.xml | grep 'testdb2'
   <shardingUser name="root" password="123456" schemas="testdb,testdb2" readOnly="false" blacklist="blacklist1" maxCon="20"/>
       
root@ytt-large:/home/ytt# docker restart dble-server
dble-server   
   
  1. 再次查看日志内容,曾经无报错。
    root@ytt-large:/home/ytt# docker logs dble-server | tail -n 6
    Starting dble-server...
    Removed stale pid file: /opt/dble/dble.pid
    wait-for-it.sh: waiting 15 seconds for 127.0.0.1:8066
    wait-for-it.sh: 127.0.0.1:8066 is available after 2 seconds
    init shardingNode and execute template_table.sql
    dble init finish
  1. 连贯服务端口,查看下逻辑库:曾经失常创立结束。
root@ytt-large:/home/ytt# mysql -uroot -p123456 -h127.0.0.1 -P8066 -e "show databases"
mysql: [Warning] Using a password on the command line interface can be insecure.
    +----------+
    | DATABASE |
    +----------+
    | testdb   |
    | testdb2  |
    +----------+
正文完
 0