mysql8_innodb_cluster

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
mysql8_innodb_cluster [2024/06/22 15:49] andonovjmysql8_innodb_cluster [2024/06/25 13:40] (current) andonovj
Line 37: Line 37:
  
       - name: Stop firewall       - name: Stop firewall
-        ansible.builtin.command: service firewalld stop+        service
 +          name: firewalld 
 +          state: stopped
 </Code> </Code>
  
Line 65: Line 67:
         shell: |         shell: |
           temporal_password=`awk '/A temporary password is generated for/ {a=$0} END{ print a }' /var/log/mysqld.log | awk '{print $(NF)}'`           temporal_password=`awk '/A temporary password is generated for/ {a=$0} END{ print a }' /var/log/mysqld.log | awk '{print $(NF)}'`
 +          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 'root'@'localhost' IDENTIFIED BY '{{ root_password }}';flush privileges; " --connect-expired-password           mysql -uroot -p${temporal_password} -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ root_password }}';flush privileges; " --connect-expired-password
           echo "[client]           echo "[client]
Line 80: Line 83:
           name: mysqld           name: mysqld
           state: stopped           state: stopped
- 
-      - name: Template the my.cnf 
-        template: 
-          dest: "/etc/my.cnf" 
-          src: templates/my.cnf.js.j2 
-          owner: "root" 
-          group: "root" 
-          mode: '0644' 
  
       - 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: "{{ groups['dbservers'][1:] }}"           secondary_nodes: "{{ groups['dbservers'][1:] }}"
 +
 +      - 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 /tmp/bootstrap_cluster.js         command: mysqlsh -f /tmp/bootstrap_cluster.js
 +
 +      - name: Wait to start
 +        wait_for:
 +          timeout: 5
  
       - name: Add the other instances       - name: Add the other instances
         command: mysqlsh -f /tmp/add_instances.js         command: mysqlsh -f /tmp/add_instances.js
-        when: inventory_hostname in "{{ primary_node }}"+        when: inventory_hostname == groups['dbservers'][0]
 </Code> </Code>
  
Line 198: Line 201:
  
 #bootstrap.js.j2 #bootstrap.js.j2
-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('mysql')+var mysql = require('mysql');
  
-try { +try{ 
-    var session = mysql.getClassicSession('root@localhost', '{{ root_password }}') +   dba.configureInstance('root@localhost', { 
-    session.runSql("create user '{{ cluster_user }}' identified by '{{ cluster_user_password }}'") +    password: `${root_password}`, 
-    session.runSql("GRANT ALL PRIVILEGES ON *.* TO {{ cluster_user }}@'%' WITH GRANT OPTION")+    restart: true, 
 +    interactive: false, 
 +    clusterAdmin: '{{ cluster_user }}'
 +    clusterAdminPassword: `${cluster_user_password}` 
 +  });
 } catch(e){ } catch(e){
-    print('\n The innodb cluster admin user could not be created\n' + e.message + '\n')+    print('\n The innodb cluster admin user could not be created\n' + e.message + '\n');
 } }
  
Line 219: Line 228:
 var secondary_nodes = secondary_nodes.replaceAll("u","").replaceAll("'","\"").replaceAll("\"","").replaceAll("[","").replaceAll("]","").replaceAll(" ","").split(','); var secondary_nodes = secondary_nodes.replaceAll("u","").replaceAll("'","\"").replaceAll("\"","").replaceAll("[","").replaceAll("]","").replaceAll(" ","").split(',');
  
-var mysql = require('mysql')+var mysql = require('mysql');
  
 try { try {
Line 308: Line 317:
 We see that the node is down. So let's try to simulate a restoration of the connection: We see that the node is down. So let's try to simulate a restoration of the connection:
  
-<Code:bash|Restore connection to the node>+<Code:bash|Start the service> 
 +[root@mysql-cluster-b ~]# service mysqld start 
 +Redirecting to /bin/systemctl start mysqld.service 
 +[root@mysql-cluster-b ~]# 
 +</Code> 
 + 
 +Now we can check again: 
 + 
 +<Code:bash|Check again>
 { {
     "clusterName": "InnoDBCluster",     "clusterName": "InnoDBCluster",
Line 367: Line 384:
 cluster.rescan() cluster.rescan()
 </Code> </Code>
 +
 +
 +====Backup====
 +
 +
 +====Restore====
  • mysql8_innodb_cluster.1719071389.txt.gz
  • Last modified: 2024/06/22 15:49
  • by andonovj