Refs #8140: MariaDB Server Deploy - Role WIP

This commit is contained in:
Xavi Lleó 2024-12-16 15:42:53 +01:00
parent 2cf5358d61
commit a58386259c
12 changed files with 77 additions and 39 deletions

View File

@ -1,2 +1,6 @@
mariadb_base_packages:
- mariadb-server
- mariadb-backup
mariadb_requeriments:
- curl
- apt-transport-https

View File

@ -1,3 +1,4 @@
[Service]
LimitNOFILE=600000
LimitMEMLOCK=2M
LimitNOFILE=81035

0
roles/services/files/scripts/check-memory.sh Normal file → Executable file
View File

0
roles/services/files/scripts/export-privs.sh Normal file → Executable file
View File

0
roles/services/files/scripts/mysqltuner.pl Normal file → Executable file
View File

0
roles/services/files/scripts/promote-master.sh Normal file → Executable file
View File

0
roles/services/files/scripts/promote-slave.sh Normal file → Executable file
View File

0
roles/services/files/scripts/scheduler-log.sh Normal file → Executable file
View File

0
roles/services/files/scripts/sync-conf.sh Normal file → Executable file
View File

View File

@ -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

View File

@ -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

View File

@ -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