Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
mysql8_innodb_cluster [2024/06/22 15:05] – [Configuration] andonovj | mysql8_innodb_cluster [2024/06/25 13:40] (current) – andonovj | ||
---|---|---|---|
Line 2: | Line 2: | ||
Innodb CLuster is a modern solution to provide group replication for MySQL. In this configuration, | Innodb CLuster is a modern solution to provide group replication for MySQL. In this configuration, | ||
- | {{: | + | {{: |
Of course our IPs will look different because I am waaaay too lazy to care for proper pictures. | Of course our IPs will look different because I am waaaay too lazy to care for proper pictures. | ||
Line 37: | Line 37: | ||
- name: Stop firewall | - name: Stop firewall | ||
- | | + | service: |
+ | name: firewalld | ||
+ | state: stopped | ||
</ | </ | ||
Line 65: | Line 67: | ||
shell: | | shell: | | ||
temporal_password=`awk '/A temporary password is generated for/ {a=$0} END{ print a }' / | temporal_password=`awk '/A temporary password is generated for/ {a=$0} END{ print a }' / | ||
+ | mysql -uroot -p${temporal_password} -e "SET GLOBAL super_read_only = 0; SET GLOBAL read_only = 0; " --connect-expired-password | ||
mysql -uroot -p${temporal_password} -e "ALTER USER ' | mysql -uroot -p${temporal_password} -e "ALTER USER ' | ||
echo " | echo " | ||
Line 80: | Line 83: | ||
name: mysqld | name: mysqld | ||
state: stopped | state: stopped | ||
- | |||
- | - name: Template the my.cnf | ||
- | template: | ||
- | dest: "/ | ||
- | src: templates/ | ||
- | owner: " | ||
- | group: " | ||
- | mode: ' | ||
- name: Define the primary host (e.g. first host in the group) | - name: Define the primary host (e.g. first host in the group) | ||
Line 96: | Line 91: | ||
set_fact: | set_fact: | ||
secondary_nodes: | secondary_nodes: | ||
+ | |||
+ | - name: Get secondary hosts | ||
+ | debug: | ||
+ | var: secondary_nodes | ||
- name: Start MySQL | - name: Start MySQL | ||
Line 120: | Line 119: | ||
- name: Bootstrap the cluster (new deployment) | - name: Bootstrap the cluster (new deployment) | ||
command: mysqlsh -f / | command: mysqlsh -f / | ||
+ | |||
+ | - name: Wait to start | ||
+ | wait_for: | ||
+ | timeout: 5 | ||
- name: Add the other instances | - name: Add the other instances | ||
command: mysqlsh -f / | command: mysqlsh -f / | ||
- | when: inventory_hostname | + | when: inventory_hostname |
</ | </ | ||
Line 198: | Line 201: | ||
# | # | ||
- | var cluster_user_password = "{{ cluster_user_password }}" | + | var cluster_user_password = "{{ cluster_user_password }}"; |
- | var clusterName = "{{ cluster_name }}" | + | var clusterName = "{{ cluster_name }}"; |
- | var secondary_nodes = "{{ secondary_nodes }}" | + | var secondary_nodes = "{{ secondary_nodes }}"; |
+ | var root_password = "{{ root_password }}"; | ||
+ | var cluster_user = "{{ cluster_user }}"; | ||
- | var mysql = require(' | + | var mysql = require(' |
- | try { | + | try{ |
- | var session = mysql.getClassicSession(' | + | dba.configureInstance(' |
- | | + | password: `${root_password}`, |
- | | + | |
+ | interactive: | ||
+ | clusterAdmin: | ||
+ | clusterAdminPassword: | ||
+ | }); | ||
} catch(e){ | } catch(e){ | ||
- | print(' | + | print(' |
} | } | ||
Line 219: | Line 228: | ||
var secondary_nodes = secondary_nodes.replaceAll(" | var secondary_nodes = secondary_nodes.replaceAll(" | ||
- | var mysql = require(' | + | var mysql = require(' |
try { | try { | ||
Line 232: | Line 241: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | |||
+ | =====Management===== | ||
+ | It is all cool and stuff, but let's go through several scenarios with our cluster: | ||
+ | |||
+ | 1. Loss of a member | ||
+ | 2. Backup | ||
+ | 3. Recovery | ||
+ | |||
+ | |||
+ | First thing first, what we do if the connection between the primary and the secondary fails, well we have to rejoin, let's see how. | ||
+ | |||
+ | |||
+ | ====Loss of a member==== | ||
+ | To do that, we will simulate a stop of the service, someone stopped our service :-). | ||
+ | |||
+ | < | ||
+ | [root@mysql-cluster-b ~]# service mysqld stop | ||
+ | Redirecting to / | ||
+ | [root@mysql-cluster-b ~]# | ||
+ | </ | ||
+ | |||
+ | Since our cluster can tolerate one failure, after that, it cannot tolerate anymore: | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | **" | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We see that the node is down. So let's try to simulate a restoration of the connection: | ||
+ | |||
+ | < | ||
+ | [root@mysql-cluster-b ~]# service mysqld start | ||
+ | Redirecting to / | ||
+ | [root@mysql-cluster-b ~]# | ||
+ | </ | ||
+ | |||
+ | Now we can check again: | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Now we see that it is working, if for some reason it doesn' | ||
+ | < | ||
+ | Cluster.rejoinInstance(instance) | ||
+ | cluster.rescan() | ||
+ | </ | ||
+ | |||
+ | It is important that if the UUID was changed, we have to remove the instance from the metadata before adding it: | ||
+ | |||
+ | < | ||
+ | cluster.removeInstance(" | ||
+ | cluster.rescan() | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====Backup==== | ||
+ | |||
+ | |||
+ | ====Restore==== |