This角色将使用MySQL InnoDB Cluster或GTID replication
在HA模式下安装和配置MySQL Server或MySQL目录
- Role Variables
- Vagrant up, build the test infrastructure
- Ansible setup and pre-flight check
- Deploy MySQL InnoDB Cluster
- Cluster high availability check
- Restore from complete outage
- Clean up
角色变量
此角色接受此变量:
必需 | 默认 | desc | |
---|---|---|---|
mysql_subnet |
yes |
192.168.25.0/24 |
子网在哪里聆听。如果VM或Bare Metal Server具有多个接口,则Ansible将过滤界面,而MySQL将仅在特定接口上收听。该变量还用于计算MySQL Server ID。 |
mysql_root_pw |
yes |
mysql root密码。 | |
mysql_authentication |
no |
mysql_native_password |
mySQL身份验证方法。 |
disable_firewall |
no |
no |
如果设置为Yes Ansible将禁用防火墙。 |
disable_selinux |
no |
no |
禁用SELINUX。默认号,如果要配置Selinux,请使用另一个角色。您可以禁用SELINUX将此变量设置为Yes |
resolv_mode |
no |
dns |
mySQL如何解析名称,默认DNS。如果设置为主机/etc/hosts文件将被覆盖 |
mysql_listen_all_interfaces |
no |
no |
将此变量设置为YES,以允许MySQL在所有接口上收听0.0.0.0/0。否则,将使用 mysql_subnet variable | 检索收听IP地址
mysql_user |
no |
mysql |
mySQL系统用户 |
mysql_group |
no |
mysql |
MySQL搜索系统的组用户 |
mysql_data_dir |
no |
/var/lib/mysql |
mysql数据dir |
mysql_log_dir |
no |
/var/log/mysql |
mysql log dir |
mysql_conf_dir |
no |
/etc/mysql |
mysql conf dir |
mysql_pid_dir |
no |
/var/run/mysqld |
mysql pid dir |
mysql_operator_user |
no |
operator |
mySQL操作员用户,用于引导mysql innodb群集。 |
mysql_operator_password |
no |
Op3r4torMyPw |
操作员用户的密码 |
mysql_replica_user |
no |
replica |
mySQL副本用户。用于所有复制操作 |
mysql_replica_password |
no |
rEpL1c4p4Sw0,rd |
副本用户的密码 |
mysql_replication_mode |
no |
InnoDB Cluster,GTID,空/无(默认) | |
mysql_gr_name |
no |
如果 mysql_replication_mode 设置为 innodb cluster 。组复制的UUID | |
mysql_gr_vcu |
no |
如果 mysql_replication_mode 设置为 innodb cluster 。小组复制view change uuid | |
mysql_innodb_cluster_name |
no |
如果 mysql_replication_mode 设置为 innodb cluster 。 mysql innodb群集的名称 |
流动,建立测试基础架构
要测试这个角色,我们使用Vagrant和Virtualbox,但是如果您愿意,您也可以使用自己的VMS或Baremetal机器。
第一步是下载this repo和birng所有VM。但首先在 change_me 变量中的vagrantfile粘贴您的public ssh键中。您还可以通过更改NNODES变量来调整部署的VM数量(在此Exaple中,我们将使用5个节点)。现在我们准备好配备机器:
git clone https://github.com/garutilorenzo/ansible-role-linux-mysql.git
cd ansible-role-linux-mysql/
vagrant up
Bringing machine 'my-ubuntu-0' up with 'virtualbox' provider...
Bringing machine 'my-ubuntu-1' up with 'virtualbox' provider...
Bringing machine 'my-ubuntu-2' up with 'virtualbox' provider...
Bringing machine 'my-ubuntu-3' up with 'virtualbox' provider...
Bringing machine 'my-ubuntu-4' up with 'virtualbox' provider...
[...]
[...]
my-ubuntu-4: Inserting generated public key within guest...
==> my-ubuntu-4: Machine booted and ready!
==> my-ubuntu-4: Checking for guest additions in VM...
my-ubuntu-4: The guest additions on this VM do not match the installed version of
my-ubuntu-4: VirtualBox! In most cases this is fine, but in rare cases it can
my-ubuntu-4: prevent things such as shared folders from working properly. If you see
my-ubuntu-4: shared folder errors, please make sure the guest additions within the
my-ubuntu-4: virtual machine match the version of VirtualBox you have installed on
my-ubuntu-4: your host and reload your VM.
my-ubuntu-4:
my-ubuntu-4: Guest Additions Version: 6.0.0 r127566
my-ubuntu-4: VirtualBox Version: 6.1
==> my-ubuntu-4: Setting hostname...
==> my-ubuntu-4: Configuring and enabling network interfaces...
==> my-ubuntu-4: Mounting shared folders...
my-ubuntu-4: /vagrant => C:/Users/Lorenzo Garuti/workspaces/simple-ubuntu
==> my-ubuntu-4: Running provisioner: shell...
my-ubuntu-4: Running: inline script
==> my-ubuntu-4: Running provisioner: shell...
my-ubuntu-4: Running: inline script
my-ubuntu-4: hello from node 5
Ansible设置和飞行前检查
现在,如果您没有安装易菜,请安装Ansible和所有要求:
apt-get install python3 python3-pip uuidgen openssl
pip3 install pipenv
pipenv shell
pip install -r requirements.txt
现在安装了Ansible,我们可以直接从GitHub下载该角色:
ansible-galaxy install git+https://github.com/garutilorenzo/ansible-role-linux-mysql.git
Whit Ansible和我们可以设置库存文件(hosts.ini)的角色:
[mysql]
my-ubuntu-0 ansible_host=192.168.25.110
my-ubuntu-1 ansible_host=192.168.25.111
my-ubuntu-2 ansible_host=192.168.25.112
my-ubuntu-3 ansible_host=192.168.25.113
my-ubuntu-4 ansible_host=192.168.25.114
和vars.yml文件:
---
disable_firewall: yes
disable_selinux: yes
mysql_resolv_mode: hosts
mysql_subnet: 192.168.25.0/24
mysql_listen_all_interfaces: yes
mysql_root_pw: '<CHANGE_ME>' # <- openssl rand -base64 32 | sed 's/=//'
mysql_replication_mode: 'InnoDB Cluster'
mysql_gr_name: '<CHANGE_ME>' # <- uuidgen
mysql_gr_vcu: '<CHANGE_ME>' # <- uuidgen
mysql_innodb_cluster_name: 'cluster_lab'
注意 mysql_gr_name和mysql_gr_vcu是不同的uuid,所以两次运行uuidgen。
使用此Vars,我们将使用MySQL InnoDB群集在HA模式下部署MySQL,将从现有的Group Replication配置创建群集。
进行安装之前的最后一步是创建网站。
---
- hosts: mysql
become: yes
remote_user: vagrant
roles:
- role: ansible-role-linux-mysql
vars_files:
- vars.yml
部署mysql innodb群集
我们终于准备好使用Ansible部署MySQL InnoDB群集:
export ANSIBLE_HOST_KEY_CHECKING=False # Ansible skip ssh-key validation
ansible-playbook -i hosts.ini site.yml -e mysql_bootstrap_host=my-ubuntu-0
TASK [ansible-role-linux-mysql : render mysql.conf.d/mysqld.cnf] *******************************************************************************************
ok: [my-ubuntu-0]
ok: [my-ubuntu-2]
ok: [my-ubuntu-1]
ok: [my-ubuntu-3]
ok: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : render mysql.conf.d/gtid.cnf] *********************************************************************************************
ok: [my-ubuntu-1]
ok: [my-ubuntu-0]
ok: [my-ubuntu-3]
ok: [my-ubuntu-2]
ok: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : ansible.builtin.fail] *****************************************************************************************************
skipping: [my-ubuntu-0]
skipping: [my-ubuntu-1]
skipping: [my-ubuntu-2]
skipping: [my-ubuntu-3]
skipping: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : ansible.builtin.fail] *****************************************************************************************************
skipping: [my-ubuntu-0]
skipping: [my-ubuntu-1]
skipping: [my-ubuntu-2]
skipping: [my-ubuntu-3]
skipping: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : render innodb_cluster.cnf] ************************************************************************************************
ok: [my-ubuntu-0]
ok: [my-ubuntu-1]
ok: [my-ubuntu-3]
ok: [my-ubuntu-2]
ok: [my-ubuntu-4]
RUNNING HANDLER [ansible-role-linux-mysql : reload systemd] ************************************************************************************************
ok: [my-ubuntu-3]
ok: [my-ubuntu-0]
ok: [my-ubuntu-2]
ok: [my-ubuntu-4]
ok: [my-ubuntu-1]
PLAY RECAP *************************************************************************************************************************************************
my-ubuntu-0 : ok=69 changed=27 unreachable=0 failed=0 skipped=12 rescued=0 ignored=0
my-ubuntu-1 : ok=71 changed=28 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
my-ubuntu-2 : ok=71 changed=28 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
my-ubuntu-3 : ok=71 changed=28 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
my-ubuntu-4 : ok=71 changed=28 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
现在安装了群集,但是我们必须持续一些配置。由于群集是一个新的群集,因此Ansible已在bootstrap模式下启动了组复制。这意味着第一个实例(在这种情况下为my-ubuntu-0)具有te value group_replication_bootstrap_group_group 设置为 on 和 group_replication_group_seeds 空值。第二次运行的Ansible,此变量将设置为正确的值:
ansible-playbook -i hosts.ini site.yml
TASK [ansible-role-linux-mysql : ansible.builtin.fail] *****************************************************************************************************
skipping: [my-ubuntu-0]
skipping: [my-ubuntu-1]
skipping: [my-ubuntu-2]
skipping: [my-ubuntu-3]
skipping: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : ansible.builtin.fail] *****************************************************************************************************
skipping: [my-ubuntu-0]
skipping: [my-ubuntu-1]
skipping: [my-ubuntu-2]
skipping: [my-ubuntu-3]
skipping: [my-ubuntu-4]
TASK [ansible-role-linux-mysql : render innodb_cluster.cnf] ************************************************************************************************
ok: [my-ubuntu-2]
ok: [my-ubuntu-4]
ok: [my-ubuntu-1]
ok: [my-ubuntu-3]
changed: [my-ubuntu-0]
PLAY RECAP *************************************************************************************************************************************************
my-ubuntu-0 : ok=30 changed=1 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
my-ubuntu-1 : ok=30 changed=0 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
my-ubuntu-2 : ok=30 changed=0 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
my-ubuntu-3 : ok=30 changed=0 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
my-ubuntu-4 : ok=30 changed=0 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
在本指南中,MySQLSH用于在MySQL InnoDB群集上进行操作。 Here您可以找到有关MySQLSH的更多信息。
现在我们最终可以检查我们的群集:
root@my-ubuntu-0:~# mysqlsh root@my-ubuntu-0
Please provide the password for 'root@my-ubuntu-0': ******************************************
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
MySQL localhost:33060+ ssl JS > clu.status()
{
"clusterName": "cluster_lab",
"defaultReplicaSet": {
"name": "default",
"primary": "my-ubuntu-0:3306",
"ssl": "DISABLED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to 2 failures.",
"topology": {
"my-ubuntu-0:3306": {
"address": "my-ubuntu-0:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-1:3306": {
"address": "my-ubuntu-1:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-2:3306": {
"address": "my-ubuntu-2:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-3:3306": {
"address": "my-ubuntu-3:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-4:3306": {
"address": "my-ubuntu-4:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "my-ubuntu-0:3306"
}
集群高可用性检查
要测试群集,我们可以使用样本码头组成的堆栈,该示例使用:
- WordPress作为前端
- mysqlrouter将将WP连接到MySQL
要运行此测试,您必须安装Docker和Docker compose。
用户和数据库创建
我们需要为WordPress创建一个DB和一个用户,为此,我们必须找到主服务器(检查群集状态并使用 - >“ mode”:“ r/w”)
找到节点。
root@my-ubuntu-0:~# mysqlsh root@localhost
Please provide the password for 'root@localhost': ******************************************
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
Switching to SQL mode... Commands end with ;
create database wordpress;
create user 'wordpress'@'%' identified by 'wordpress';
grant all on wordpress.* TO 'wordpress'@'%';
flush privileges;
样品Dokcer组成堆栈
可以在examples文件夹中找到示例堆栈,这是组合文件:
version: '3.4'
services:
wordpress:
image: wordpress:latest
ports:
- 80:80
restart: always
environment:
- WORDPRESS_DB_HOST=mysqlrouter:6446
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
mysqlrouter:
image: garutilorenzo/mysqlrouter:8.0.30
volumes:
- type: volume
source: mysqlrouter
target: /app/mysqlrouter/
volume:
nocopy: true
environment:
- MYSQL_HOST=my-ubuntu-0
- MYSQL_PORT=3306
- MYSQL_USER=root
- MYSQL_PASSWORD=<CHANGE_ME> # <- the same password in the vars.yml file
- MYSQL_ROUTER_ACCOUNT=mysql_router_user
- MYSQL_ROUTER_PASSWORD=<CHANGE_ME> # <- openssl rand -base64 32 | sed 's/=//'
extra_hosts:
my-ubuntu-0: 192.168.25.110
my-ubuntu-1: 192.168.25.111
my-ubuntu-2: 192.168.25.112
my-ubuntu-3: 192.168.25.113
my-ubuntu-4: 192.168.25.114
volumes:
mysqlrouter:
现在我们可以启动堆栈并检查日志:
docker-compose -f mysql-router-compose.yml up -d
docker-compose -f mysql-router-compose.yml logs mysqlrouter
examples-mysqlrouter-1 | Succesfully contacted mysql server at my-ubuntu-0. Checking for cluster state.
examples-mysqlrouter-1 | Check if config exist
examples-mysqlrouter-1 | bootstrap mysqlrouter with account mysql_router_user
examples-mysqlrouter-1 | Succesfully contacted mysql server at my-ubuntu-0. Trying to bootstrap.
examples-mysqlrouter-1 | Please enter MySQL password for root:
examples-mysqlrouter-1 | # Bootstrapping MySQL Router instance at '/app/mysqlrouter'...
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | Please enter MySQL password for mysql_router_user:
examples-mysqlrouter-1 | - Creating account(s) (only those that are needed, if any)
examples-mysqlrouter-1 | - Verifying account (using it to run SQL queries that would be run by Router)
examples-mysqlrouter-1 | - Storing account in keyring
examples-mysqlrouter-1 | - Adjusting permissions of generated files
examples-mysqlrouter-1 | - Creating configuration /app/mysqlrouter/mysqlrouter.conf
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | # MySQL Router configured for the InnoDB Cluster 'cluster_lab'
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | After this MySQL Router has been started with the generated configuration
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | $ mysqlrouter -c /app/mysqlrouter/mysqlrouter.conf
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | InnoDB Cluster 'cluster_lab' can be reached by connecting to:
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | ## MySQL Classic protocol
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | - Read/Write Connections: localhost:6446
examples-mysqlrouter-1 | - Read/Only Connections: localhost:6447
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | ## MySQL X protocol
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | - Read/Write Connections: localhost:6448
examples-mysqlrouter-1 | - Read/Only Connections: localhost:6449
examples-mysqlrouter-1 |
examples-mysqlrouter-1 | Starting mysql-router.
examples-mysqlrouter-1 | 2022-08-30 12:03:57 io INFO [7f794f1e0bc0] starting 4 io-threads, using backend 'linux_epoll'
examples-mysqlrouter-1 | 2022-08-30 12:03:57 http_server INFO [7f794f1e0bc0] listening on 0.0.0.0:8443
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache_plugin INFO [7f794a606700] Starting Metadata Cache
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f794a606700] Connections using ssl_mode 'PREFERRED'
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] Starting metadata cache refresh thread
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790e7fc700] [routing:bootstrap_rw] started: routing strategy = first-available
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790e7fc700] Start accepting connections for routing routing:bootstrap_rw listening on 6446
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790dffb700] [routing:bootstrap_x_ro] started: routing strategy = round-robin-with-fallback
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790dffb700] Start accepting connections for routing routing:bootstrap_x_ro listening on 6449
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790effd700] [routing:bootstrap_ro] started: routing strategy = round-robin-with-fallback
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790effd700] Start accepting connections for routing routing:bootstrap_ro listening on 6447
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] Connected with metadata server running on my-ubuntu-2:3306
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790d7fa700] [routing:bootstrap_x_rw] started: routing strategy = first-available
examples-mysqlrouter-1 | 2022-08-30 12:03:57 routing INFO [7f790d7fa700] Start accepting connections for routing routing:bootstrap_x_rw listening on 6448
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] Potential changes detected in cluster 'cluster_lab' after metadata refresh
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] Metadata for cluster 'cluster_lab' has 5 member(s), single-primary: (view_id=0)
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] my-ubuntu-2:3306 / 33060 - mode=RO
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] my-ubuntu-1:3306 / 33060 - mode=RO
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] my-ubuntu-0:3306 / 33060 - mode=RW
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] my-ubuntu-3:3306 / 33060 - mode=RO
examples-mysqlrouter-1 | 2022-08-30 12:03:57 metadata_cache INFO [7f7948602700] my-ubuntu-4:3306 / 33060 - mode=RO
测试前端
现在,如果您尝试访问localhost,您可以看到WordPress安装页面:
安装和配置WP,现在我们已经准备好了一些Chaos Monkey
模拟灾难
要测试WP达到性能,我们可以开始此简单测试:
while true; do curl -s -o /dev/null -w "%{http_code}" http://localhost; echo; sleep 1; done
200
200
现在关闭RW节点(在这种情况下为my-ubuntu-0):
root@my-ubuntu-0:~# sudo halt -p
Connection to 192.168.25.110 closed by remote host.
Connection to 192.168.25.110 closed.
并检查测试脚本的输出:
while true; do curl -s -o /dev/null -w "%{http_code}" http://localhost; echo; sleep 1; done
200
500 # <- my-ubuntu-0 shutdown and MySQL primary switch
200
200
现在,我们从第二个节点中检查群集状态,我们看到群集仍然是在线,并且可以忍受一次失败:
root@my-ubuntu-1:~# mysqlsh root@localhost
Please provide the password for 'root@localhost': ******************************************
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
MySQL localhost:33060+ ssl JS > clu.status()
{
"clusterName": "cluster_lab",
"defaultReplicaSet": {
"name": "default",
"primary": "my-ubuntu-2:3306",
"ssl": "DISABLED",
"status": "OK_PARTIAL",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure. 1 member is not active.",
"topology": {
"my-ubuntu-0:3306": {
"address": "my-ubuntu-0:3306",
"memberRole": "SECONDARY",
"mode": "n/a",
"readReplicas": {},
"role": "HA",
"shellConnectError": "MySQL Error 2003: Could not open connection to 'my-ubuntu-0:3306': Can't connect to MySQL server on 'my-ubuntu-0:3306' (110)",
"status": "(MISSING)"
},
"my-ubuntu-1:3306": {
"address": "my-ubuntu-1:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-2:3306": {
"address": "my-ubuntu-2:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-3:3306": {
"address": "my-ubuntu-3:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-4:3306": {
"address": "my-ubuntu-4:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "my-ubuntu-2:3306"
}
MySQL localhost:33060+ ssl JS >
如果您在localhost上检查WP,现在主人是 my-ubuntu-2 node。
现在,如果我们再次提出 my-ubuntu-0 节点,节点将重新加入群集,并将从其他节点获得更新:
root@my-ubuntu-1:~# mysqlsh root@localhost
Please provide the password for 'root@localhost': ******************************************
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
MySQL localhost:33060+ ssl JS > clu.status()
{
"clusterName": "cluster_lab",
"defaultReplicaSet": {
"name": "default",
"primary": "my-ubuntu-2:3306",
"ssl": "DISABLED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to 2 failures.",
"topology": {
"my-ubuntu-0:3306": {
"address": "my-ubuntu-0:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-1:3306": {
"address": "my-ubuntu-1:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-2:3306": {
"address": "my-ubuntu-2:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-3:3306": {
"address": "my-ubuntu-3:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-4:3306": {
"address": "my-ubuntu-4:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "my-ubuntu-2:3306"
}
从完全中断恢复
如果出于任何原因所有服务器都会下降,则必须从complete outage恢复集群。
要这样做,我们必须连接到一个实例,edit/etc/mysql/mysql.conf.d/innodb_cluster.cnf和set group_replication_bootstrap_group_group_group to on 和注释 group_replication_group_seeds 。我们现在必须重新启动mysql:
vagrant@my-ubuntu-0:~$
vi /etc/mysql/mysql.conf.d/innodb_cluster.cnf
group_replication_bootstrap_group=on
#group_replication_group_seeds=my-ubuntu-0:33061,my-ubuntu-1:33061,my-ubuntu-2:33061,my-ubuntu-3:33061,my-ubuntu-4:33061
systemctl restart mysqld
对于所有其他(四个)成员,我们必须启动组复制:
vagrant@my-ubuntu-4:~$ mysqlsh root@localhost
Please provide the password for 'root@localhost': ******************************************
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
Switching to SQL mode... Commands end with ;
MySQL localhost:33060+ ssl SQL > start group_replication;
Query OK, 0 rows affected (1.7095 sec)
如果集群上的流量很低或缺乏群集将在线:
MySQL localhost:33060+ ssl SQL > \js
Switching to JavaScript mode...
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
MySQL localhost:33060+ ssl JS > clu.status()
{
"clusterName": "cluster_lab",
"defaultReplicaSet": {
"name": "default",
"primary": "my-ubuntu-0:3306",
"ssl": "DISABLED",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to 2 failures.",
"topology": {
"my-ubuntu-0:3306": {
"address": "my-ubuntu-0:3306",
"memberRole": "PRIMARY",
"mode": "R/W",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-1:3306": {
"address": "my-ubuntu-1:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-2:3306": {
"address": "my-ubuntu-2:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-3:3306": {
"address": "my-ubuntu-3:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
},
"my-ubuntu-4:3306": {
"address": "my-ubuntu-4:3306",
"memberRole": "SECONDARY",
"mode": "R/O",
"readReplicas": {},
"replicationLag": "applier_queue_applied",
"role": "HA",
"status": "ONLINE",
"version": "8.0.30"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "my-ubuntu-0:3306"
}
如果该集群在complete outage的时刻有大量的流量。您可能必须运行mysqlsh:
MySQL localhost:33060+ ssl JS > var clu = dba.rebootClusterFromCompleteOutage();
清理
完成后,您最终可以用:
销毁集群
vagrant destroy
my-ubuntu-4: Are you sure you want to destroy the 'my-ubuntu-4' VM? [y/N] y
==> my-ubuntu-4: Forcing shutdown of VM...
==> my-ubuntu-4: Destroying VM and associated drives...
my-ubuntu-3: Are you sure you want to destroy the 'my-ubuntu-3' VM? [y/N] y
==> my-ubuntu-3: Forcing shutdown of VM...
==> my-ubuntu-3: Destroying VM and associated drives...
my-ubuntu-2: Are you sure you want to destroy the 'my-ubuntu-2' VM? [y/N] y
==> my-ubuntu-2: Forcing shutdown of VM...
==> my-ubuntu-2: Destroying VM and associated drives...
my-ubuntu-1: Are you sure you want to destroy the 'my-ubuntu-1' VM? [y/N] y
==> my-ubuntu-1: Forcing shutdown of VM...
==> my-ubuntu-1: Destroying VM and associated drives...
my-ubuntu-0: Are you sure you want to destroy the 'my-ubuntu-0' VM? [y/N] y
==> my-ubuntu-0: Forcing shutdown of VM...
==> my-ubuntu-0: Destroying VM and associated drives...