Configure MariDB server via this role

This commit is contained in:
phil 2023-10-14 10:43:06 +02:00
parent 1f1c8d1542
commit 6b3d265524
6 changed files with 32 additions and 28 deletions

View file

@ -5,20 +5,14 @@ This role installs MariaDB, including:
- Monitoring with Monit and Munin
- Backups with automysqlbackup
No configuration of the database server will take place.
## Configuration
## Variables
You can use the following variables to adopt the role to your needs. Place them in a dictionary called `mariadb`:
| Varible | Value | Notes |
|--|--|--|
| `bind_address` | string | Address to bind the MariaDB server to |
Ecample:
Create a dictionary called `mysqld` and define your settings:
```YAML
mariadb:
bind_address: "10.0.0.2"
mysqld:
bind_address: 0.0.0.0
slow_query_log: 1
...
```
There are additional variables to configure automysqlbackup:

View file

@ -7,8 +7,14 @@ munin_sql_password: "{{ lookup('ansible.builtin.password', '/tmp/{{ inventory_ho
mysql_socket: /run/mysqld/mysqld.sock
automysqlbackup_backupdir: /var/lib/automysqlbackup
automysqlbackiup_dbhost: localhost
automysqlbackup_mailaddr: root
automysqlbackup_postbackup: /usr/local/bin/automysqlbackup_post_script
mysqld:
slow_query_log: 1
slowlog_query_log_file: /var/log/mysql/mariadb-slow.logA
slowlog_query_time: 10
slowlog_log_slow_rate_limit: 1000
automysqlbackup_postbackup: /usr/local/bin/automysqlbackup_post_script
log_slow_verbosity: query_plan

View file

@ -1,11 +1,11 @@
# Managed by ansible
# {{ ansible_managed }}
DBHOST={{ automysqlbackiup_dbhost | default("localhost") }}
DBHOST={{ automysqlbackiup_dbhost }}
DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ `
BACKUPDIR="{{ automysqlbackup_backupdir | default("/var/lib/automysqlbackup") }}"
BACKUPDIR="{{ automysqlbackup_backupdir }}"
MAILCONTENT="quiet"
MAXATTSIZE="4000"
MAILADDR="{{ automysqlbackup_mailaddr | default("root") }}"
MAILADDR="{{ automysqlbackup_mailaddr }}"
MDBNAMES="mysql $DBNAMES"
DBEXCLUDE=""
CREATE_DATABASE=yes

View file

@ -1,9 +1,9 @@
# Ansible managed
# {{ ansible_managed }}
[mysqld]
# slow log
slow_query_log = 1
slow_query_log_file = {{ slowlog_query_log_file }}
long_query_time = {{ slowlog_query_time }}
log_slow_rate_limit = {{ slowlog_log_slow_rate_limit }}
log_slow_verbosity = query_plan
{% if mysqld_config is defined %}
{% for key, value in mysqld_config.items() %}
{{ key }} = {{ value }}
{% endfor %}
{% endif %}

View file

@ -1,3 +1,5 @@
# {{ ansible_managed }}
check process mariadb with pidfile /run/mysqld/mysqld.pid
group database
start program = "/usr/sbin/service mysql start"

View file

@ -1,3 +1,5 @@
# {{ ansible_managed }}
[mysql*]
env.mysqluser {{ munin_sql_user }}
env.mysqlpassword {{ munin_sql_password }}