From 31f002f9d932b6a0b30ce291ba68373c549b7a7e Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Thu, 17 Oct 2019 13:35:11 -0400 Subject: [PATCH 1/9] Added option to prepare mysql servers for replication --- mysql/README.md | 11 ++- mysql/defaults/main.yml | 10 ++- mysql/files/dbadmin.sh | 101 +++++++++++++++++++++++ mysql/files/xinetd/mysqlchk | 13 +++ mysql/files/xinetd/mysqlchk.sh | 54 ++++++++++++ mysql/handlers/main.yml | 5 ++ mysql/tasks/main.yml | 3 + mysql/tasks/replication.yml | 53 ++++++++++++ mysql/templates/evolinux-custom.cnf.j2 | 7 +- mysql/templates/replication.cnf.j2 | 7 ++ mysql/templates/replication_check.cfg.j2 | 3 + 11 files changed, 255 insertions(+), 12 deletions(-) create mode 100644 mysql/files/dbadmin.sh create mode 100644 mysql/files/xinetd/mysqlchk create mode 100644 mysql/files/xinetd/mysqlchk.sh create mode 100644 mysql/tasks/replication.yml create mode 100644 mysql/templates/replication.cnf.j2 create mode 100644 mysql/templates/replication_check.cfg.j2 diff --git a/mysql/README.md b/mysql/README.md index ff4fcbe9..bb87921e 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -15,11 +15,13 @@ Tasks are extracted in several files, included in `tasks/main.yml` : * `munin.yml` : Munin plugins ; * `log2mail.yml` : log2mail patterns ; * `utils.yml` : useful tools. +* `replication.yml`: install and configure prerequisites for mysql replication, do not forget to set `mysql_bind_address`, `mysql_server_id` and `mysql_log_bin` ## Available variables * `mysql_variant` : install Oracle's MySQL or MariaDB (default: `oracle`) [Debian 8 only]; * `mysql_replace_root_with_mysqladmin`: switch from `root` to `mysqladmin` user or not ; +* `mysql_replication`: setup all prerequisites for replication. * `mysql_thread_cache_size`: number of threads for the cache ; * `mysql_innodb_buffer_pool_size`: amount of RAM dedicated to InnoDB ; * `mysql_bind_address` : (default: `Null`, default evolinux config is then used) ; @@ -30,8 +32,7 @@ Tasks are extracted in several files, included in `tasks/main.yml` : * `mysql_max_heap_table_size`: (default: `Null`, default evolinux config is then used) ; * `mysql_query_cache_limit`: (default: `Null`, default evolinux config is then used) ; * `mysql_query_cache_size`: (default: `Null`, default evolinux config is then used) ; -* `mysql_log_bin`: (default: `Null`, activates binlogs if used) ; -* `mysql_server_id`: (default: `Null`, MySQL version default is then used) ; +* `mysql_server_id`: (default: `Null`, only used with `mysql_replication`, default mysql server id will be used otherwise) ; * `mysql_custom_datadir`: custom datadir. * `mysql_custom_tmpdir`: custom tmpdir. * `general_alert_email`: email address to send various alert messages (default: `root@localhost`). @@ -41,5 +42,9 @@ Tasks are extracted in several files, included in `tasks/main.yml` : * `mysql_force_new_nrpe_password` : change the password for NRPE even if it exists already (default: `False`). * `mysql_install_libclient`: install mysql client libraries (default: `False`). * `mysql_restart_if_needed` : should the restart handler be executed (default: `True`) +* `mysql_log_bin`: (default: `Null`, activates binlogs if used with `mysql_replication`) ; +* `mysql_repl_password`: Password hash for replication user, only creates a user if set. +## Notes +Changing the _datadir_ location can be done multiple times, as long as it is not restored to the default initial location, (because a symlink is created and can't be switched back, yet). -NB : changing the _datadir_ location can be done multiple times, as long as it is not restored to the default initial location, (because a symlink is created and can't be switched back, yet). +When using replication, note that the connections from the client server on the haproxy 8306 and mysql 3306 ports need to be open and the sql servers need to communicate on port 3306. diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index 633619cf..f364de18 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -21,7 +21,6 @@ mysql_innodb_buffer_pool_size: '{{ (ansible_memtotal_mb * 0.3) | int }}M' # If these variables are changed to non-Null values, # they will be added in the zzz-evolinux-custom.cnf file. # Otherwise, the value from de the z-evolinux-defaults.cnf file will preveil. -mysql_bind_address: Null mysql_max_connections: Null mysql_max_connect_errors: Null mysql_table_cache: Null @@ -29,8 +28,6 @@ mysql_tmp_table_size: Null mysql_max_heap_table_size: Null mysql_query_cache_limit: Null mysql_query_cache_size: Null -mysql_log_bin: Null -mysql_server_id: Null mysql_cron_optimize: True mysql_cron_optimize_frequency: weekly @@ -44,3 +41,10 @@ mysql_evolinux_defaults_file: z-evolinux-defaults.cnf mysql_evolinux_custom_file: zzz-evolinux-custom.cnf mysql_restart_if_needed: True + +# replication variables: +mysql_replication: false +mysql_log_bin: null +mysql_server_id: null +mysql_bind_address: null +mysql_repl_password: '' \ No newline at end of file diff --git a/mysql/files/dbadmin.sh b/mysql/files/dbadmin.sh new file mode 100644 index 00000000..f5e61ea8 --- /dev/null +++ b/mysql/files/dbadmin.sh @@ -0,0 +1,101 @@ +#!/bin/sh +# +# Manage MySQL accounts and databases. +# +# Note: in the following code: +# - account means user@host +# - user is the user part of account +# + +MYSQL_OPTS="--raw --skip-column-names --skip-line-numbers" + +usage() { + cat <&2 +Usage: $0 [] + +Available commands are: + + list [] + List all accounts and their databases, separated by semi-colon. If user + is specified, list databases for this user only. + + passwd + Change password for specified user. + +EOT +} + +error() { + printf >&2 "Error: $@\n" +} + +get_host() { + user="$1" + host=$(mysql $MYSQL_OPTS --execute "SELECT host FROM mysql.user WHERE user='$user'") + if [ $(echo "$host" |wc -l) -gt 1 ]; then + # TODO: Not perfect! + echo "$host" |grep '%' + else + echo $host + fi +} + +get_dbs() { + account="$1" + echo "$(mysql $MYSQL_OPTS --execute "SHOW GRANTS FOR $account" |perl -ne 'print "$1 " if (/^GRANT (?!USAGE).* ON `(.*)`/)')" +} + +get_accounts() { + echo "$(mysql $MYSQL_OPTS --execute "SELECT user,host FROM mysql.user;" |perl -ne 'print "$1\@$2\n" if (/^([^\s]+)\s+([^\s]+)$/)'|sed "s/^/'/; s/@/'@'/; s/$/'/;")" +} + +list() { + if [ $# -gt 0 ]; then + user="$1" + host=$(get_host $user) + account="'$user'@'$host'" + echo $account:$(get_dbs "$account") + else + for account in $(get_accounts); do + echo $account:$(get_dbs "$account") + done + fi +} + +passwd() { + if [ $# -ne 2 ]; then + usage + exit 1 + fi + + user="$1" + password="$2" + host=$(get_host $user) + + mysql -e "SET PASSWORD FOR '$user'@'$host' = PASSWORD('$password');" +} + + +# +# Argument processing. +# + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +command="$1" +shift + +case "$command" in + list) + list $@ + ;; + passwd) + passwd $@ + ;; + *) + error "Unknown command: $command." + ;; +esac diff --git a/mysql/files/xinetd/mysqlchk b/mysql/files/xinetd/mysqlchk new file mode 100644 index 00000000..d7c12935 --- /dev/null +++ b/mysql/files/xinetd/mysqlchk @@ -0,0 +1,13 @@ +# Ansible managed +service mysqlchk +{ + socket_type = stream + port = 8306 + protocol = tcp + wait = no + type = UNLISTED + user = root + server = /usr/share/scripts/mysqlchk.sh + log_on_failure += USERID + disable = no +} diff --git a/mysql/files/xinetd/mysqlchk.sh b/mysql/files/xinetd/mysqlchk.sh new file mode 100644 index 00000000..7b5860d2 --- /dev/null +++ b/mysql/files/xinetd/mysqlchk.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# Ansible managed +# +# http://sysbible.org/x/2008/12/04/having-haproxy-check-mysql-status-through-a-xinetd-script/ +# +# This script checks if a mysql server is healthy running on localhost. It will +# return: +# +# "HTTP/1.x 200 OK\r" (if mysql is running smoothly) +# +# - OR - +# +# "HTTP/1.x 500 Internal Server Error\r" (else) +# +# The purpose of this script is make haproxy capable of monitoring mysql properly +# +# Author: Unai Rodriguez +# +# It is recommended that a low-privileged-mysql user is created to be used by +# this script. Something like this: +# +# mysql> GRANT SELECT on mysql.* TO 'mysqlchkusr'@'localhost' \ +# -> IDENTIFIED BY '257retfg2uysg218' WITH GRANT OPTION; +# mysql> flush privileges; + +TMP_FILE="/tmp/mysqlchk.out" +ERR_FILE="/tmp/mysqlchk.err" + +# +# We perform a simple query that should return a few results :-p +# +/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf -e "show databases;" > $TMP_FILE 2> $ERR_FILE + +# +# Check the output. If it is not empty then everything is fine and we return +# something. Else, we just do not return anything. +# + +if [ "$(/bin/cat $TMP_FILE)" != "" ]; then + # mysql is fine, return http 200 + /bin/echo -e "HTTP/1.1 200 OK\r\n" + /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" + /bin/echo -e "\r\n" + /bin/echo -e "MySQL is running.\r\n" + /bin/echo -e "\r\n" +else + # mysql is fine, return http 503 + /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n" + /bin/echo -e "Content-Type: Content-Type: text/plain\r\n" + /bin/echo -e "\r\n" + /bin/echo -e "MySQL is *down*.\r\n" + /bin/echo -e "\r\n" +fi diff --git a/mysql/handlers/main.yml b/mysql/handlers/main.yml index 2ea13151..50755f30 100644 --- a/mysql/handlers/main.yml +++ b/mysql/handlers/main.yml @@ -23,3 +23,8 @@ systemd: name: mysql daemon_reload: yes + +- name: 'restart xinetd' + service: + name: 'xinetd' + state: 'restart' diff --git a/mysql/tasks/main.yml b/mysql/tasks/main.yml index 89ee6866..11435c73 100644 --- a/mysql/tasks/main.yml +++ b/mysql/tasks/main.yml @@ -22,6 +22,9 @@ - include: config_jessie.yml when: ansible_distribution_release == "jessie" +- include: replication.yml + when: mysql_replication + - include: datadir.yml - include: logdir.yml diff --git a/mysql/tasks/replication.yml b/mysql/tasks/replication.yml new file mode 100644 index 00000000..6e5ee039 --- /dev/null +++ b/mysql/tasks/replication.yml @@ -0,0 +1,53 @@ +--- + +- name: 'Copy MySQL configuration for replication' + template: + src: 'replication.cnf.j2' + dest: "{{ mysql_config_directory }}/zzzz-replication.cnf" + with_first_found: + - "templates/mysql/replication.{{ inventory_hostname }}.cnf.j2" + - "templates/mysql/replication.{{ host_group }}.cnf.j2" + - 'templates/mysql/replication.cnf.j2' + - 'replication.cnf.j2' + notify: 'restart mysql' + +- name: 'Create repl user' + mysql_user: + name: 'repl' + host: '%' + encrypted: true + password: "{{ mysql_repl_password }}" + priv: '*.*:REPLICATION SLAVE,REPLICATION CLIENT' + update_password: 'on_create' + state: 'present' + register: create_repl_user + when: mysql_repl_password | length > 0 + +- name: 'Add Nagios check for replication' + template: + src: 'replication_check.cfg.j2' + dest: '/etc/nagios/nrpe.d/replication.cfg' + notify: 'restart nagios-nrpe-server' + +- name: 'Install xinetd' + apt: + name: 'xinetd' + +- name: 'Add xinetd configuration for MySQL HAProxy check' + copy: + src: 'xinetd/mysqlchk' + dest: '/etc/xinetd.d/' + mode: '0644' + notify: 'restart xinetd' + +- name: 'Copy mysqlchk script' + copy: + src: 'xinetd/mysqlchk.sh' + dest: '/usr/share/scripts/' + mode: '0755' + +- name: 'Copy dbadmin script' + copy: + src: 'dbadmin.sh' + dest: '/usr/share/scripts/' + mode: '0755' diff --git a/mysql/templates/evolinux-custom.cnf.j2 b/mysql/templates/evolinux-custom.cnf.j2 index f8ee104e..fd50fb36 100644 --- a/mysql/templates/evolinux-custom.cnf.j2 +++ b/mysql/templates/evolinux-custom.cnf.j2 @@ -29,9 +29,4 @@ query_cache_limit = {{ mysql_query_cache_limit }} {% if mysql_query_cache_limit %} query_cache_size = {{ mysql_query_cache_size }} {% endif %} -{% if mysql_log_bin %} -log_bin = {{ mysql_log_bin }} -{% endif %} -{% if mysql_server_id %} -server_id = {{ mysql_server_id }} -{% endif %} + diff --git a/mysql/templates/replication.cnf.j2 b/mysql/templates/replication.cnf.j2 new file mode 100644 index 00000000..f6da45d9 --- /dev/null +++ b/mysql/templates/replication.cnf.j2 @@ -0,0 +1,7 @@ +# {{ansible_managed}} + +[mysqld] +{% if mysql_log_bin %} +log_bin = {{ mysql_log_bin }} +{% endif %} +server_id = {{ mysql_server_id }} diff --git a/mysql/templates/replication_check.cfg.j2 b/mysql/templates/replication_check.cfg.j2 new file mode 100644 index 00000000..76135811 --- /dev/null +++ b/mysql/templates/replication_check.cfg.j2 @@ -0,0 +1,3 @@ +# ansible managed + +command[check_mysql_slave]=/usr/lib/nagios/plugins/check_mysql --check-slave -H localhost -f ~nagios/.my.cnf -w 1800 -c 3600 From c319be25420f86e2d57070aacc2cd23857e15261 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Fri, 18 Oct 2019 10:40:14 -0400 Subject: [PATCH 2/9] Make it possible for mysql role to copy evolix scripts Based myself off of the webapps/evoadmin-web role, but I'm not sure we still consider this a hack or not. We use a read only /usr fs, so we need to remount it to add scripts in /usr/local/share. --- mysql/tasks/replication.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mysql/tasks/replication.yml b/mysql/tasks/replication.yml index 6e5ee039..65939ba7 100644 --- a/mysql/tasks/replication.yml +++ b/mysql/tasks/replication.yml @@ -40,6 +40,10 @@ mode: '0644' notify: 'restart xinetd' +# /!\ Warning, this is a temporary hack +- include_role: + name: remount-usr + - name: 'Copy mysqlchk script' copy: src: 'xinetd/mysqlchk.sh' From 45fba1f87854a0dbf87e0dcf884c2932128fc963 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Wed, 4 Dec 2019 10:35:49 -0500 Subject: [PATCH 3/9] Removed useless dbadmin script from mysql replication tasks It was used by a very specific client case and is not needed for a general role. --- mysql/files/dbadmin.sh | 101 ------------------------------------ mysql/tasks/replication.yml | 6 --- 2 files changed, 107 deletions(-) delete mode 100644 mysql/files/dbadmin.sh diff --git a/mysql/files/dbadmin.sh b/mysql/files/dbadmin.sh deleted file mode 100644 index f5e61ea8..00000000 --- a/mysql/files/dbadmin.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/sh -# -# Manage MySQL accounts and databases. -# -# Note: in the following code: -# - account means user@host -# - user is the user part of account -# - -MYSQL_OPTS="--raw --skip-column-names --skip-line-numbers" - -usage() { - cat <&2 -Usage: $0 [] - -Available commands are: - - list [] - List all accounts and their databases, separated by semi-colon. If user - is specified, list databases for this user only. - - passwd - Change password for specified user. - -EOT -} - -error() { - printf >&2 "Error: $@\n" -} - -get_host() { - user="$1" - host=$(mysql $MYSQL_OPTS --execute "SELECT host FROM mysql.user WHERE user='$user'") - if [ $(echo "$host" |wc -l) -gt 1 ]; then - # TODO: Not perfect! - echo "$host" |grep '%' - else - echo $host - fi -} - -get_dbs() { - account="$1" - echo "$(mysql $MYSQL_OPTS --execute "SHOW GRANTS FOR $account" |perl -ne 'print "$1 " if (/^GRANT (?!USAGE).* ON `(.*)`/)')" -} - -get_accounts() { - echo "$(mysql $MYSQL_OPTS --execute "SELECT user,host FROM mysql.user;" |perl -ne 'print "$1\@$2\n" if (/^([^\s]+)\s+([^\s]+)$/)'|sed "s/^/'/; s/@/'@'/; s/$/'/;")" -} - -list() { - if [ $# -gt 0 ]; then - user="$1" - host=$(get_host $user) - account="'$user'@'$host'" - echo $account:$(get_dbs "$account") - else - for account in $(get_accounts); do - echo $account:$(get_dbs "$account") - done - fi -} - -passwd() { - if [ $# -ne 2 ]; then - usage - exit 1 - fi - - user="$1" - password="$2" - host=$(get_host $user) - - mysql -e "SET PASSWORD FOR '$user'@'$host' = PASSWORD('$password');" -} - - -# -# Argument processing. -# - -if [ $# -lt 1 ]; then - usage - exit 1 -fi - -command="$1" -shift - -case "$command" in - list) - list $@ - ;; - passwd) - passwd $@ - ;; - *) - error "Unknown command: $command." - ;; -esac diff --git a/mysql/tasks/replication.yml b/mysql/tasks/replication.yml index 65939ba7..33263815 100644 --- a/mysql/tasks/replication.yml +++ b/mysql/tasks/replication.yml @@ -49,9 +49,3 @@ src: 'xinetd/mysqlchk.sh' dest: '/usr/share/scripts/' mode: '0755' - -- name: 'Copy dbadmin script' - copy: - src: 'dbadmin.sh' - dest: '/usr/share/scripts/' - mode: '0755' From 6289c7fe1c72f0a241ab8301d95122809cae35f1 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Wed, 4 Dec 2019 11:11:48 -0500 Subject: [PATCH 4/9] Removed redundant nagios checks They are already installed by the base roles. --- mysql/handlers/main.yml | 5 ----- mysql/tasks/replication.yml | 6 ------ mysql/templates/replication_check.cfg.j2 | 3 --- 3 files changed, 14 deletions(-) delete mode 100644 mysql/templates/replication_check.cfg.j2 diff --git a/mysql/handlers/main.yml b/mysql/handlers/main.yml index 50755f30..87a7613a 100644 --- a/mysql/handlers/main.yml +++ b/mysql/handlers/main.yml @@ -4,11 +4,6 @@ name: munin-node state: restarted -- name: restart nagios-nrpe-server - service: - name: nagios-nrpe-server - state: restarted - - name: restart mysql service: name: mysql diff --git a/mysql/tasks/replication.yml b/mysql/tasks/replication.yml index 33263815..54f5e3e9 100644 --- a/mysql/tasks/replication.yml +++ b/mysql/tasks/replication.yml @@ -23,12 +23,6 @@ register: create_repl_user when: mysql_repl_password | length > 0 -- name: 'Add Nagios check for replication' - template: - src: 'replication_check.cfg.j2' - dest: '/etc/nagios/nrpe.d/replication.cfg' - notify: 'restart nagios-nrpe-server' - - name: 'Install xinetd' apt: name: 'xinetd' diff --git a/mysql/templates/replication_check.cfg.j2 b/mysql/templates/replication_check.cfg.j2 deleted file mode 100644 index 76135811..00000000 --- a/mysql/templates/replication_check.cfg.j2 +++ /dev/null @@ -1,3 +0,0 @@ -# ansible managed - -command[check_mysql_slave]=/usr/lib/nagios/plugins/check_mysql --check-slave -H localhost -f ~nagios/.my.cnf -w 1800 -c 3600 From d15819fb04c247b54b3348cee41a39317c0eb96f Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Mon, 13 Jan 2020 17:22:16 +0100 Subject: [PATCH 5/9] Replication should set a binlog format This could possible be better served in the base config file, but for now I'll keep it here. --- mysql/defaults/main.yml | 3 ++- mysql/templates/replication.cnf.j2 | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index f364de18..501b2cb2 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -45,6 +45,7 @@ mysql_restart_if_needed: True # replication variables: mysql_replication: false mysql_log_bin: null +mysql_binlog_format: mixed mysql_server_id: null mysql_bind_address: null -mysql_repl_password: '' \ No newline at end of file +mysql_repl_password: '' diff --git a/mysql/templates/replication.cnf.j2 b/mysql/templates/replication.cnf.j2 index f6da45d9..030f2470 100644 --- a/mysql/templates/replication.cnf.j2 +++ b/mysql/templates/replication.cnf.j2 @@ -5,3 +5,4 @@ log_bin = {{ mysql_log_bin }} {% endif %} server_id = {{ mysql_server_id }} +binlog_format = {{ mysql_binlog_format }} From b80f3993ae826d5bd8cb8619e77f5d53a169efbe Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Mon, 13 Jan 2020 17:23:34 +0100 Subject: [PATCH 6/9] Added some mysql variables and allowed forcing config update The default behaviour is kept, but this way we can manage a mysql installation from ansible. --- mysql/defaults/main.yml | 2 ++ mysql/tasks/config_jessie.yml | 2 +- mysql/tasks/config_stretch.yml | 2 +- mysql/templates/evolinux-custom.cnf.j2 | 7 +++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index 501b2cb2..8544daef 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -28,6 +28,8 @@ mysql_tmp_table_size: Null mysql_max_heap_table_size: Null mysql_query_cache_limit: Null mysql_query_cache_size: Null +mysql_max_allowed_packet: Null +mysql_force_custom_config: 'no' mysql_cron_optimize: True mysql_cron_optimize_frequency: weekly diff --git a/mysql/tasks/config_jessie.yml b/mysql/tasks/config_jessie.yml index 9fe11bb7..a5dd4d77 100644 --- a/mysql/tasks/config_jessie.yml +++ b/mysql/tasks/config_jessie.yml @@ -21,6 +21,6 @@ owner: root group: root mode: "0644" - force: no + force: "{{ mysql_force_custom_config }}" tags: - mysql diff --git a/mysql/tasks/config_stretch.yml b/mysql/tasks/config_stretch.yml index 0725ee1f..d6d59efd 100644 --- a/mysql/tasks/config_stretch.yml +++ b/mysql/tasks/config_stretch.yml @@ -21,7 +21,7 @@ owner: root group: root mode: "0644" - force: no + force: "{{ mysql_force_custom_config }}" tags: - mysql diff --git a/mysql/templates/evolinux-custom.cnf.j2 b/mysql/templates/evolinux-custom.cnf.j2 index fd50fb36..daa70a48 100644 --- a/mysql/templates/evolinux-custom.cnf.j2 +++ b/mysql/templates/evolinux-custom.cnf.j2 @@ -29,4 +29,11 @@ query_cache_limit = {{ mysql_query_cache_limit }} {% if mysql_query_cache_limit %} query_cache_size = {{ mysql_query_cache_size }} {% endif %} +{% if mysql_max_allowed_packet %} +max_allowed_packet = {{ mysql_max_allowed_packet }} +{% endif %} +{% if mysql_lower_case_table_names %} +lower_case_table_names = {{ mysql_lower_case_table_names }} +{% endif %} + From 1a96616f42936ef4ca1d5065ae1a781448b60275 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Mon, 13 Jan 2020 17:50:24 +0100 Subject: [PATCH 7/9] Fix right problem in mysql replication The configuration file was not set to 0644, which caused the file to be ignored by mysql and it's configuration not to be set. --- mysql/tasks/replication.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mysql/tasks/replication.yml b/mysql/tasks/replication.yml index 54f5e3e9..f447d099 100644 --- a/mysql/tasks/replication.yml +++ b/mysql/tasks/replication.yml @@ -4,11 +4,7 @@ template: src: 'replication.cnf.j2' dest: "{{ mysql_config_directory }}/zzzz-replication.cnf" - with_first_found: - - "templates/mysql/replication.{{ inventory_hostname }}.cnf.j2" - - "templates/mysql/replication.{{ host_group }}.cnf.j2" - - 'templates/mysql/replication.cnf.j2' - - 'replication.cnf.j2' + mode: "0644" notify: 'restart mysql' - name: 'Create repl user' From 5b9cc3af31a71f126f0630de21ef902b2ec9379f Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Wed, 15 Jan 2020 15:58:29 +0100 Subject: [PATCH 8/9] Added mysql_innodb_log_file_size option to the mysql role Makes it possible to have larger binary entries when replicating. --- mysql/defaults/main.yml | 2 ++ mysql/templates/evolinux-custom.cnf.j2 | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index 8544daef..49115ee9 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -30,6 +30,7 @@ mysql_query_cache_limit: Null mysql_query_cache_size: Null mysql_max_allowed_packet: Null mysql_force_custom_config: 'no' +mysql_innodb_log_file_size: Null mysql_cron_optimize: True mysql_cron_optimize_frequency: weekly @@ -51,3 +52,4 @@ mysql_binlog_format: mixed mysql_server_id: null mysql_bind_address: null mysql_repl_password: '' + diff --git a/mysql/templates/evolinux-custom.cnf.j2 b/mysql/templates/evolinux-custom.cnf.j2 index daa70a48..d33a4f2b 100644 --- a/mysql/templates/evolinux-custom.cnf.j2 +++ b/mysql/templates/evolinux-custom.cnf.j2 @@ -35,5 +35,6 @@ max_allowed_packet = {{ mysql_max_allowed_packet }} {% if mysql_lower_case_table_names %} lower_case_table_names = {{ mysql_lower_case_table_names }} {% endif %} - - +{% if mysql_innodb_log_file_size %} +innodb_log_file_size = {{ mysql_innodb_log_file_size }} +{% endif %} From 8c1e40c1a964fda838602eea9aa3c2f22b1e2d55 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Mon, 1 Jun 2020 12:03:23 -0400 Subject: [PATCH 9/9] Add option to make a mysql install read only Rebased on unstable --- CHANGELOG.md | 5 +++-- mysql/defaults/main.yml | 2 +- mysql/templates/evolinux-custom.cnf.j2 | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab0d0ced..eee08070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ The **patch** part changes incrementally at each release. ## [Unreleased] ### Added +* mysql: activate binary logs by specifying log_bin path +* mysql: specify a custom server_id +* mysql: option to define as read only ### Changed @@ -47,8 +50,6 @@ The **patch** part changes incrementally at each release. * minifirewall: add a variable to force the check scripts update * mongodb: mongodb: compatibility with Debian 10 * mysql-oracle: backport tasks from mysql role -* mysql: activate binary logs by specifying log_bin path -* mysql: specify a custom server_id * networkd-to-ifconfig: add variables for configuration by variables * packweb-apache: Deploy opcache.php to give some insights on PHP's opcache status * php: variable to install the mysqlnd module instead of the default mysql module diff --git a/mysql/defaults/main.yml b/mysql/defaults/main.yml index 49115ee9..8d8771fa 100644 --- a/mysql/defaults/main.yml +++ b/mysql/defaults/main.yml @@ -52,4 +52,4 @@ mysql_binlog_format: mixed mysql_server_id: null mysql_bind_address: null mysql_repl_password: '' - +mysql_read_only: 0 diff --git a/mysql/templates/evolinux-custom.cnf.j2 b/mysql/templates/evolinux-custom.cnf.j2 index d33a4f2b..63d7ea2d 100644 --- a/mysql/templates/evolinux-custom.cnf.j2 +++ b/mysql/templates/evolinux-custom.cnf.j2 @@ -38,3 +38,4 @@ lower_case_table_names = {{ mysql_lower_case_table_names }} {% if mysql_innodb_log_file_size %} innodb_log_file_size = {{ mysql_innodb_log_file_size }} {% endif %} +read_only = {{ mysql_read_only }}