实验环境
主机名/IP | 角色 |
server01/192.168.1.201 | 主 |
server02/192.168.1.202 | 辅 |
server03/192.168.1.203 | 辅 |
server04/192.168.1.204 | 只读副本 |
InnoDB Cluster 8.4部署步骤请查阅文档:https://www.wakamizu.cn/innodb-cluster-8-4%e9%9b%86%e7%be%a4%e9%83%a8%e7%bd%b2/
server04
添加映射
vim /etc/hosts
192.168.1.201 server01
192.168.1.202 server02
192.168.1.203 server03
192.168.1.204 server04
安装mysql存储库
wget https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb
dpkg -i mysql-apt-config_0.8.32-1_all.deb
apt update -y
安装mysql
apt install mysql-server -y
配置允许外部访问mysql
vim /etc/mysql/mysql.conf.d/mysql.conf
[mysqld]
bind-address=0.0.0.0
重启服务
systemctl restart mysql
安装mysql shell
apt install mysql-shell -y
使用mysql shell连接mysql
mysqlsh mysql://root@localhost:3306
进入js模式查询已连接数据库信息
\js
session;
shell.status();
\quit
执行mysql指令可以使用:
\sql mysql指令
创建集群服务配置账户
mysqlsh mysql://root@localhost:3306
\js
dba.configureInstance('root@localhost:3306',{clusterAdmin:"'clusteradmin'@'%'"});
检查实例是否符合集群要求
dba.checkInstanceConfiguration('clusteradmin@localhost:3306');
server01
将server04加入集群
mysqlsh -u root -p
\js
var cluster = dba.getCluster()
cluster.addReplicaInstance('clusteradmin@192.168.1.204:3306')
查看信息
cluster.status()
{
"clusterName": "testCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "server01:3306",
"ssl": "REQUIRED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"server01:3306": {
"address": "server01:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {
"Replica1": {
"address": "server04:3306",
"role": "READ_REPLICA",
"status": "ONLINE",
"version": "8.4.2"
}
},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.2"
},
"server02:3306": {
"address": "server02:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.2"
},
"server03:3306": {
"address": "server03:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.4.2"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "server01:3306"
}
加入集群指令也可以增加参数指定克隆来源
cluster.addReplicaInstance('clusteradmin@192.168.1.204:3306',{ recoveryMethod: "clone",cloneDonor:"192.168.1.202:3306"})
注意:当Group Replication以单主模式运行时,无法在次要成员上启动复制IO线程。这是因为在单主模式下,只有主节点可以执行写操作,而次要节点只能执行读操作。
移除只读副本节点
cluster.removeInstance('clusteradmin@192.168.1.204:3306')
重新加入集群
cluster.rejoinInstance('clusteradmin@192.168.1.204:3306')