结合docker容器创建innodb cluster集群

结合docker容器创建innodb cluster集群

环境

系统版本:centos7.4
docker版本:18.09.0
mysql容器:centos/mysql-57-centos7
网络拓扑:weave跨主机互联方案
服务器:
server1:172.17.224.46
server2:172.17.224.47
server3:172.17.224.49
mysql-shell二进制包:https://dev.mysql.com/downloads/shell/
mysql-router二进制包:https://dev.mysql.com/downloads/router/

开始构建

1、构建容器

docker run -it --name mysql1 -p 6446:6446 -p 6447:6447 --hostname mysql1 centos/mysql-57-centos7 /bin/bash

vim my.cnf

[mysql]  
# 设置mysql客户端默认字符集  
default-character-set=utf8   
socket=/var/lib/mysql/mysql.sock

[mysqld]  
skip-name-resolve  
#设置3306端口  
port = 3306   
socket=/var/lib/mysql/mysql.sock
# 设置mysql的安装目录  
basedir=/opt/rh/rh-mysql57/root
# 设置mysql数据库的数据的存放目录  
datadir=/var/lib/mysql/data
# 允许最大连接数  
max_connections=200  
# 服务端使用的字符集默认为8比特编码的latin1字符集  
character-set-server=utf8  
# 创建新表时将使用的默认存储引擎  
default-storage-engine=INNODB  
# 开启错误日志
log-error=/var/log/mysql/.err

max_allowed_packet=16M  
language=/opt/rh/rh-mysql57/root/usr/share/rh-mysql57-mysql/english/

#高可用
server_id=4
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
relay-log=svr-relay-bin

transaction_write_set_extraction=XXHASH64

#主从复制配置
loose-group_replication_group_name= a38e32fd-5fb6-11e8-ad7a-00259015d941
#注意:这里的地址不能用 node01:24901 这种写法,要用IP,否则无法通信
loose-group_replication_start_on_boot = OFF
loose-group_replication_local_address= "172.18.0.6:24901"
loose-group_replication_group_seeds= "172.18.0.4:24901,172.18.0.5:24901,172.18.0.6:24901,172.18.0.7:24901,172.18.0.8:24901"
loose-group_replication_bootstrap_group = OFF
loose-group_replication_single_primary_mode=OFF
loose-group_replication_allow_local_disjoint_gtids_join = ON
loose-group_replication_enforce_update_everywhere_checks = OFF

#loose-group_replication_bootstrap_group= off
#loose-group_replication_enforce_update_everywhere_checks= FALSE
#loose-group_replication_start_on_boot=off
#
#disabled_storage_engines = MyISAM,BLACKHOLE,FEDERATED,CSV,ARCHIVE
#report_port = 3306
docker cp my.cnf mysql1:/etc/
docker exec -it -uroot mysql1 /bin/bash -c 'mkdir /var/log/mysql && chown mysql:mysql /var/log/mysql'
docker exec -it -umysql mysql1 /bin/bash -c 'run-mysqld'

进入容器进行修改

docker exec -t -uroot mysql1 /bin/bash

给用户授权

mysql
mysql>grant all on *.* to 'test'@'%' with grant option;
mysql>exit
tar xf mysql-shell-8.0.13-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
tar xf mysql-router-8.0.13-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
ln -s /usr/local/mysql-shell-8.0.13-linux-glibc2.12-x86-64bit/bin/mysqlsh /usr/bin/

进入mysql-shell

mysqlsh
 MySQL  JS > \connect [email protected]:3306
 MySQL  172.18.0.4:3306 ssl  JS > dba.checkInstanceConfiguration() #检查配置是否合格
 MySQL  172.18.0.4:3306 ssl  JS > dba.configureLocalInstance() #若配置有错误则自动修改配置
 MySQL  172.18.0.4:3306 ssl  JS > var cluster = dba.createCluster('testCluster') #创建集群
 MySQL  172.18.0.4:3306 ssl  JS > cluster.status() #查看集群状态

重复以上部分操作增加节点mysql2、mysql3
然后在mysql1上增加节点到集群中
并将容器通过weave跨主机互联

weave attach <ipaddress> <CONTAINER ID>
weave connect <host ipaddress>
mysqlsh
 MySQL  JS > \connect [email protected]:3306
 MySQL  172.18.0.4:3306 ssl  JS > var cluster = cluster.getCluster()
 MySQL  172.18.0.4:3306 ssl  JS > cluster.addInstance('[email protected]:3306') # 增加节点
 MySQL  172.18.0.4:3306 ssl  JS > cluster.addInstance('[email protected]:3306') # 增加节点
 MySQL  172.18.0.4:3306 ssl  JS > cluster.status()

报错汇总

错误提示:
[ERROR] Slave SQL for channel 'group_replication_recovery': Error 'Operation CREATE USER failed for 'andunroot'@'%'' on query. Default
 database: ''. Query: 'CREATE USER 'andunroot'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*4DE620B39469D11BDB11E3EBE7BFE40BDDA6FE88'', Error_code: 1396
[Warning] Slave: Operation CREATE USER failed for 'andunroot'@'%' Error_code: 1396
[ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stoppe
d at log 'binlog.000001' position 793

权限错误,无法创建账户。
错误提示:
[ERROR] Slave SQL for channel 'group_replication_recovery': Error 'Can't drop database 'mysql_innodb_cluster_metadata'; database does
n't exist' on query. Default database: 'mysql_innodb_cluster_metadata'. Query: 'DROP SCHEMA mysql_innodb_cluster_metadata', Error_code: 1008
[Warning] Slave: Can't drop database 'mysql_innodb_cluster_metadata'; database doesn't exist Error_code: 1008
[ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopp
ed at log 'binlog.000001' position 3795

SLAVE中没有mysql_innodb_cluster_metadata库,无法同步
mysqlsh
 MySQL  JS > \connect [email protected]:3306
 MySQL  172.18.0.4:3306 ssl  JS > \sql
 MySQL  172.18.0.4:3306 ssl  SQL > stop group_replication;
 MySQL  172.18.0.4:3306 ssl  SQL > set global super_read_only=FALSE;
 MySQL  172.18.0.4:3306 ssl  SQL > create database mysql_innodb_cluster_metadata;
 MySQL  172.18.0.4:3306 ssl  SQL > set global super_read_only=ON;
然后重新添加此节点

你可能感兴趣的:(Docker,innodb,cluster)