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 - Monitoring with Monit and Munin
- Backups with automysqlbackup - Backups with automysqlbackup
No configuration of the database server will take place. ## Configuration
## Variables Create a dictionary called `mysqld` and define your settings:
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:
```YAML ```YAML
mariadb: mysqld:
bind_address: "10.0.0.2" bind_address: 0.0.0.0
slow_query_log: 1
...
``` ```
There are additional variables to configure automysqlbackup: 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 mysql_socket: /run/mysqld/mysqld.sock
slowlog_query_log_file: /var/log/mysql/mariadb-slow.logA automysqlbackup_backupdir: /var/lib/automysqlbackup
slowlog_query_time: 10 automysqlbackiup_dbhost: localhost
slowlog_log_slow_rate_limit: 1000 automysqlbackup_mailaddr: root
automysqlbackup_postbackup: /usr/local/bin/automysqlbackup_post_script 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
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 ,\ ` 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" MAILCONTENT="quiet"
MAXATTSIZE="4000" MAXATTSIZE="4000"
MAILADDR="{{ automysqlbackup_mailaddr | default("root") }}" MAILADDR="{{ automysqlbackup_mailaddr }}"
MDBNAMES="mysql $DBNAMES" MDBNAMES="mysql $DBNAMES"
DBEXCLUDE="" DBEXCLUDE=""
CREATE_DATABASE=yes CREATE_DATABASE=yes

View file

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

View file

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

View file

@ -1,4 +1,6 @@
# {{ ansible_managed }}
[mysql*] [mysql*]
env.mysqluser {{ munin_sql_user }} env.mysqluser {{ munin_sql_user }}
env.mysqlpassword {{ munin_sql_password }} env.mysqlpassword {{ munin_sql_password }}
env.mysqlconnection DBI:mysql:information_schema env.mysqlconnection DBI:mysql:information_schema