You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67-62Lines changed: 67 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,19 +9,48 @@ This role will install and configure MySQL server or MySQL in HA mode using [MyS
9
9
10
10
## Table of Contents
11
11
12
+
*[Role Variables](#role-variables)
12
13
*[Vagrant up, build the test infrastructure](#vagrant-up-build-the-test-infrastructure)
13
14
*[Ansible setup and pre-flight check](#ansible-setup-and-pre-flight-check)
14
15
*[Deploy MySQL InnoDB Cluster ](#deploy-mysql-innodb-cluster)
15
16
*[Cluster high availability check](#cluster-high-availability-check)
16
17
*[Restore from complete outage](#restore-from-complete-outage)
17
18
*[Clean up](#clean-up)
18
19
20
+
### Role Variables
21
+
22
+
This role accept this variables:
23
+
24
+
| Var | Required | Default | Desc |
25
+
| ------- | ------- | ----------- | ----------- |
26
+
|`mysql_subnet`|`yes`|`192.168.25.0/24`| Subnet where MySQL will be listen. If the VM or bare metal server has more than one interface, Ansible will filter the interface and MySQL wil listen only on a specific interface. This variable is also used to calculate the MySQL server ID. |
27
+
|`mysql_root_pw`|`yes`| `` | MySQL root password. |
28
+
|`mysql_authentication`|`no`|`mysql_native_password`| MySQL authentication method. |
29
+
|`disable_firewall`|`no`|`no`| If set to yes Ansible will disable the firewall. |
30
+
|`disable_selinux`|`no`|`no`| Disable SELinux. Default no, if you want to configure SELinux use another Role. You can disable SELinux setting this variable to yes |
31
+
|`resolv_mode`|`no`|`dns`| How MySQL resolve the names, default dns. If set to *host* the /etc/hosts file will be overwritten |
32
+
|`mysql_listen_all_interfaces`|`no`|`no`| Set this variable to yes to allow MySQL to listen on all interfaces 0.0.0.0/0. Otherwise the listen ip address will be retrieved using *mysql_subnet* variable |
33
+
|`mysql_user`|`no`||`mysql`| MySQL system user |
34
+
|`mysql_group`|`no`||`mysql`| Group of the MySQL search system user |
35
+
|`mysql_data_dir`|`no`||`/var/lib/mysql`| MySQL data dir |
36
+
|`mysql_log_dir`|`no`||`/var/log/mysql`| MySQL log dir |
37
+
|`mysql_conf_dir`|`no`||`/etc/mysql`| MySQL conf dir |
38
+
|`mysql_pid_dir`|`no`||`/var/run/mysqld`| MySQL pid dir |
39
+
|`mysql_operator_user`|`no`||`operator`| MySQL operator user, used to bootstrap MySQL InnoDB Cluster. |
40
+
|`mysql_operator_password`|`no`||`Op3r4torMyPw`| Password of operator user |
41
+
|`mysql_replica_user`|`no`||`replica`| MySQL replica user. Used for all the replica operations |
42
+
|`mysql_replica_password`|`no`||`rEpL1c4p4Sw0,rd`| Password of replica user |
|`mysql_gr_name`|`no`|| `` | Required if *mysql_replication_mode* is set to *InnoDB Cluster*. UUID of the Group Replication |
46
+
|`mysql_gr_vcu`|`no`|| `` | Required if *mysql_replication_mode* is set to *InnoDB Cluster*. Group Replication [view change uuid](https://dev.mysql.com/doc/refman/8.0/en/group-replication-options.html#sysvar_group_replication_view_change_uuid)|
47
+
|`mysql_innodb_cluster_name`|`no`|| `` | Required if *mysql_replication_mode* is set to *InnoDB Cluster*. The name of MySQL InnoDB Cluster |
19
48
20
49
### Vagrant up, build the test infrastructure
21
50
22
-
To test this collection we use [Vagrant](https://www.vagrantup.com/) and [Virtualbox](https://www.virtualbox.org/), but if you prefer you can also use your own VMs or your baremetal machines.
51
+
To test this role we use [Vagrant](https://www.vagrantup.com/) and [Virtualbox](https://www.virtualbox.org/), but if you prefer you can also use your own VMs or your baremetal machines.
23
52
24
-
The first step is to download this [repo](https://github.com/garutilorenzo/ansible-role-linux-mysql/) and birng up all the VMs. But first in the Vagrantfile paste your public ssh key in the *CHANGE_ME* variable. You can also adjust the number of the vm deployed by changing the NNODES variable (in this exaple we will use 5 nodes). Now we are ready to provision the machines:
53
+
The first step is to download this repo and birng up all the VMs. But first in the Vagrantfile paste your public ssh key in the *CHANGE_ME* variable. You can also adjust the number of the vm deployed by changing the NNODES variable (in this exaple we will use 5 nodes). Now we are ready to provision the machines:
In this guide mysqlsh is used to make operations on MySQL InnoDB Cluster. [Here](https://dev.mysql.com/doc/mysql-shell/8.0/en/) you can find more information about mysqlsh.
250
+
220
251
Now we can finally check our cluster:
221
252
222
253
```
223
254
root@my-ubuntu-0:~# mysqlsh root@my-ubuntu-0
224
255
Please provide the password for 'root@my-ubuntu-0': ******************************************
225
-
Save password for 'root@my-ubuntu-0'? [Y]es/[N]o/Ne[v]er (default No):
226
-
MySQL Shell 8.0.30
227
-
228
-
Copyright (c) 2016, 2022, Oracle and/or its affiliates.
229
-
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
230
-
Other names may be trademarks of their respective owners.
231
-
232
-
Type '\help' or '\?' for help; '\quit' to exit.
233
-
Creating a session to 'root@my-ubuntu-0'
234
-
Fetching schema names for autocompletion... Press ^C to stop.
235
-
Your MySQL connection id is 75 (X protocol)
236
-
Server version: 8.0.30 MySQL Community Server - GPL
237
-
No default schema selected; type \use <schema> to set one.
238
256
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
239
-
<Cluster:cluster_lab>
240
257
MySQL localhost:33060+ ssl JS > clu.status()
241
258
{
242
259
"clusterName": "cluster_lab",
@@ -309,25 +326,23 @@ MySQL localhost:33060+ ssl JS > clu.status()
309
326
To test the cluster we can use a sample Docker compose stack, the example uses:
310
327
311
328
* Wordpress as frontend
312
-
*[mysqlrouter](https://github.com/garutilorenzo/mysqlrouter)to connect Wordpress to Mysql Innodb cluster
329
+
*[mysqlrouter](https://github.com/garutilorenzo/mysqlrouter)will connect WP to MySQL
313
330
314
331
To run this test you have to install [Docker](https://docs.docker.com/get-docker/) and [Docker compose](https://docs.docker.com/compose/install/).
315
332
316
333
#### User and Database creation
317
334
318
-
We need to create on db and one user for wordpress, to do this we have to find the primary server (check the cluster status and find the node with -> "mode": "R/W")
335
+
We need to create one db and one user for wordpress, to do this we have to find the primary server (check the cluster status and find the node with -> "mode": "R/W")
319
336
320
337
```
321
-
mysqlsh root@localhost
338
+
root@my-ubuntu-0:~# mysqlsh root@localhost
322
339
Please provide the password for 'root@localhost': ******************************************
323
-
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No):
324
-
MySQL Shell 8.0.30
325
340
326
341
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
327
342
Switching to SQL mode... Commands end with ;
328
343
329
344
create database wordpress;
330
-
create user 'wordpress'@'%' identified with 'wordpress';
345
+
create user 'wordpress'@'%' identified by 'wordpress';
331
346
grant all on wordpress.* TO 'wordpress'@'%';
332
347
flush privileges;
333
348
```
@@ -448,36 +463,43 @@ Install and configure WP, and now we are ready for some [Chaos Monkey](https://n
448
463
449
464
#### Simulate disaster
450
465
451
-
We can now shutdown the RW node (in this case my-ubuntu-0):
466
+
To test WP reachability we can start this simple test:
467
+
468
+
469
+
```
470
+
while true; do curl -s -o /dev/null -w "%{http_code}" http://localhost; echo; sleep 1; done
471
+
200
472
+
200
473
+
474
+
```
475
+
476
+
now shutdown the RW node (in this case my-ubuntu-0):
452
477
453
478
```
454
479
root@my-ubuntu-0:~# sudo halt -p
455
480
Connection to 192.168.25.110 closed by remote host.
456
481
Connection to 192.168.25.110 closed.
457
482
```
458
483
459
-
Now we check the cluster status from the second node, and we see that the cluster is still *ONLINE* and can tolerate one more failure:
484
+
and check the output of the test script:
460
485
461
486
```
462
-
root@my-ubuntu-1:~# mysqlsh root@localhost
487
+
while true; do curl -s -o /dev/null -w "%{http_code}" http://localhost; echo; sleep 1; done
488
+
200
489
+
500 # <- my-ubuntu-0 shutdown and MySQL primary switch
490
+
200
491
+
200
463
492
464
-
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No):
465
-
MySQL Shell 8.0.30
493
+
```
466
494
467
-
Copyright (c) 2016, 2022, Oracle and/or its affiliates.
468
-
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
469
-
Other names may be trademarks of their respective owners.
495
+
Now we check the cluster status from the second node, and we see that the cluster is still *ONLINE* and can tolerate one more failure:
470
496
471
-
Type '\help' or '\?' for help; '\quit' to exit.
472
-
Creating a session to 'root@localhost'
473
-
Fetching schema names for autocompletion... Press ^C to stop.
474
-
Your MySQL connection id is 2897 (X protocol)
475
-
Server version: 8.0.30 MySQL Community Server - GPL
476
-
No default schema selected; type \use <schema> to set one.
497
+
```
498
+
root@my-ubuntu-1:~# mysqlsh root@localhost
499
+
Please provide the password for 'root@localhost': ******************************************
477
500
478
-
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
479
-
<Cluster:cluster_lab>
480
-
MySQL localhost:33060+ ssl JS > clu.status()
501
+
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
502
+
MySQL localhost:33060+ ssl JS > clu.status()
481
503
{
482
504
"clusterName": "cluster_lab",
483
505
"defaultReplicaSet": {
@@ -549,20 +571,7 @@ Now if we bring up again the *my-ubuntu-0* node, the node wil rejoin the cluster
549
571
550
572
```
551
573
root@my-ubuntu-1:~# mysqlsh root@localhost
552
-
553
-
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No):
554
-
MySQL Shell 8.0.30
555
-
556
-
Copyright (c) 2016, 2022, Oracle and/or its affiliates.
557
-
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
558
-
Other names may be trademarks of their respective owners.
559
-
560
-
Type '\help' or '\?' for help; '\quit' to exit.
561
-
Creating a session to 'root@localhost'
562
-
Fetching schema names for autocompletion... Press ^C to stop.
563
-
Your MySQL connection id is 2897 (X protocol)
564
-
Server version: 8.0.30 MySQL Community Server - GPL
565
-
No default schema selected; type \use <schema> to set one.
574
+
Please provide the password for 'root@localhost': ******************************************
566
575
567
576
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
568
577
MySQL localhost:33060+ ssl JS > clu.status()
@@ -639,7 +648,7 @@ If for any reason all the servers went down, the cluster has to be restored from
639
648
To do this we have to connect to one instance, edit /etc/mysql/mysql.conf.d/innodb_cluster.cnf and set *group_replication_bootstrap_group* to *ON* and comment *group_replication_group_seeds*. We have now to restart MySQL:
640
649
641
650
```
642
-
vagrant@my-ubuntu-0:~$ mysqlsh root@localhost
651
+
vagrant@my-ubuntu-0:~$
643
652
vi /etc/mysql/mysql.conf.d/innodb_cluster.cnf
644
653
645
654
group_replication_bootstrap_group=on
@@ -653,8 +662,6 @@ For all the other (four) members we have to start the group replication:
653
662
```
654
663
vagrant@my-ubuntu-4:~$ mysqlsh root@localhost
655
664
Please provide the password for 'root@localhost': ******************************************
656
-
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No):
657
-
MySQL Shell 8.0.30
658
665
659
666
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
If the traffic on the cluster was low or absent the cluster will be ONLINE:
666
673
667
674
```
668
-
MySQL localhost:33060+ ssl SQL > \js
675
+
MySQL localhost:33060+ ssl SQL > \js
669
676
Switching to JavaScript mode...
670
-
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
671
-
<Cluster:cluster_lab>
672
-
MySQL localhost:33060+ ssl JS > clu.status()
677
+
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
678
+
MySQL localhost:33060+ ssl JS > clu.status()
673
679
{
674
680
"clusterName": "cluster_lab",
675
681
"defaultReplicaSet": {
@@ -736,10 +742,9 @@ Switching to JavaScript mode...
736
742
}
737
743
```
738
744
739
-
If the cluster has a high volume traffic at the moment of the complete outage you have to probably run form mysqlsh:
745
+
If the cluster has a high volume traffic at the moment of the [complete outage](https://dev.mysql.com/doc/mysql-shell/8.0/en/troubleshooting-innodb-cluster.html). you have to probably run form mysqlsh:
740
746
741
747
```
742
-
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
743
748
MySQL localhost:33060+ ssl JS > var clu = dba.rebootClusterFromCompleteOutage();
0 commit comments