Merge branch '2225-mysqltuner' into unstable
This commit is contained in:
commit
09aa8ebe01
|
@ -18,4 +18,7 @@ mysql_innodb_buffer_pool_size: '{{ (ansible_memtotal_mb * 0.3) | int }}M'
|
||||||
mysql_cron_optimize: True
|
mysql_cron_optimize: True
|
||||||
mysql_cron_optimize_frequency: weekly
|
mysql_cron_optimize_frequency: weekly
|
||||||
|
|
||||||
|
mysql_cron_mysqltuner: True
|
||||||
|
mysql_cron_mysqltuner_frequency: monthly
|
||||||
|
|
||||||
mysql_force_new_nrpe_password: False
|
mysql_force_new_nrpe_password: False
|
||||||
|
|
50
mysql/files/mysqltuner.cron.sh
Normal file
50
mysql/files/mysqltuner.cron.sh
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
export TERM=screen
|
||||||
|
|
||||||
|
mem=$(free -m | grep Mem: | tr -s ' ' | cut -d ' ' -f2)
|
||||||
|
swap=$(free -m | grep Swap: | tr -s ' ' | cut -d ' ' -f2)
|
||||||
|
template=$(mktemp --tmpdir=/tmp evomysqltuner.XXX)
|
||||||
|
body=$(mktemp --tmpdir=/tmp evomysqltuner.XXX)
|
||||||
|
clientmail=$(grep EVOMAINTMAIL /etc/evomaintenance.cf | cut -d'=' -f2)
|
||||||
|
hostname=$(grep HOSTNAME /etc/evomaintenance.cf | cut -d'=' -f2)
|
||||||
|
hostname=${hostname%%.evolix.net}
|
||||||
|
# If hostname is composed with -, remove the first part.
|
||||||
|
if [[ $hostname =~ "-" ]]; then
|
||||||
|
hostname=$(echo $hostname | cut -d'-' -f2-)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove temporary files on exit.
|
||||||
|
trap "rm $template $body" EXIT
|
||||||
|
|
||||||
|
# Add port here if you have more than one instance!
|
||||||
|
instances="3306"
|
||||||
|
for instance in $instances; do
|
||||||
|
mysqltuner --port $instance --host 127.0.0.1 --forcemem $mem --forceswap $swap \
|
||||||
|
| aha > /var/www/mysqlreport_${instance}.html
|
||||||
|
cat << EOT > $template
|
||||||
|
Content-Type: text/plain; charset="utf-8"
|
||||||
|
Reply-To: Équipe Evolix <equipe@evolix.fr>
|
||||||
|
From: Équipe Evolix <equipe@evolix.net>
|
||||||
|
To: $clientmail
|
||||||
|
Subject: Rapport MySQL instance $instance pour votre serveur $hostname
|
||||||
|
EOT
|
||||||
|
cat << EOT > $body
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
Veuillez trouver ci-joint un rapport MySQL.
|
||||||
|
Celui-ci permet d'identifier aisément si des optimisations MySQL sont possibles.
|
||||||
|
|
||||||
|
N'hésitez pas à nous indiquer par mail ou ticket quelles variables vous souhaiter
|
||||||
|
optimiser.
|
||||||
|
|
||||||
|
Veuillez noter qu'il faudra redémarrer MySQL pour appliquer de nouveaux paramètres.
|
||||||
|
|
||||||
|
Bien à vous,
|
||||||
|
--
|
||||||
|
Rapport automatique Evolix
|
||||||
|
EOT
|
||||||
|
mutt -x -e 'set send_charset="utf-8"' -H $template \
|
||||||
|
-a /var/www/mysqlreport_${instance}.html < $body
|
||||||
|
done
|
||||||
|
chmod 644 /var/www/mysqlreport*html
|
|
@ -13,6 +13,8 @@
|
||||||
template:
|
template:
|
||||||
src: log2mail.j2
|
src: log2mail.j2
|
||||||
dest: /etc/log2mail/config/mysql.conf
|
dest: /etc/log2mail/config/mysql.conf
|
||||||
|
owner: log2mail
|
||||||
|
group: adm
|
||||||
mode: "0640"
|
mode: "0640"
|
||||||
when: log2mail_config_dir.stat.exists
|
when: log2mail_config_dir.stat.exists
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- include: packages.yml
|
- include: packages_stretch.yml
|
||||||
|
when: ansible_distribution_release == "stretch"
|
||||||
|
|
||||||
|
- include: packages_jessie.yml
|
||||||
|
when: ansible_distribution_release == "jessie"
|
||||||
|
|
||||||
- include: users_stretch.yml
|
- include: users_stretch.yml
|
||||||
when: ansible_distribution_release == "stretch"
|
when: ansible_distribution_release == "stretch"
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create a password for NRPE
|
- name: Create a password for NRPE
|
||||||
shell: perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'
|
command: "apg -n 1 -m 16 -M lcN"
|
||||||
register: mysql_nrpe_password
|
register: mysql_nrpe_password
|
||||||
changed_when: False
|
changed_when: False
|
||||||
|
|
||||||
|
|
37
mysql/tasks/packages_stretch.yml
Normal file
37
mysql/tasks/packages_stretch.yml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: Choose packages
|
||||||
|
set_fact:
|
||||||
|
mysql_packages: "{{ item }}"
|
||||||
|
with_items:
|
||||||
|
- mariadb-server
|
||||||
|
- mariadb-client
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
- packages
|
||||||
|
|
||||||
|
- name: Install MySQL packages
|
||||||
|
apt:
|
||||||
|
name: '{{ item }}'
|
||||||
|
update_cache: yes
|
||||||
|
state: present
|
||||||
|
with_items: "{{ mysql_packages }}"
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
- packages
|
||||||
|
|
||||||
|
- name: MySQL is started
|
||||||
|
service:
|
||||||
|
name: mysql
|
||||||
|
state: started
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
- services
|
||||||
|
|
||||||
|
- name: apg package is installed
|
||||||
|
apt:
|
||||||
|
name: apg
|
||||||
|
state: present
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
- packages
|
|
@ -10,7 +10,7 @@
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
- name: create a password for mysqladmin
|
- name: create a password for mysqladmin
|
||||||
shell: perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'
|
command: "apg -n 1 -m 16 -M lcN"
|
||||||
register: mysql_admin_password
|
register: mysql_admin_password
|
||||||
changed_when: False
|
changed_when: False
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
- name: create a password for mysqladmin
|
- name: create a password for mysqladmin
|
||||||
shell: perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'
|
command: "apg -n 1 -m 16 -M lcN"
|
||||||
register: mysql_admin_password
|
register: mysql_admin_password
|
||||||
changed_when: False
|
changed_when: False
|
||||||
tags:
|
tags:
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
|
|
||||||
- name: create a password for debian-sys-maint
|
- name: create a password for debian-sys-maint
|
||||||
shell: perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'
|
command: "apg -n 1 -m 16 -M lcN"
|
||||||
register: mysql_debian_password
|
register: mysql_debian_password
|
||||||
changed_when: False
|
changed_when: False
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: Ensure /usr/share/scripts exists
|
- name: Ensure scripts directory exists
|
||||||
file:
|
file:
|
||||||
dest: /usr/share/scripts
|
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}"
|
||||||
mode: "0700"
|
mode: "0700"
|
||||||
state: directory
|
state: directory
|
||||||
tags:
|
tags:
|
||||||
|
@ -52,13 +52,17 @@
|
||||||
when: (mysql_scripts_dir or general_scripts_dir) | search ("/usr")
|
when: (mysql_scripts_dir or general_scripts_dir) | search ("/usr")
|
||||||
|
|
||||||
- name: Install mysqltuner
|
- name: Install mysqltuner
|
||||||
copy:
|
# copy:
|
||||||
src: mysqltuner.pl
|
# src: mysqltuner.pl
|
||||||
dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/mysqltuner.pl"
|
# dest: "{{ mysql_scripts_dir or general_scripts_dir | mandatory }}/mysqltuner.pl"
|
||||||
mode: "0700"
|
# mode: "0700"
|
||||||
|
apt:
|
||||||
|
name: mysqltuner
|
||||||
|
state: present
|
||||||
tags:
|
tags:
|
||||||
- mysql
|
- mysql
|
||||||
- mysqltuner
|
- mysqltuner
|
||||||
|
- mysqltuner
|
||||||
|
|
||||||
- name: Install aha
|
- name: Install aha
|
||||||
apt:
|
apt:
|
||||||
|
@ -79,7 +83,7 @@
|
||||||
tags:
|
tags:
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
- name: "Cron dir is present"
|
- name: "Cron dir for optimize is present"
|
||||||
file:
|
file:
|
||||||
path: "/etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}"
|
path: "/etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
@ -98,12 +102,36 @@
|
||||||
|
|
||||||
- name: "Disable cron to optimize MySQL"
|
- name: "Disable cron to optimize MySQL"
|
||||||
file:
|
file:
|
||||||
dest: /etc/cron.weekly/mysql-optimize.sh
|
dest: /etc/cron.{{ mysql_cron_optimize_frequency | mandatory }}/mysql-optimize.sh
|
||||||
state: absent
|
state: absent
|
||||||
when: not mysql_cron_optimize
|
when: not mysql_cron_optimize
|
||||||
tags:
|
tags:
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
|
- name: "Cron dir for mysqltuner is present"
|
||||||
|
file:
|
||||||
|
path: "/etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}"
|
||||||
|
state: directory
|
||||||
|
mode: "0755"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
|
||||||
|
- name: "Enable mysqltuner in cron"
|
||||||
|
copy:
|
||||||
|
src: mysqltuner.cron.sh
|
||||||
|
dest: /etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}/mysqltuner.sh
|
||||||
|
when: mysql_cron_mysqltuner
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
|
||||||
|
- name: "Disable mysqltuner in cron"
|
||||||
|
file:
|
||||||
|
dest: /etc/cron.{{ mysql_cron_mysqltuner_frequency | mandatory }}/mysqltuner.sh
|
||||||
|
state: absent
|
||||||
|
when: not mysql_cron_mysqltuner
|
||||||
|
tags:
|
||||||
|
- mysql
|
||||||
|
|
||||||
# my-add.sh
|
# my-add.sh
|
||||||
|
|
||||||
- include: remount_usr_rw.yml
|
- include: remount_usr_rw.yml
|
||||||
|
|
Loading…
Reference in a new issue