1. 程式人生 > >Mysql innodb cluster

Mysql innodb cluster

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 [email protected]’%’ WITH GRANT OPTION;
GRANT RELOAD,SHUTDOWN,PROCESS,FILE,SUPER,REPLICATION SLAVE,REPLICATION CLIENT,CREATE USER ON .

TO [email protected]’%’ WITH GRANT OPTION;
GRANT SELECT ON . TO [email protected]’%’ WITH GRANT OPTION;

如果僅需要讀取操作,則可以使用受限的特權賬戶

GRANT SELECT ON mysql_innodb_cluster_metadata.* TO [email protected]’%’;
GRANT SELECT ON performance_schema.global_status TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_applier_configuration TO

[email protected]’%’;
GRANT SELECT ON performance_schema.replication_applier_status TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_applier_status_by_coordinator TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_applier_status_by_worker TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_connection_configuration TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_connection_status TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_group_member_stats TO [email protected]’%’;
GRANT SELECT ON performance_schema.replication_group_members TO [email protected]’%’;
GRANT SELECT ON performance_schema.threads TO [email protected]’%’ 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(‘[email protected]:3306’);
var cluster = dba.createCluster(‘prodCluster’,{adoptFromGR:true,force:true});

到此叢集建立完畢!

三種幫組的用法:
dba.help()
object.help(’’)
dba.help(‘createCluster’)

8,增加例項進入Cluster
例子:因為在建立的時候已經自動將my.cnf組複製中的三個主機加進去了。所以一下只是一個例子而已!
cluster.addInstance(‘[email protected]: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 [email protected]:3306 -d myrouter --user=root
user = root (各伺服器上面都需要進行建立root使用者並且設定其host的範圍)

-d 的意思:
為一個新的例項建立一個自包含的目錄路由器。

注意一下資訊:
Classic MySQL protocol connections to cluster ‘prodCluster’:

  • Read/Write Connections: localhost:6446
    X protocol connections to cluster ‘prodCluster’:
  • Read/Write Connections: localhost:64460

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