1,准备的环境:
安装python
安装mysql数据库,并且配置组复制
2,下载安装mysql-shell下载地址
wget https://cdn.mysql.com//Downloads/MySQL-Shell/mysql-shell-8.0.12-linux-glibc2.12-x86-64bit.tar.gz
3,下载安装mysql-router 下载地址
wget https://cdn.mysql.com//Downloads/MySQL-Router/mysql-router-8.0.12-linux-glibc2.12-x86-64bit.tar.gz
4, 每台安装mysql shell 与 mysql router软件
tar -zxvf mysql shell
tar -zxvf mysql router
禁止其他引擎创建库表:在my.cnf中
disabled_storage_engines = MyISAM,BLACKHOLE,FEDERATED,CSV,ARCHIVE
5, 授予用户权限
提供的是管理Innodb集群问题所需的权限
GRANT ALL PRIVILEGES ON mysql_innodb_cluster_metadata.* TO your_user@’%’ WITH GRANT OPTION;
GRANT RELOAD,SHUTDOWN,PROCESS,FILE,SUPER,REPLICATION SLAVE,REPLICATION CLIENT,CREATE USER ON . TO your_user@’%’ WITH GRANT OPTION;
GRANT SELECT ON . TO your_user@’%’ WITH GRANT OPTION;
如果仅需要读取操作,则可以使用受限的特权账户
GRANT SELECT ON mysql_innodb_cluster_metadata.* TO your_user@’%’;
GRANT SELECT ON performance_schema.global_status TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_applier_configuration TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_applier_status TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_applier_status_by_coordinator TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_applier_status_by_worker TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_connection_configuration TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_connection_status TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_group_member_stats TO your_user@’%’;
GRANT SELECT ON performance_schema.replication_group_members TO your_user@’%’;
GRANT SELECT ON performance_schema.threads TO your_user@’%’ WITH GRANT OPTION;
6,授予权限(每台服务器上面执行)
GRANT ALL PRIVILEGES ON mysql_innodb_cluster_metadata.* TO rep1 with grant option;
GRANT RELOAD,SHUTDOWN,PROCESS,FILE,SUPER,REPLICATION SLAVE,REPLICATION CLIENT,CREATE USER ON . TO rep1 with grant option;
GRANT SELECT ON . TO rep1 with grant option;
flush privileges;
7,通过mysql shell 中的bin/mysqlsh执行
#mysql_shell路径/bin/mysqlsh
连接组复制中其中一台mysql实例,最好是连接任意一台。
shell.connect(‘rep1@10.6.248.196:3306’);
var cluster = dba.createCluster(‘prodCluster’,{adoptFromGR:true,force:true});
到此集群创建完毕!
三种帮组的用法:
dba.help()
object.help(’’)
dba.help(‘createCluster’)
8,增加实例进入Cluster
例子:因为在创建的时候已经自动将my.cnf组复制中的三个主机加进去了。所以一下只是一个例子而已!
cluster.addInstance(‘rep1@10.6.248.197:3306’);
且增加实例需要用于拥有的权限如下:
ERROR: The account ‘rep1’@’%’ is missing privileges required to manage an InnoDB cluster:
Missing privileges on schema ‘mysql’: DELETE, INSERT, UPDATE.
简单的解决办法就是:
grant all privileges on . to rep1 with grant option;
其中退出mysql JS > \quit;
9,安装router 并且执行命令(每台):
./bin/mysqlrouter --bootstrap rep1@10.6.248.196:3306 -d myrouter --user=root
user = root (各服务器上面都需要进行创建root用户并且设定其host的范围)
-d 的意思:
为一个新的实例创建一个自包含的目录路由器。
注意一下信息:
Classic MySQL protocol connections to cluster ‘prodCluster’:
10,安装完成后,会在当前目录下生成一个myrouter的目录,下面会有一个配置文件
#vim mysqlrouter.conf
路径:/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter
配置文件如下:
[DEFAULT]
user=root
logging_folder=/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter/log
runtime_folder=/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter/run
data_folder=/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter/data
keyring_path=/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter/data/keyring
master_key_path=/mysqlAPI/mysql-router-8.0.12-linux-glibc2.12-x86-64bit/bin/myrouter/mysqlrouter.key
connect_timeout=30
read_timeout=30
[logger]
level = INFO
[metadata_cache:prodCluster]
router_id=1
bootstrap_server_addresses=mysql://Monitor:3306,mysql://Myslave:3306,mysql://Kmaster:3306
user=mysql_router1_xk5lw47ba9ky
metadata_cluster=prodCluster
ttl=300
[routing:prodCluster_default_rw]
bind_address=10.6.248.196
bind_port=6446
destinations=10.6.248.196
routing_strategy=round-robin
protocol=classic
connect_timeout = 300
client_connect_timeout = 300
max_connect_errors = 60
max_connections = 10000
mode = read-write
#mode = read-only
[routing:prodCluster_default_x_ro]
bind_address=10.6.248.196
bind_port=64460
destinations=10.6.248.197:3306,10.6.248.198:3306
routing_strategy=round-robin
protocol=x
connect_timeout = 300
client_connect_timeout = 300
max_connect_errors = 60
max_connections = 10000
mode = read-write
[routing:prodCluster_default_rw]
bind_address=10.6.248.196
bind_port=6446
destinations=10.6.248.196
routing_strategy=round-robin
protocol=x
connect_timeout = 300
client_connect_timeout = 300
max_connect_errors = 60
max_connections = 10000
mode = read-write
#mode = read-only
[routing:prodCluster_default_x_ro]
bind_address=10.6.248.196
bind_port=64460
destinations=10.6.248.197:3306,10.6.248.198:3306
routing_strategy=round-robin
protocol=classic
connect_timeout = 300
client_connect_timeout = 300
max_connect_errors = 60
max_connections = 10000
mode = read-write