利用docker容器,利用mysql-shell 和mysql-router 實現。
setup 1:(建立三個容器)
[root@localhost docker] docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos centos7 7e6257c9f8d8 4 weeks ago 203MBcentos centos8 0d120b6ccaa8 4 weeks ago 215MB docker run -itd --name centos-mysql_s1 --net host centos:centos8 /bin/bash29b2d4ea24663fd984f884bd081c3e5caf53c80c1c2058e2a40a43ee52db9d18[root@localhost docker] docker run -itd --name centos-mysql_s3 --net host centos:centos8 /bin/bash5d4cec7784e33586fa7edfbdab6e854f0f9c938ad611d051dcc5fc2c9dc8dffe[root@localhost docker]34;/bin/bash&34;/bin/bash&34;/bin/bash& lltotal 1421000drwxr-xr-x. 2 root root 136 Sep 14 10:39 docker-rw-r--r--. 1 root root 65413120 Sep 14 11:10 docker.tar-rw-r--r--. 1 root root 694845440 Sep 14 11:34 mysql-8.0.18-linux-glibc2.12-x86_64.tar-rw-r--r--. 1 7155 31415 503854832 Sep 22 2019 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz-rw-r--r--. 1 7155 31415 40986912 Sep 22 2019 mysql-router-8.0.18-linux-glibc2.12-x86_64.tar.xz-rw-r--r--. 1 7155 31415 149997696 Sep 23 2019 mysql-test-8.0.18-linux-glibc2.12-x86_64.tar.xz[root@localhost dir] docker cp mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz centos-mysql_s2:/root[root@localhost dir]開始進入容器[root@localhost dir] cd /usr/local/[root@localhost local] ln -s mysql-8.0.18-linux-glibc2.12-x86_64/ mysql[root@localhost local] yum install -y libaio numactl[root@localhost mysql] useradd mysql -r -g mysql -s /sbin/nologin[root@localhost mysql] ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ./support-files/mysql.server startStarting MySQL.Logging to &39;... SUCCESS![root@localhost mysql] 修改密碼建立一個遠程連接用戶[root@localhost mysql]39;help;&39;\h&39;\c&39;root&39;localhost&39;123456&39;lt&39;%&39;lt123456&39;lt&39;%&39;lt&39;%&39;lt123456&vi /etc/my.cnf[mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=2200 ./support-files/mysql.server restart exit netstat -tnlp |grep mysqltcp6 0 0 :::2200 :::* LISTEN 6634/mysqldtcp6 0 0 :::2211 :::* LISTEN 18973/mysqldtcp6 0 0 :::33060 :::* LISTEN 3681/mysqldtcp6 0 0 :::2222 :::* LISTEN 26452/mysqld[root@localhost dir] cd /usr/local/[root@localhost local] ln -s mysql-shell-8.0.21-linux-glibc2.12-x86-64bit/ mysql-shell /usr/local/mysql-shell/bin/mysqlsh lt@192.168.1.13:2200Please provide the password for &39;: ********Save password for &39;? [Y]es/[N]o/Ne[v]er (default No): yMySQL Shell 8.0.21Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates.Other names may be trademarks of their respective owners.Type &39; or &39; for help; &39; to exit.Creating a session to &39;Fetching schema names for autocompletion... Press ^C to stop.Your MySQL connection id is 9Server version: 8.0.18 MySQL Community Server - GPLNo default schema selected; type \use <schema> to set one. MySQL 192.168.1.13:2200 ssl JS > dba.configureInstance();Configuring local MySQL instance listening at port 2200 for use in an InnoDB cluster...This instance reports its own address as localhost.localdomain:2200Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.NOTE: Some configuration options need to be fixed:+--------------------------+---------------+----------------+--------------------------------------------------+| Variable | Current Value | Required Value | Note |+--------------------------+---------------+----------------+--------------------------------------------------+| binlog_checksum | CRC32 | NONE | Update the server variable || enforce_gtid_consistency | OFF | ON | Update read-only variable and restart the server || gtid_mode | OFF | ON | Update read-only variable and restart the server || server_id | 1 | <unique ID> | Update read-only variable and restart the server |+--------------------------+---------------+----------------+--------------------------------------------------+Some variables need to be changed, but cannot be done dynamically on the server.Do you want to perform the required configuration changes? [y/n]: yDo you want to restart the instance after configuring it? [y/n]: yConfiguring instance...The instance &39; was configured to be used in an InnoDB cluster.Restarting MySQL...NOTE: MySQL server at localhost.localdomain:2200 was restarted. MySQL 192.168.1.13:2200 ssl JS > \exit[root@localhost mysql-shell]39;lt@192.168.1.13:2211& /usr/local/mysql-shell/bin/mysqlsh lt@192.168.1.13:2222Please provide the password for &39;: ******** MySQL 192.168.1.13:2222 ssl JS > dba.configureInstance(); MySQL 192.168.1.13:2222 ssl JS > \exit
[root@localhost mysql-shell]39;testCluster&39;lt@192.168.1.13:2211&39;lt@192.168.1.13:2222& tar xvf ~/dir/mysql-router-8.0.18-linux-glibc2.12-x86_64.tar.xz[root@localhost local] cd mysql-router[root@localhost local] /usr/local/mysql-router/bin/mysqlrouter --config /etc/mysqlrouter.cnf &[root@localhost mysql-router]# netstat -tnlp |grep mysqltcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 31818/mysqlroutertcp 0 0 0.0.0.0:8002 0.0.0.0:* LISTEN 31818/mysqlroutertcp6 0 0 :::22001 :::* LISTEN 11404/mysqldtcp6 0 0 :::2200 :::* LISTEN 11404/mysqldtcp6 0 0 :::22111 :::* LISTEN 11880/mysqldtcp6 0 0 :::2211 :::* LISTEN 11880/mysqldtcp6 0 0 :::33060 :::* LISTEN 3681/mysqldtcp6 0 0 :::22221 :::* LISTEN 12244/mysqldtcp6 0 0 :::2222 :::* LISTEN 12244/mysqld
至此:大功告成。