mysql版本 : mysql8 集群所需最少实例 : 三台 添加hosts记录(添加集群以及数据同步通过主机名交互数据) [root@p0807 ~]# vim /etc/hosts
10.10.21.102 dacs01 10.10.21.103 dacs02 10.10.21.104 dacs03 image.png

[root@p0806 data]# unzip mysql8.0.route.zip [root@p0806 data]# ls mysql8.0.route mysql8.0.route.zip [root@p0806 data]# cd mysql8.0.route [root@p0806 mysql8.0.route]# ll image.png [root@p0806 mysql8.0.route]# docker load -i mysql8.0.tar
[root@p0806 mysql8.0.route]# docker load -i mysql8.0.route.tar image.png [root@p0806 mysql8.0.route]# docker run --restart=always -v /etc/localtime:/etc/localtime:ro -d -e MYSQL_ROOT_PASSWORD=root --net=host --name=db00 mysql/mysql-server:8.0 [root@p0806 mysql8.0.route]# docker ps -a

[root@p0806 mysql8.0.route]# lsof -i:3306 image.png [root@p0806 mysql8.0.route]# docker exec -it db00 mysql -uroot -proot \

-e "CREATE USER 'dacs'@'%';" \ -e "GRANT ALL privileges ON . TO 'dacs'@'%' with grant option;" \ -e "ALTER USER 'dacs'@'%' identified with mysql_native_password by 'dacs@2021';" \ -e "reset master;"

image.png 检查集群 [root@p0806 mysql8.0.route]# docker exec -it db00 mysqlsh -uroot -proot -S/var/run/mysqld/mysqlx.sock image.png 添加集群 MySQL localhost+ ssl JS > dba.configureInstance("dacs@10.10.21.102:3306") image.png PS: MySQL localhost+ ssl JS > dba.configureInstance("dacs@10.10.21.102:3306") MySQL localhost+ ssl JS > dba.configureInstance("dacs@10.10.21.103:3306") MySQL localhost+ ssl JS > dba.configureInstance("dacs@10.10.21.104:3306") 添加完成后重启集群db 再次检查集群状态 MySQLlocalhost+sslJS>dba.checkInstanceConfiguration("dacs@10.10.21.102:3306") image.png PS: MySQLlocalhost+sslJS>dba.checkInstanceConfiguration("dacs@10.10.21.102:3306") MySQLlocalhost+sslJS>dba.checkInstanceConfiguration("dacs@10.10.21.103:3306") MySQLlocalhost+sslJS>dba.checkInstanceConfiguration("dacs@10.10.21.104:3306") 配置完成后重新连接 MySQL localhost+ ssl JS > \c dacs@10.10.21.102:3306 image.png

创建集群实例 MySQL 10.10.21.102:3306 ssl JS > var cluster = dba.createCluster("mycluster") image.png

MySQL10.10.21.102:3306ssl JS > cluster.addInstance("dacs@10.10.21.103:3306")
image.png

MySQL10.10.21.102:3306ssl JS > cluster.addInstance("dacs@10.10.21.104:3306")
MySQL10.10.21.102:3306ssl JS > cluster.describe() image.png [root@p0806 ~]# docker run --restart=always -v /etc/localtime:/etc/localtime:ro -d --name mysql-router \

--net=host \ -e MYSQL_HOST=127.0.0.1 \ -e MYSQL_PORT=3306 \ -e MYSQL_USER=dacs \ -e MYSQL_PASSWORD=dacs@2022 \ -e MYSQL_INNODB_CLUSTER_MEMBERS=3 \ mysql/mysql-router:8.0 image.png

[root@p0806 ~]# docker run --restart=always -v /etc/localtime:/etc/localtime:ro -d --name=mysql-client --hostname=mysql-client -v /data:/data -e MYSQL_ROOT_PASSWORD=root mysql/mysql-server:8.0 image.png

[root@p0806 ~]# docker ps -a image.png