Improve log management (#27)
* New log management (see #25) - Add logrotate (as optional feature) setup - Delete obsolete log management (log + log_slow_queries) * Change log pathpull/29/head
parent
c90556976b
commit
589754e618
|
@ -8,6 +8,7 @@ mysql_vendor: 'mariadb'
|
||||||
mysql_root_password: 'change_me_NOW'
|
mysql_root_password: 'change_me_NOW'
|
||||||
mysql_notify_restart: true
|
mysql_notify_restart: true
|
||||||
mysql_upstream_apt_src: false
|
mysql_upstream_apt_src: false
|
||||||
|
mysql_manage_logrotate: true
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
# Configuration
|
# Configuration
|
||||||
|
@ -25,7 +26,7 @@ mysql_socket: '/var/run/mysqld/mysqld.sock'
|
||||||
|
|
||||||
# Slow query log settings.
|
# Slow query log settings.
|
||||||
mysql_slow_query_log_enabled: false
|
mysql_slow_query_log_enabled: false
|
||||||
mysql_slow_query_log_file: '/var/log/mysql-slow.log'
|
mysql_slow_query_log_file: '/var/log/mysql/mysql_slow.log'
|
||||||
mysql_slow_query_time: 2
|
mysql_slow_query_time: 2
|
||||||
|
|
||||||
# Memory settings (default values optimized ~512MB RAM).
|
# Memory settings (default values optimized ~512MB RAM).
|
||||||
|
@ -57,8 +58,7 @@ mysql_innodb_lock_wait_timeout: 50
|
||||||
mysql_mysqldump_max_allowed_packet: '64M'
|
mysql_mysqldump_max_allowed_packet: '64M'
|
||||||
|
|
||||||
# Logging settings.
|
# Logging settings.
|
||||||
mysql_log: ''
|
mysql_log_error: '/var/log/mysql/mysql_error.log'
|
||||||
mysql_log_error: '/var/log/mysql.err'
|
|
||||||
mysql_syslog_tag: 'mysql'
|
mysql_syslog_tag: 'mysql'
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
|
|
|
@ -54,3 +54,9 @@
|
||||||
host="{{ item.host | default('localhost') }}"
|
host="{{ item.host | default('localhost') }}"
|
||||||
state=present
|
state=present
|
||||||
with_items: "{{ mysql_users }}"
|
with_items: "{{ mysql_users }}"
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy logrotate configuration
|
||||||
|
template:
|
||||||
|
src: "etc/logrotate.d/mysql-server.j2"
|
||||||
|
dest: "/etc/logrotate.d/mysql-server"
|
||||||
|
when: mysql_manage_logrotate
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
# - I put everything in one block and added sharedscripts, so that mysql gets
|
||||||
|
# flush-logs'd only once.
|
||||||
|
# Else the binary logs would automatically increase by n times every day.
|
||||||
|
# - The error log is obsolete, messages go to syslog now.
|
||||||
|
{{ mysql_log_error }} {% if mysql_slow_query_log_enabled %}{{ mysql_slow_query_log_file }}{% endif %} {
|
||||||
|
daily
|
||||||
|
rotate 7
|
||||||
|
missingok
|
||||||
|
create 640 mysql adm
|
||||||
|
compress
|
||||||
|
sharedscripts
|
||||||
|
postrotate
|
||||||
|
test -x /usr/bin/mysqladmin || exit 0
|
||||||
|
if [ -f `my_print_defaults --mysqld | grep -m 1 -oP "pid-file=\K.+$"` ]; then
|
||||||
|
# If this fails, check debian.conf!
|
||||||
|
mysqladmin --defaults-file=/etc/mysql/debian.cnf --local flush-error-log \
|
||||||
|
flush-engine-log flush-general-log flush-slow-log
|
||||||
|
fi
|
||||||
|
endscript
|
||||||
|
}
|
|
@ -14,21 +14,15 @@ socket = {{ mysql_socket }}
|
||||||
|
|
||||||
{# TODO: FIX later #}
|
{# TODO: FIX later #}
|
||||||
# Logging configuration.
|
# Logging configuration.
|
||||||
{% if mysql_log_error == 'syslog' or mysql_log == 'syslog' %}
|
{% if mysql_log_error == 'syslog' %}
|
||||||
syslog
|
syslog
|
||||||
syslog-tag = {{ mysql_syslog_tag }}
|
syslog-tag = {{ mysql_syslog_tag }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if mysql_log %}
|
|
||||||
log = {{ mysql_log }}
|
|
||||||
{% endif %}
|
|
||||||
log-error = {{ mysql_log_error }}
|
log-error = {{ mysql_log_error }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if mysql_slow_query_log_enabled %}
|
{% if mysql_slow_query_log_enabled %}
|
||||||
# Slow query log configuration.
|
# Slow query log configuration.
|
||||||
{% if mysql_vendor not in ['mariadb', 'mariadbgalera'] or mysql_mariadb_version | version_compare('10.0', '<') %}
|
|
||||||
log_slow_queries = 1
|
|
||||||
{% endif %}
|
|
||||||
slow_query_log = 1
|
slow_query_log = 1
|
||||||
slow_query_log_file = {{ mysql_slow_query_log_file }}
|
slow_query_log_file = {{ mysql_slow_query_log_file }}
|
||||||
long_query_time = {{ mysql_slow_query_time }}
|
long_query_time = {{ mysql_slow_query_time }}
|
||||||
|
|
|
@ -3,3 +3,4 @@ mysql_extra_configuration:
|
||||||
innodb_commit_concurrency: 0
|
innodb_commit_concurrency: 0
|
||||||
mysql_use_percona_apt: true
|
mysql_use_percona_apt: true
|
||||||
mysql_install_xtrabackup_package: true
|
mysql_install_xtrabackup_package: true
|
||||||
|
mysql_slow_query_log_enabled: true
|
||||||
|
|
Loading…
Reference in New Issue