From a58386259c149f04d53a15a51f6e618d0271f356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Lle=C3=B3=20Tom=C3=A1s?= Date: Mon, 16 Dec 2024 15:42:53 +0100 Subject: [PATCH] Refs #8140: MariaDB Server Deploy - Role WIP --- roles/services/defaults/main.yaml | 8 +- roles/services/files/mariadb_override.conf | 1 + roles/services/files/scripts/check-memory.sh | 0 roles/services/files/scripts/export-privs.sh | 0 roles/services/files/scripts/mysqltuner.pl | 0 .../services/files/scripts/promote-master.sh | 0 roles/services/files/scripts/promote-slave.sh | 0 roles/services/files/scripts/scheduler-log.sh | 0 roles/services/files/scripts/sync-conf.sh | 0 roles/services/files/z90-vn.cnf | 1 - roles/services/handlers/main.yml | 8 +- roles/services/tasks/mariadb.yml | 98 ++++++++++++------- 12 files changed, 77 insertions(+), 39 deletions(-) mode change 100644 => 100755 roles/services/files/scripts/check-memory.sh mode change 100644 => 100755 roles/services/files/scripts/export-privs.sh mode change 100644 => 100755 roles/services/files/scripts/mysqltuner.pl mode change 100644 => 100755 roles/services/files/scripts/promote-master.sh mode change 100644 => 100755 roles/services/files/scripts/promote-slave.sh mode change 100644 => 100755 roles/services/files/scripts/scheduler-log.sh mode change 100644 => 100755 roles/services/files/scripts/sync-conf.sh diff --git a/roles/services/defaults/main.yaml b/roles/services/defaults/main.yaml index 139597f..c326c4f 100644 --- a/roles/services/defaults/main.yaml +++ b/roles/services/defaults/main.yaml @@ -1,2 +1,6 @@ - - +mariadb_base_packages: + - mariadb-server + - mariadb-backup +mariadb_requeriments: + - curl + - apt-transport-https \ No newline at end of file diff --git a/roles/services/files/mariadb_override.conf b/roles/services/files/mariadb_override.conf index 678e16a..215c342 100644 --- a/roles/services/files/mariadb_override.conf +++ b/roles/services/files/mariadb_override.conf @@ -1,3 +1,4 @@ [Service] LimitNOFILE=600000 LimitMEMLOCK=2M +LimitNOFILE=81035 \ No newline at end of file diff --git a/roles/services/files/scripts/check-memory.sh b/roles/services/files/scripts/check-memory.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/export-privs.sh b/roles/services/files/scripts/export-privs.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/mysqltuner.pl b/roles/services/files/scripts/mysqltuner.pl old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/promote-master.sh b/roles/services/files/scripts/promote-master.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/promote-slave.sh b/roles/services/files/scripts/promote-slave.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/scheduler-log.sh b/roles/services/files/scripts/scheduler-log.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/scripts/sync-conf.sh b/roles/services/files/scripts/sync-conf.sh old mode 100644 new mode 100755 diff --git a/roles/services/files/z90-vn.cnf b/roles/services/files/z90-vn.cnf index 3b4c5cd..0f6a716 100644 --- a/roles/services/files/z90-vn.cnf +++ b/roles/services/files/z90-vn.cnf @@ -116,5 +116,4 @@ performance_schema = ON performance_schema_digests_size = 20000 performance-schema-consumer-events-statements-history = ON performance_schema_consumer_events_statements_history_long = ON -query_response_time_stats = ON userstat = ON diff --git a/roles/services/handlers/main.yml b/roles/services/handlers/main.yml index c5b90a5..77780d8 100644 --- a/roles/services/handlers/main.yml +++ b/roles/services/handlers/main.yml @@ -2,10 +2,12 @@ systemd: name: chrony state: restarted -- name: restart-mariadb - systemd: - name: mariadb - name: reload systemd command: cmd: systemctl daemon-reload +- name: restart-mariadb + systemd: + name: mariadb + state: restarted + diff --git a/roles/services/tasks/mariadb.yml b/roles/services/tasks/mariadb.yml index 8b1bde2..514f8b4 100644 --- a/roles/services/tasks/mariadb.yml +++ b/roles/services/tasks/mariadb.yml @@ -1,8 +1,29 @@ +# Percona things pmm2-client https://docs.percona.com/percona-monitoring-and-management/setting-up/client/index.html#package-manager +# Add backup directory custom scripts + +- name: Ensure Install requirements for MariaDB repository setup script + apt: + name: "{{ mariadb_requeriments }}" + state: present + install_recommends: no + +- name: Download MariaDB repository setup script + get_url: + url: "https://r.mariadb.com/downloads/mariadb_repo_setup" + dest: "/tmp/mariadb_repo_setup" + mode: "u=rwx,g=rx,o=rx" + +- name: Run MariaDB repository setup script + command: + cmd: "/bin/bash /tmp/mariadb_repo_setup --mariadb-server-version=10.11.10" + creates: "/etc/apt/sources.list.d/mariadb.list" + - name: Install MariaDB packages apt: - name: mariadb-server + name: "{{ mariadb_base_packages }}" state: present - #install_recommends: no + install_recommends: no + - name: Ensure required directories exist file: path: "{{ item.path }}" @@ -11,33 +32,16 @@ group: "{{ item.group }}" mode: "{{ item.mode }}" loop: - - { path: /var/log/mysql, owner: mysql, group: adm, mode: 'u=rwx,g=rxs,o=' } - - { path: /root/scripts, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } + - { path: /mnt/local-backup, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } - { path: /mnt/mysqlbin, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } - - { path: /etc/systemd/system/mariadb.service.d, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } - { path: /mnt/mysqltmp, owner: root, group: root, mode: 'u=rwx,g=rwx,o=rwxt' } - { path: /mnt/mysqlbin/binlog, owner: mysql, group: mysql, mode: 'u=rwx,g=,o=' } -- name: Set MariaDB custom configuration - copy: - src: "{{ item }}" - dest: /etc/mysql/mariadb.conf.d/ - owner: root - group: root - mode: u=rw,g=r,o=r - with_fileglob: - - "files/z9*.cnf" - notify: restart-mariadb -- name: Set MariaDB custom root scripts - copy: - src: "{{ item }}" - dest: /root/scripts/ - owner: root - group: root - mode: u=rwx,g=rx,o=rx - with_fileglob: - - "files/scripts/*.sh" + - { path: /var/log/mysql, owner: mysql, group: adm, mode: 'u=rwx,g=rxs,o=' } + - { path: /root/scripts, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx'} + - { path: /etc/systemd/system/mariadb.service.d, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } + - name: Ensure required files are copied to their destinations - ansible.builtin.copy: + copy: src: "{{ item.src }}" dest: "{{ item.dest }}" owner: root @@ -47,8 +51,29 @@ - { src: 'files/scripts/README.md', dest: '/root/scripts/README.md', mode: 'u=rw,g=r,o=r' } - { src: 'mariadb_override.conf', dest: '/etc/systemd/system/mariadb.service.d/override.conf', mode: 'u=rw,g=r,o=r' } - { src: 'files/scripts/mysqltuner.pl', dest: '/root/scripts/mysqltuner.pl', mode: 'u=rwx,g=rx,o=rx' } - notify: - - reload systemd + notify: reload systemd + +- name: Set MariaDB custom root scripts + copy: + src: "{{ item }}" + dest: /root/scripts/ + owner: root + group: root + mode: u=rwx,g=rx,o=rx + with_fileglob: + - "files/scripts/*.sh" + +- name: Add tmpfs in /etc/fstab + blockinfile: + path: /etc/fstab + marker: "# {mark} ANSIBLE-MANAGED TMPFS ENTRY" + block: | + tmpfs /mnt/mysqltmp tmpfs rw,size=6144M 0 0 + +- name: Mount all filesystems from /etc/fstab + command: mount -a + #when: ansible_facts.mounts | selectattr('mount', 'equalto', '/mnt/mysqltmp') | list | length == 0 + - name: Set MariaDB Cron to /etc/cron.d template: src: templates/cron_mariadb @@ -56,12 +81,7 @@ owner: root group: root mode: u=rw,g=r,o=r -- name: Add tmpfs in /etc/fstab - blockinfile: - path: /etc/fstab - marker: "# {mark} ANSIBLE-MANAGED TMPFS ENTRY" - block: | - tmpfs /mnt/mysqltmp tmpfs rw,size=6144M 0 0 + - name: Insert MySQL certificates copy: content: "{{ item.content }}" @@ -73,3 +93,15 @@ - { content: '{{ ca_mysql }}', dest: '/etc/mysql/ca.pem', mode: 'u=rw,g=r,o=r' } - { content: '{{ cert_mysql }}', dest: '/etc/mysql/cert.pem', mode: 'u=rw,g=r,o=r' } - { content: '{{ private_mysql }}', dest: '/etc/mysql/key.pem', mode: 'u=rw,g=,o=' } + notify: restart-mariadb + +- name: Set MariaDB custom configuration + copy: + src: "{{ item }}" + dest: /etc/mysql/mariadb.conf.d/ + owner: root + group: root + mode: u=rw,g=r,o=r + with_fileglob: + - "files/z9*.cnf" + notify: restart-mariadb \ No newline at end of file