Skip to content

Commit ec02a1d

Browse files
committed
Updated README
1 parent 10fc089 commit ec02a1d

File tree

1 file changed

+67
-62
lines changed

1 file changed

+67
-62
lines changed

README.md

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,48 @@ This role will install and configure MySQL server or MySQL in HA mode using [MyS
99

1010
## Table of Contents
1111

12+
* [Role Variables](#role-variables)
1213
* [Vagrant up, build the test infrastructure](#vagrant-up-build-the-test-infrastructure)
1314
* [Ansible setup and pre-flight check](#ansible-setup-and-pre-flight-check)
1415
* [Deploy MySQL InnoDB Cluster ](#deploy-mysql-innodb-cluster)
1516
* [Cluster high availability check](#cluster-high-availability-check)
1617
* [Restore from complete outage](#restore-from-complete-outage)
1718
* [Clean up](#clean-up)
1819

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 |
43+
| `mysql_replication_mode` | `no` | `` | [InnoDB Cluster](https://dev.mysql.com/doc/refman/8.0/en/mysql-innodb-cluster-introduction.html), [GTID](https://dev.mysql.com/doc/mysql-replication-excerpt/5.6/en/replication-gtids.html), Empty/None (default) |
44+
45+
| `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 |
1948

2049
### Vagrant up, build the test infrastructure
2150

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.
2352

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:
2554

2655
```
2756
git clone https://github.com/garutilorenzo/ansible-role-linux-mysql.git
@@ -217,26 +246,14 @@ my-ubuntu-3 : ok=30 changed=0 unreachable=0 failed=0 sk
217246
my-ubuntu-4 : ok=30 changed=0 unreachable=0 failed=0 skipped=18 rescued=0 ignored=0
218247
```
219248
249+
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+
220251
Now we can finally check our cluster:
221252
222253
```
223254
root@my-ubuntu-0:~# mysqlsh root@my-ubuntu-0
224255
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.
238256
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
239-
<Cluster:cluster_lab>
240257
MySQL localhost:33060+ ssl JS > clu.status()
241258
{
242259
"clusterName": "cluster_lab",
@@ -309,25 +326,23 @@ MySQL localhost:33060+ ssl JS > clu.status()
309326
To test the cluster we can use a sample Docker compose stack, the example uses:
310327

311328
* 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
313330

314331
To run this test you have to install [Docker](https://docs.docker.com/get-docker/) and [Docker compose](https://docs.docker.com/compose/install/).
315332

316333
#### User and Database creation
317334

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")
319336

320337
```
321-
mysqlsh root@localhost
338+
root@my-ubuntu-0:~# mysqlsh root@localhost
322339
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
325340
326341
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
327342
Switching to SQL mode... Commands end with ;
328343
329344
create database wordpress;
330-
create user 'wordpress'@'%' identified with 'wordpress';
345+
create user 'wordpress'@'%' identified by 'wordpress';
331346
grant all on wordpress.* TO 'wordpress'@'%';
332347
flush privileges;
333348
```
@@ -448,36 +463,43 @@ Install and configure WP, and now we are ready for some [Chaos Monkey](https://n
448463

449464
#### Simulate disaster
450465

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):
452477

453478
```
454479
root@my-ubuntu-0:~# sudo halt -p
455480
Connection to 192.168.25.110 closed by remote host.
456481
Connection to 192.168.25.110 closed.
457482
```
458483

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:
460485

461486
```
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
463492
464-
Save password for 'root@localhost'? [Y]es/[N]o/Ne[v]er (default No):
465-
MySQL Shell 8.0.30
493+
```
466494

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:
470496

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': ******************************************
477500
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()
481503
{
482504
"clusterName": "cluster_lab",
483505
"defaultReplicaSet": {
@@ -549,20 +571,7 @@ Now if we bring up again the *my-ubuntu-0* node, the node wil rejoin the cluster
549571

550572
```
551573
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': ******************************************
566575
567576
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
568577
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
639648
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:
640649

641650
```
642-
vagrant@my-ubuntu-0:~$ mysqlsh root@localhost
651+
vagrant@my-ubuntu-0:~$
643652
vi /etc/mysql/mysql.conf.d/innodb_cluster.cnf
644653
645654
group_replication_bootstrap_group=on
@@ -653,8 +662,6 @@ For all the other (four) members we have to start the group replication:
653662
```
654663
vagrant@my-ubuntu-4:~$ mysqlsh root@localhost
655664
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
658665
659666
MySQL localhost:33060+ ssl JS > \sql # <- SWITCH TO SQL MODE
660667
Switching to SQL mode... Commands end with ;
@@ -665,11 +672,10 @@ Query OK, 0 rows affected (1.7095 sec)
665672
If the traffic on the cluster was low or absent the cluster will be ONLINE:
666673

667674
```
668-
MySQL localhost:33060+ ssl SQL > \js
675+
MySQL localhost:33060+ ssl SQL > \js
669676
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()
673679
{
674680
"clusterName": "cluster_lab",
675681
"defaultReplicaSet": {
@@ -736,10 +742,9 @@ Switching to JavaScript mode...
736742
}
737743
```
738744

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:
740746

741747
```
742-
MySQL localhost:33060+ ssl JS > clu = dba.getCluster()
743748
MySQL localhost:33060+ ssl JS > var clu = dba.rebootClusterFromCompleteOutage();
744749
```
745750

0 commit comments

Comments
 (0)