搭建 MySQL 8.0 InnoDB Cluster
rpm -i https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum install mysql-community-{server,client,common,libs}-*
systemctl start mysqld
2、修改 my.cnf 配置文件
#節點1
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.1.249:24901"
loose-group_replication_group_seeds= "192.168.1.249:24901,192.168.1.252:24901,192.168.1.253:24901"
loose-group_replication_bootstrap_group=off
loose-group_replication_ip_whitelist="192.168.1.0/24"
#節點2
server_id=2
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.1.252:24901"
loose-group_replication_group_seeds= "192.168.1.249:24901,192.168.1.252:24901,192.168.1.253:24901"
loose-group_replication_bootstrap_group=off
loose-group_replication_ip_whitelist="192.168.1.0/24"
loose-group_replication_allow_local_disjoint_gtids_join=ON
#節點3
server_id=3
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.1.253:24901"
loose-group_replication_group_seeds= "192.168.1.249:24901,192.168.1.252:24901,192.168.1.253:24901"
loose-group_replication_bootstrap_group=off
loose-group_replication_ip_whitelist="192.168.1.0/24"
loose-group_replication_allow_local_disjoint_gtids_join=ON
3、在三個節點創建復制賬戶
SET SQL_LOG_BIN=0;
alter user root@'localhost' identified by 'MySQL8.0';
CREATE USER root@'%' IDENTIFIED BY 'MySQL8.0';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT BACKUP_ADMIN, BINLOG_ADMIN, CONNECTION_ADMIN, ENCRYPTION_KEY_ADMIN, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, REPLICATION_SLAVE_ADMIN, RESOURCE_GROUP_ADMIN, RESOURCE_GROUP_USER, ROLE_ADMIN, SET_USER_ID, SYSTEM_VARIABLES_ADMIN, XA_RECOVER_ADMIN ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;
4、在第一個節點創建集群並添加節點二、節點三
MySQL JS > shell.connect('root@kuber01:3306')
MySQL kuber01:3306 ssl JS > cluster.addInstance('root@node02:3306');
MySQL kuber01:3306 ssl JS > cluster.addInstance('root@node03:3306');
MySQL kuber01:3306 ssl JS > cluster.status();
5、所有節點停止後重啟集群:
var cluster = dba.rebootClusterFromCompleteOutage('myCluster');
6、配置 MySQL Router
mysqlrouter --bootstrap root@kuber01:3306 --user=mysqlrouter
mysqlrouter &
參考文檔:
https://blog.csdn.net/KokJuis/article/details/78401022
https://blog.csdn.net/tuyong1972873004/article/details/77260036
搭建 MySQL 8.0 InnoDB Cluster