refs #8414 - Split All Rol
This commit is contained in:
parent
7f5277d1e0
commit
9472b212ce
|
@ -15,43 +15,4 @@ dcsamba_base_packages:
|
|||
- ldb-tools
|
||||
- samba-dsdb-modules
|
||||
- samba-vfs-modules
|
||||
mariadb_base_packages:
|
||||
- mariadb-server
|
||||
- mariadb-backup
|
||||
- pmm2-client
|
||||
mariadb_requeriments:
|
||||
- curl
|
||||
- apt-transport-https
|
||||
certificates:
|
||||
- { content: '{{ ca_company_deprecated }}', dest: '/etc/mysql/ca.pem', mode: 'u=rw,g=r,o=r' }
|
||||
- { content: '{{ cert_mysql }}', dest: '/etc/mysql/cert.pem', mode: 'u=rw,g=r,o=r' }
|
||||
- { content: '{{ cert_mysql_key }}', dest: '/etc/mysql/key.pem', mode: 'u=rw,g=,o=' }
|
||||
required_directories:
|
||||
- { path: /mnt/local-backup, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' }
|
||||
- { path: /mnt/mysqlbin, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' }
|
||||
- { path: /mnt/mysqltmp, owner: root, group: root, mode: 'u=rwx,g=rwx,o=rwxt' }
|
||||
- { path: /mnt/mysqlbin/binlog, owner: mysql, group: mysql, mode: 'u=rwx,g=,o=' }
|
||||
- { path: /root/scripts, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' }
|
||||
- { path: /root/mariabackup, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' }
|
||||
- { path: /mnt/mysqldata/mysql, owner: mysql, group: mysql, mode: 'u=rwx,g=rx,o=rx' }
|
||||
- { path: /etc/systemd/system/mariadb.service.d, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' }
|
||||
|
||||
required_files_and_mariabackup_files_and_root_scripts:
|
||||
- { src: "mariadb_override.conf", dest: "/etc/systemd/system/mariadb.service.d/override.conf", mode: "u=rw,g=r,o=r" }
|
||||
- { src: "mysql-flush.sh", dest: "/etc/qemu/fsfreeze-hook.d/mysql-flush.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/mariabackup/bacula-before.sh", dest: "/root/mariabackup/bacula-before.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/mariabackup/config.sh", dest: "/root/mariabackup/config.sh", mode: "u=rwx,g=rx,o=x" }
|
||||
- { src: "files/mariabackup/inc-backup.sh", dest: "/root/mariabackup/inc-backup.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/mariabackup/restore-backup.sh", dest: "/root/mariabackup/restore-backup.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/check-memory.sh", dest: "/root/scripts/check-memory.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/export-privs.sh", dest: "/root/scripts/export-privs.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/mysqltuner.pl", dest: "/root/scripts/mysqltuner.pl", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/promote-master.sh", dest: "/root/scripts/promote-master.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/promote-slave.sh", dest: "/root/scripts/promote-slave.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/README.md", dest: "/root/scripts/README.md", mode: "u=rw,g=r,o=r" }
|
||||
- { src: "files/scripts/scheduler-log.sh", dest: "/root/scripts/scheduler-log.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/scripts/sync-conf.sh", dest: "/root/scripts/sync-conf.sh", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { src: "files/marianrpe/95-mariadb.cfg", dest: "/etc/nagios/nrpe.d/95-mariadb.cfg", mode: "u=rw,g=r,o=r" }
|
||||
downloads:
|
||||
- { url: "https://r.mariadb.com/downloads/mariadb_repo_setup", dest: "/tmp/mariadb_repo_setup", mode: "u=rwx,g=rx,o=rx" }
|
||||
- { url: "https://repo.percona.com/apt/percona-release_latest.generic_all.deb", dest: "/tmp/percona-release_latest.generic_all.deb", mode: "u=rw,g=r,o=r" }
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#!/bin/bash
|
||||
# https://mariadb.com/kb/en/mariabackup/
|
||||
set -e
|
||||
|
||||
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
. "$myDir/config.sh"
|
||||
|
||||
todayDir="$(date +%Y-%m-%d)"
|
||||
backupName="${todayDir}_$(date +"%H-%M")_full"
|
||||
backupFile="$backupDir/$backupName.gz"
|
||||
|
||||
if [ -d "$backupDir" ]; then
|
||||
rm -rf "$backupDir/"*
|
||||
fi
|
||||
|
||||
ulimit -n 8192
|
||||
mariabackup \
|
||||
--defaults-extra-file="$myDir/my.cnf" \
|
||||
--backup \
|
||||
--extra-lsndir="$backupDir/$backupName" \
|
||||
--history="$todayDir" \
|
||||
2>> "$logFile" \
|
||||
| gzip \
|
||||
> "$backupFile"
|
||||
|
||||
if [ $? != "0" ]; then
|
||||
echo "An error ocurred during backup, please take a look at log file: $logFile"
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Destination file for backup logs
|
||||
logFile=/var/log/vn-mariabackup.log
|
||||
|
||||
# Temporary local directory to save backups
|
||||
backupDir=/mnt/local-backup
|
||||
|
||||
# Directory for backup history
|
||||
historyDir=/mnt/backup4mariadb
|
||||
|
||||
# Number of days for backup rotation
|
||||
cleanDays=90
|
||||
|
||||
# Directory for temporal restore data
|
||||
restoreDir=/mnt/mysqldata/mysql-restore
|
||||
|
||||
# Directory of MySQL data
|
||||
dataDir=/mnt/mysqldata/mysql
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#!/bin/bash
|
||||
# https://mariadb.com/kb/en/incremental-backup-and-restore-with-mariabackup/
|
||||
set -e
|
||||
|
||||
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
. "$myDir/config.sh"
|
||||
|
||||
todayDir="$(date +%Y-%m-%d)"
|
||||
todayPath="$historyDir/$todayDir"
|
||||
|
||||
pattern="$todayPath/${todayDir}_??-??_full.xb.gz.enc"
|
||||
files=($pattern)
|
||||
backupFile="${files[0]}"
|
||||
backupBase=$(basename -- "$backupFile")
|
||||
backupName="${backupBase%%.*}"
|
||||
|
||||
incrementalName="${todayDir}_$(date +"%H-%M")_incremental"
|
||||
incrementalFile="$backupDir/${incrementalName}.xb.gz.enc"
|
||||
|
||||
ulimit -n 24098
|
||||
mariabackup \
|
||||
--defaults-extra-file="$myDir/my.cnf" \
|
||||
--backup \
|
||||
--incremental-basedir="$backupDir/$backupName" \
|
||||
--extra-lsndir="$backupDir/$incrementalName" \
|
||||
--incremental-history-name="$todayDir" \
|
||||
2>> "$logFile" \
|
||||
| gzip \
|
||||
| openssl enc -aes-256-cbc -pbkdf2 -kfile "$myDir/xbcrypt.key" \
|
||||
> "$incrementalFile"
|
||||
|
||||
if [ $? != "0" ]; then
|
||||
echo "An error ocurred during backup, please take a look at log file: $logFile"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$incrementalFile" "$todayPath"
|
||||
cp -r "$backupDir/$incrementalName" "$todayPath"
|
|
@ -1,53 +0,0 @@
|
|||
#!/bin/bash
|
||||
# https://mariadb.com/kb/en/using-encryption-and-compression-tools-with-mariabackup/
|
||||
set -e
|
||||
|
||||
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
. "$myDir/config.sh"
|
||||
|
||||
backupFile=$1
|
||||
|
||||
if [ -z "$backupFile" ]; then
|
||||
echo "Backup file not defined."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$backupFile" ]; then
|
||||
echo "Backup file does not exist: $backupFile"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Restoring MySQL data from backup."
|
||||
|
||||
rm -rf "$restoreDir"
|
||||
mkdir -p "$restoreDir"
|
||||
|
||||
echo "Decompresing backup."
|
||||
gzip --decompress --stdout "$backupFile" \
|
||||
| mbstream -x --directory="$restoreDir"
|
||||
|
||||
echo "Preparing backup."
|
||||
mariabackup \
|
||||
--defaults-extra-file="$myDir/my.cnf" \
|
||||
--prepare \
|
||||
--target-dir="$restoreDir"
|
||||
|
||||
echo "Stopping service."
|
||||
service mariadb stop
|
||||
if pgrep mariadbd; then pkill -9 mariadbd; fi
|
||||
|
||||
echo "Restoring data."
|
||||
rm -rf "$dataDir"
|
||||
mariabackup \
|
||||
--defaults-extra-file="$myDir/my.cnf" \
|
||||
--move-back \
|
||||
--target-dir="$restoreDir" \
|
||||
2>> "$logFile"
|
||||
chown -R mysql:mysql "$dataDir"
|
||||
|
||||
rm "$dataDir/mysql/slow_log."*
|
||||
rm "$dataDir/mysql/general_log."*
|
||||
|
||||
echo "Removing restore data."
|
||||
rm -r "$restoreDir"
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
UPDATE vn2008.tblContadores
|
||||
SET dbproduccion = FALSE;
|
||||
|
||||
DELETE FROM util.binlogQueue;
|
||||
|
||||
GRANT
|
||||
SELECT,
|
||||
INSERT,
|
||||
UPDATE,
|
||||
DELETE,
|
||||
CREATE,
|
||||
DROP,
|
||||
INDEX,
|
||||
ALTER,
|
||||
CREATE TEMPORARY TABLES,
|
||||
CREATE VIEW,
|
||||
EVENT,
|
||||
TRIGGER,
|
||||
SHOW VIEW,
|
||||
CREATE ROUTINE,
|
||||
ALTER ROUTINE,
|
||||
EXECUTE
|
||||
ON *.* TO developerBoss;
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
. "$myDir/config.sh"
|
||||
. "$myDir/apply.config.sh"
|
||||
|
||||
todayDir=$(date +%Y-%m-%d)
|
||||
pattern="$baculaDir/mnt/local-backup/${todayDir}_??-??_full.gz"
|
||||
files=($pattern)
|
||||
backupFile="${files[0]}"
|
||||
|
||||
"$myDir/restore-backup.sh" "$backupFile"
|
||||
rm -r "$baculaDir"
|
||||
|
||||
if [[ "${#dbClusterSiblings[@]}" -gt "0" ]]; then
|
||||
for node in "${dbClusterSiblings[@]}"; do
|
||||
ssh root@$node service mysql stop
|
||||
ssh root@$node "if pgrep mariadbd; then pkill -9 mariadbd; fi"
|
||||
done
|
||||
|
||||
galera_new_cluster
|
||||
else
|
||||
service mariadb start
|
||||
fi
|
||||
|
||||
echo "Applying custom script."
|
||||
mysql -e "UPDATE util.config SET environment = '$dbEnvironment', lastDump = NOW()"
|
||||
mysql < "$myDir/apply.sql"
|
||||
|
||||
echo "Upgrading tables."
|
||||
mysql_upgrade
|
||||
|
||||
echo "Applying repository changes."
|
||||
curl --silent --request POST --location --user "$jenkinsAuth" "$jenkinsUrl/build?delay=0sec"
|
||||
|
||||
echo "Waiting for Jenkins job to end."
|
||||
jobResult=null
|
||||
while [ "$jobResult" = "null" ]; do
|
||||
sleep 10
|
||||
jobResult=$(curl --silent --location --user "$jenkinsAuth" "$jenkinsUrl/lastBuild/api/json" | jq --raw-output ".result")
|
||||
done
|
||||
echo "Job result: $jobResult"
|
||||
|
||||
echo "Promoting to master."
|
||||
"/root/scripts/promote-master.sh"
|
||||
|
||||
for node in "${dbClusterSiblings[@]}"; do
|
||||
ssh root@$node service mysql start
|
||||
done
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
UPDATE vn2008.tblContadores
|
||||
SET dbproduccion = FALSE;
|
||||
|
||||
DELETE FROM util.binlogQueue;
|
||||
|
||||
UPDATE `account`.`user` SET `active` = TRUE WHERE `name` = 'mindshore';
|
|
@ -1,51 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
. "$myDir/config.sh"
|
||||
. "$myDir/apply.config.sh"
|
||||
|
||||
todayDir=$(date +%Y-%m-%d)
|
||||
pattern="$baculaDir/mnt/local-backup/${todayDir}_??-??_full.gz"
|
||||
files=($pattern)
|
||||
backupFile="${files[0]}"
|
||||
|
||||
"$myDir/restore-backup.sh" "$backupFile"
|
||||
rm -r "$baculaDir"
|
||||
|
||||
if [[ "${#dbClusterSiblings[@]}" -gt "0" ]]; then
|
||||
for node in "${dbClusterSiblings[@]}"; do
|
||||
ssh root@$node service mysql stop
|
||||
ssh root@$node "if pgrep mariadbd; then pkill -9 mariadbd; fi"
|
||||
done
|
||||
|
||||
galera_new_cluster
|
||||
else
|
||||
service mariadb start
|
||||
fi
|
||||
|
||||
echo "Applying custom script."
|
||||
mysql -e "UPDATE util.config SET environment = '$dbEnvironment', lastDump = NOW()"
|
||||
mysql < "$myDir/apply.sql"
|
||||
|
||||
echo "Upgrading tables."
|
||||
mysql_upgrade
|
||||
|
||||
echo "Applying repository changes."
|
||||
curl --silent --request POST --location --user "$jenkinsAuth" "$jenkinsUrl/build?delay=0sec"
|
||||
|
||||
echo "Waiting for Jenkins job to end."
|
||||
jobResult=null
|
||||
while [ "$jobResult" = "null" ]; do
|
||||
sleep 10
|
||||
jobResult=$(curl --silent --location --user "$jenkinsAuth" "$jenkinsUrl/lastBuild/api/json" | jq --raw-output ".result")
|
||||
done
|
||||
echo "Job result: $jobResult"
|
||||
|
||||
echo "Promoting to master."
|
||||
"/root/scripts/promote-master.sh"
|
||||
|
||||
for node in "${dbClusterSiblings[@]}"; do
|
||||
ssh root@$node service mysql start
|
||||
done
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
[mysqld]
|
||||
# Docs: https://mariadb.com/kb/en/server-system-variables
|
||||
|
||||
lc_messages = es_ES
|
||||
lc_time_names = es_ES
|
||||
character-set-server = utf8
|
||||
collation-server = utf8_unicode_ci
|
||||
explicit_defaults_for_timestamp = ON
|
||||
datadir = /mnt/mysqldata/mysql
|
||||
tmpdir = /mnt/mysqltmp
|
||||
log_bin_trust_function_creators = 1
|
||||
sql_mode = NO_ENGINE_SUBSTITUTION
|
||||
bind-address = 0.0.0.0
|
||||
max_password_errors = 50
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Threads
|
||||
|
||||
thread_stack = 512K
|
||||
join_buffer_size = 2M
|
||||
sort_buffer_size = 4M
|
||||
net_buffer_length = 256K
|
||||
max_allowed_packet = 16M
|
||||
read_buffer_size = 1M
|
||||
read_rnd_buffer_size = 512K
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Performance
|
||||
|
||||
thread_cache_size = 450
|
||||
interactive_timeout = 1800
|
||||
wait_timeout = 1800
|
||||
open_files_limit = 20000
|
||||
low_priority_updates = 1
|
||||
table_open_cache = 40000
|
||||
table_definition_cache = 10000
|
||||
table_open_cache_instances = 1
|
||||
key_buffer_size = 256K
|
||||
max_heap_table_size = 128M
|
||||
tmp_table_size = 128M
|
||||
concurrent_insert = ALWAYS
|
||||
group_concat_max_len = 10000
|
||||
max_connect_errors = 50
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Binary log
|
||||
|
||||
max_binlog_size = 1GB
|
||||
binlog_cache_size = 16M
|
||||
binlog_stmt_cache_size = 16M
|
||||
binlog_row_image = noblob
|
||||
binlog_format = row
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ InnoDB
|
||||
|
||||
transaction-isolation = READ-COMMITTED
|
||||
idle_transaction_timeout = 60
|
||||
innodb_io_capacity = 100
|
||||
innodb_io_capacity_max = 100
|
||||
innodb_monitor_enable = all
|
||||
innodb_read_io_threads = 16
|
||||
innodb_write_io_threads = 16
|
||||
innodb_checksum_algorithm = crc32
|
||||
innodb_adaptive_hash_index = 0
|
||||
innodb_flush_method = O_DIRECT
|
||||
innodb_log_buffer_size = 32M
|
||||
innodb_purge_threads = 4
|
||||
innodb_buffer_pool_dump_at_shutdown = ON
|
||||
innodb_buffer_pool_load_at_startup = ON
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Logging
|
||||
|
||||
log_error = /var/log/mysql/error.log
|
||||
log_output = TABLE
|
||||
general_log = OFF
|
||||
slow_query_log = ON
|
||||
long_query_time = 2
|
||||
min_examined_row_limit = 0
|
||||
log_slow_admin_statements = ON
|
||||
log_queries_not_using_indexes = OFF
|
||||
max_error_count = 100
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ SSL
|
||||
|
||||
ssl-ca = /etc/mysql/ca.pem
|
||||
ssl-cert = /etc/mysql/cert.pem
|
||||
ssl-key = /etc/mysql/key.pem
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Query cache
|
||||
|
||||
query_cache_limit = 0
|
||||
query_cache_type = OFF
|
||||
query_cache_size = 0
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Performance Schema
|
||||
|
||||
performance_schema = ON
|
||||
performance_schema_digests_size = 20000
|
||||
performance-schema-consumer-events-statements-history = ON
|
||||
performance_schema_consumer_events_statements_history_long = ON
|
||||
userstat = ON
|
|
@ -1,14 +0,0 @@
|
|||
[mysqld]
|
||||
|
||||
port = 3307
|
||||
bind-address = 0.0.0.0
|
||||
innodb_buffer_pool_size = 18G
|
||||
event-scheduler = OFF
|
||||
innodb_log_file_size = 5G
|
||||
log_warnings = 2
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Binary log
|
||||
|
||||
log-bin = bin.log
|
||||
expire_logs_days = 1
|
||||
relay_log = mysqld-relay-bin
|
|
@ -1,29 +0,0 @@
|
|||
[mysqld]
|
||||
|
||||
port = 3306
|
||||
innodb_log_file_size = 8G
|
||||
log_warnings = 1
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Binary log
|
||||
|
||||
log-bin = /mnt/mysqlbin/binlog/bin.log
|
||||
max_connections = 1000
|
||||
expire_logs_days = 7
|
||||
innodb_buffer_pool_size = 64G
|
||||
relay_log = /mnt/mysqlbin/binlog/relay.log
|
||||
binlog-ignore-db = tmp
|
||||
binlog-ignore-db = PERCONA_SCHEMA
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++ Replication
|
||||
|
||||
event-scheduler = ON
|
||||
slave_exec_mode = STRICT
|
||||
|
||||
replicate-ignore-db = tmp
|
||||
replicate-ignore-table = util.eventLog
|
||||
replicate-ignore-table = cache.cache_calc
|
||||
replicate-ignore-table = cache.available
|
||||
replicate-ignore-table = cache.availableNoRaids
|
||||
replicate-ignore-table = cache.cache_valid
|
||||
replicate-ignore-table = cache.stock
|
||||
replicate-ignore-table = cache.visible
|
|
@ -1,3 +0,0 @@
|
|||
[Service]
|
||||
LimitNOFILE=600000
|
||||
LimitMEMLOCK=2M
|
|
@ -1,4 +0,0 @@
|
|||
command[check_disk_mysqldata]=/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /mnt/mysqldata
|
||||
command[check_disk_mysqlbin]=/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /mnt/mysqlbin
|
||||
command[check_disk_backup]=/usr/lib/nagios/plugins/check_disk -w 10% -c 5% -p /mnt/local-backup
|
||||
command[check_mysql_scheduler]=/etc/nagios/plugins/check_mysql_scheduler
|
|
@ -1,57 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# https://github.com/qemu/qemu/blob/master/scripts/qemu-guest-agent/fsfreeze-hook.d/mysql-flush.sh.sample
|
||||
# Flush MySQL tables to the disk before the filesystem is frozen.
|
||||
# At the same time, this keeps a read lock in order to avoid write accesses
|
||||
# from the other clients until the filesystem is thawed.
|
||||
|
||||
MYSQL="/usr/bin/mysql"
|
||||
MYSQL_OPTS="-uroot" #"-prootpassword"
|
||||
FIFO=/var/run/mysql-flush.fifo
|
||||
|
||||
# Check mysql is installed and the server running
|
||||
[ -x "$MYSQL" ] && "$MYSQL" $MYSQL_OPTS < /dev/null || exit 0
|
||||
|
||||
flush_and_wait() {
|
||||
printf "FLUSH TABLES WITH READ LOCK \\G\n"
|
||||
trap 'printf "$(date): $0 is killed\n">&2' HUP INT QUIT ALRM TERM
|
||||
read < $FIFO
|
||||
printf "UNLOCK TABLES \\G\n"
|
||||
rm -f $FIFO
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
freeze)
|
||||
mkfifo $FIFO || exit 1
|
||||
flush_and_wait | "$MYSQL" $MYSQL_OPTS &
|
||||
# wait until every block is flushed
|
||||
while [ "$(echo 'SHOW STATUS LIKE "Key_blocks_not_flushed"' |\
|
||||
"$MYSQL" $MYSQL_OPTS | tail -1 | cut -f 2)" -gt 0 ]; do
|
||||
sleep 1
|
||||
done
|
||||
# for InnoDB, wait until every log is flushed
|
||||
INNODB_STATUS=$(mktemp /tmp/mysql-flush.XXXXXX)
|
||||
[ $? -ne 0 ] && exit 2
|
||||
trap "rm -f $INNODB_STATUS; exit 1" HUP INT QUIT ALRM TERM
|
||||
while :; do
|
||||
printf "SHOW ENGINE INNODB STATUS \\G" |\
|
||||
"$MYSQL" $MYSQL_OPTS > $INNODB_STATUS
|
||||
LOG_CURRENT=$(grep 'Log sequence number' $INNODB_STATUS |\
|
||||
tr -s ' ' | cut -d' ' -f4)
|
||||
LOG_FLUSHED=$(grep 'Log flushed up to' $INNODB_STATUS |\
|
||||
tr -s ' ' | cut -d' ' -f5)
|
||||
[ "$LOG_CURRENT" = "$LOG_FLUSHED" ] && break
|
||||
sleep 1
|
||||
done
|
||||
rm -f $INNODB_STATUS
|
||||
;;
|
||||
|
||||
thaw)
|
||||
[ ! -p $FIFO ] && exit 1
|
||||
echo > $FIFO
|
||||
;;
|
||||
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,19 +0,0 @@
|
|||
# Scripts to maintain MariaDB
|
||||
|
||||
## scheduler-log.sh
|
||||
|
||||
The following table should be created into MySQL/MariaDB database.
|
||||
|
||||
```
|
||||
CREATE TABLE `eventLog` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`date` datetime NOT NULL,
|
||||
`event` varchar(512) NOT NULL,
|
||||
`error` varchar(1024) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `date` (`date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Event scheduler error log'
|
||||
```
|
||||
|
||||
Then adjust the *$logTable* variable to the correct schema.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
minFree=1
|
||||
memFree=$(free --gibi | awk '$1 == "Mem:" { print $7 }')
|
||||
|
||||
if [ "$memFree" -le "$minFree" ]; then
|
||||
echo "Free memory is ${memFree}Gi, restarting mariadb service to prevent OOM killer..."
|
||||
systemctl restart mariadb
|
||||
fi
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
OUTFILE=privs.sql
|
||||
SCHEMA=mysql
|
||||
TABLES=(
|
||||
global_priv
|
||||
db
|
||||
tables_priv
|
||||
columns_priv
|
||||
procs_priv
|
||||
proxies_priv
|
||||
roles_mapping
|
||||
)
|
||||
|
||||
echo "USE \`$SCHEMA\`;" > "$OUTFILE"
|
||||
|
||||
for TABLE in "${TABLES[@]}"
|
||||
do
|
||||
echo "TRUNCATE TABLE \`$SCHEMA\`.\`$TABLE\`;" >> "$OUTFILE"
|
||||
done
|
||||
|
||||
echo "" >> "$OUTFILE"
|
||||
mysqldump --no-create-info --skip-triggers "$SCHEMA" ${TABLES[@]} >> "$OUTFILE"
|
||||
|
||||
echo "FLUSH PRIVILEGES;" >> "$OUTFILE"
|
File diff suppressed because it is too large
Load Diff
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql -e "SET GLOBAL event_scheduler = OFF"
|
||||
|
||||
echo "SELECT db, name FROM mysql.event WHERE status = 'SLAVESIDE_DISABLED'" | mysql --raw --silent | \
|
||||
awk '{
|
||||
gsub("`", "``", $1);
|
||||
gsub("`", "``", $2);
|
||||
print "`"$1"`.`"$2"`";
|
||||
}' | \
|
||||
while read event; do
|
||||
mysql -e "ALTER EVENT $event ENABLE"
|
||||
done
|
||||
|
||||
mysql -e "SET GLOBAL event_scheduler = ON"
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql -e "SET GLOBAL event_scheduler = OFF"
|
||||
|
||||
echo "SELECT db, name FROM mysql.event WHERE status = 'ENABLED'" | mysql --raw --silent | \
|
||||
awk '{
|
||||
gsub("`", "``", $1);
|
||||
gsub("`", "``", $2);
|
||||
print "`"$1"`.`"$2"`";
|
||||
}' | \
|
||||
while read event; do
|
||||
mysql -e "ALTER EVENT $event DISABLE ON SLAVE"
|
||||
done
|
||||
|
||||
mysql -e "SET GLOBAL event_scheduler = ON"
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
logFile="/var/log/mysql/error.log"
|
||||
dateFile="/tmp/mysql_scheduler_log-lastdate"
|
||||
logTable="util.eventLog"
|
||||
purgeDays=30
|
||||
|
||||
quote() {
|
||||
local str=${1//\'/\'\'/}
|
||||
local str=${str//\\/\\\\}
|
||||
echo "'$str'"
|
||||
}
|
||||
|
||||
mysql -e "SELECT TRUE" > /dev/null 2>&1
|
||||
if [ "$?" -ne "0" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -f "$dateFile" ]; then
|
||||
fromDate=$(cat "$dateFile")
|
||||
else
|
||||
fromDate=0
|
||||
fi
|
||||
|
||||
lastDate=$(tail -n1 "$logFile" | awk '{print $1" "$2}')
|
||||
toDate=$(date +%s -d "$lastDate")
|
||||
|
||||
awk -v fromDate="$fromDate" -v toDate="$toDate" '{
|
||||
split($1, date, "-");
|
||||
split($2, time, ":");
|
||||
timestamp = mktime(date[1]" "date[2]" "date[3]" "time[1]" "time[2]" "time[3])
|
||||
if (timestamp >= fromDate && timestamp < toDate && $4" "$5" "$6 == "[ERROR] Event Scheduler:") {
|
||||
printf $1" "$2" "$7;
|
||||
for (i=8; i<=NF; i++) printf FS $i ;
|
||||
print "";
|
||||
}
|
||||
}' "$logFile" | \
|
||||
\
|
||||
while read line; do
|
||||
date="$(echo "$line" | cut -d' ' -f1,2)"
|
||||
event="$(echo "$line" | cut -d' ' -f3)"
|
||||
error="$(echo "$line" | cut -d' ' -f4-)"
|
||||
echo "INSERT INTO $logTable (date, event, error)" \
|
||||
"VALUES ($(quote "$date"), $(quote "$event"), $(quote "$error"))" | mysql
|
||||
done
|
||||
|
||||
echo -n "$toDate" > "$dateFile"
|
||||
echo "DELETE FROM $logTable WHERE date < TIMESTAMPADD(DAY, -$purgeDays, NOW())" | mysql
|
|
@ -5,9 +5,3 @@
|
|||
- name: reload-systemd
|
||||
command:
|
||||
cmd: systemctl daemon-reload
|
||||
- name: restart-mariadb
|
||||
systemd:
|
||||
name: mariadb
|
||||
state: restarted
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
- import_tasks: timeserver.yml
|
||||
tags: timeserver
|
||||
- import_tasks: mariadb.yml
|
||||
tags: mariadb
|
||||
- import_tasks: adsamba.yml
|
||||
tags: adsamba
|
||||
|
|
|
@ -1,226 +0,0 @@
|
|||
# Review /root/scripts/check-memory.sh --> It's not optimal to do what this program does
|
||||
# Also review the cron task /root/scripts/scheduler-log.sh
|
||||
|
||||
- name: Ensure Install requirements for MariaDB repository setup script
|
||||
apt:
|
||||
name: "{{ mariadb_requeriments }}"
|
||||
state: present
|
||||
install_recommends: no
|
||||
|
||||
- name: Download required setup files
|
||||
get_url:
|
||||
url: "{{ item.url }}"
|
||||
dest: "{{ item.dest }}"
|
||||
mode: "{{ item.mode }}"
|
||||
loop: "{{ downloads }}"
|
||||
|
||||
- name: Run MariaDB repository setup script
|
||||
command:
|
||||
cmd: "/bin/bash /tmp/mariadb_repo_setup --mariadb-server-version=10.11.10"
|
||||
creates: "/etc/apt/sources.list.d/mariadb.list"
|
||||
|
||||
- name: Install Percona repository package
|
||||
apt:
|
||||
deb: "/tmp/percona-release_latest.generic_all.deb"
|
||||
state: present
|
||||
install_recommends: no
|
||||
|
||||
- name: Install MariaDB packages
|
||||
apt:
|
||||
name: "{{ mariadb_base_packages }}"
|
||||
state: present
|
||||
install_recommends: no
|
||||
|
||||
- name: Ensure required directories exist
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
owner: "{{ item.owner }}"
|
||||
group: "{{ item.group }}"
|
||||
mode: "{{ item.mode }}"
|
||||
loop: "{{ required_directories }}"
|
||||
|
||||
- name: Ensure required custom and Mariabackup files are copied to their destinations and root scripts
|
||||
copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "{{ item.mode }}"
|
||||
loop: "{{ required_files_and_mariabackup_files_and_root_scripts }}"
|
||||
notify: reload-systemd
|
||||
|
||||
- name: Add tmpfs in /etc/fstab
|
||||
blockinfile:
|
||||
path: /etc/fstab
|
||||
marker: "# {mark} ANSIBLE-MANAGED TMPFS ENTRY"
|
||||
block: |
|
||||
tmpfs /mnt/mysqltmp tmpfs rw,size={{ mysqltmpsize }} 0 0
|
||||
register: fstab
|
||||
|
||||
- name: Mount all filesystems from /etc/fstab
|
||||
command: mount -a
|
||||
when: fstab.changed
|
||||
|
||||
- name: Set MariaDB Cron to /etc/cron.d
|
||||
template:
|
||||
src: templates/cron_mariadb
|
||||
dest: /etc/cron.d/vn
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
|
||||
- name: Insert MySQL certificates
|
||||
no_log: true
|
||||
copy:
|
||||
content: "{{ item.content }}"
|
||||
dest: "{{ item.dest }}"
|
||||
owner: mysql
|
||||
group: mysql
|
||||
mode: "{{ item.mode }}"
|
||||
loop: "{{ certificates }}"
|
||||
notify: restart-mariadb
|
||||
|
||||
- when: db.branch == 'production'
|
||||
block:
|
||||
- name: Set MariaDB custom configuration Production
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /etc/mysql/mariadb.conf.d/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
with_items:
|
||||
- "mariaconfigfiles/z90-vn.cnf"
|
||||
- "mariaconfigfiles/z95-production.cnf"
|
||||
notify: restart-mariadb
|
||||
|
||||
- name: Reminder to check mount points
|
||||
debug:
|
||||
msg: |
|
||||
Remember to check the following mount points:
|
||||
- /var/lib/mysql
|
||||
- /mnt/mysqlbin
|
||||
- /mnt/local-backup
|
||||
Make sure they are correctly configured and accessible.
|
||||
|
||||
- when: db.branch == 'test'
|
||||
|
||||
block:
|
||||
- name: Set MariaDB custom configuration TestDB
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /etc/mysql/mariadb.conf.d/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
with_items:
|
||||
- "files/mariaconfigfiles/z90-vn.cnf"
|
||||
- "files/mariaconfigfiles/z92-testing_dev.cnf"
|
||||
notify: restart-mariadb
|
||||
|
||||
- name: Set MariaBackup custom template configuration TestDB
|
||||
template:
|
||||
src: test-db_dev/apply.config.sh
|
||||
dest: /root/mariabackup/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=,o=
|
||||
|
||||
- name: Set MariaDB local configuration file for TestDB
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /root/mariabackup/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
with_items:
|
||||
- "mariabackuptest/apply.sql"
|
||||
- "mariabackuptest/bacula-after.sh"
|
||||
|
||||
- name: Reminder to check mount points environment TestDB
|
||||
debug:
|
||||
msg: |
|
||||
Remember to check the following mount points:
|
||||
- /mnt/mysqltmp
|
||||
Make sure they are correctly configured and accessible.
|
||||
|
||||
- when: db.branch == 'dev'
|
||||
|
||||
block:
|
||||
- name: Set MariaDB custom configuration DevDB
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /etc/mysql/mariadb.conf.d/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
with_items:
|
||||
- "files/mariaconfigfiles/z90-vn.cnf"
|
||||
- "files/mariaconfigfiles/z92-testing_dev.cnf"
|
||||
notify: restart-mariadb
|
||||
|
||||
- name: Set MariaBackup custom template configuration DevDB
|
||||
template:
|
||||
src: test-db_dev/apply.config.sh
|
||||
dest: /root/mariabackup/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=,o=
|
||||
|
||||
- name: Set MariaDB local configuration file for DevDB
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /root/mariabackup/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
with_items:
|
||||
- "mariabackupdev/apply.sql"
|
||||
- "mariabackupdev/bacula-after.sh"
|
||||
|
||||
- name: Reminder to check mount points environment DevDB
|
||||
debug:
|
||||
msg: |
|
||||
Remember to check the following mount points:
|
||||
- /mnt/mysqltmp
|
||||
Make sure they are correctly configured and accessible.
|
||||
|
||||
- name: Set Custom Configuration local template all Environment
|
||||
template:
|
||||
src: z99-local.cnf
|
||||
dest: /etc/mysql/mariadb.conf.d/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=r,o=r
|
||||
|
||||
- name: Set MariaBackup custom template configuration all Environment
|
||||
template:
|
||||
src: "my.cnf"
|
||||
dest: /root/mariabackup/
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rw,g=,o=
|
||||
|
||||
- name: Check if /var/lib/mysql/ exists
|
||||
stat:
|
||||
path: /var/lib/mysql/
|
||||
register: mysql_dir
|
||||
|
||||
|
||||
- when: mysql_dir.stat.exists
|
||||
block:
|
||||
|
||||
- name: Sync MySQL data directory
|
||||
synchronize:
|
||||
src: /var/lib/mysql/
|
||||
dest: /mnt/mysqldata/mysql/
|
||||
archive: true
|
||||
compress: true
|
||||
recursive: true
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
|
||||
- name: Remove old MySQL data after sync
|
||||
file:
|
||||
path: /var/lib/mysql/
|
||||
state: absent
|
|
@ -1,4 +0,0 @@
|
|||
MAILTO="{{ sysadmin_mail }}"
|
||||
|
||||
*/15 * * * * root /root/scripts/check-memory.sh
|
||||
*/30 * * * * root /root/scripts/scheduler-log.sh
|
|
@ -1,7 +0,0 @@
|
|||
[mariabackup]
|
||||
host = localhost
|
||||
user = mariabackup
|
||||
password = {{ lookup(passbolt, 'mariabackup', folder_parent_id=passbolt_folder).password }}
|
||||
use-memory = 1G
|
||||
parallel = 2
|
||||
stream = mbstream
|
|
@ -1,20 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Bacula directory for restore
|
||||
baculaDir=/mnt/mysqldata/bacula-restore
|
||||
|
||||
# Database branch name
|
||||
dbBranch={{ db.branch }}
|
||||
|
||||
# Database environment
|
||||
dbEnvironment={{ dbEnvironment }}
|
||||
|
||||
# MariaDB cluster sibling node hostnames
|
||||
dbClusterSiblings=()
|
||||
|
||||
# Jenkins authentication string
|
||||
jenkinsAuth=jenkins:{{ lookup(passbolt, 'jenkinsAuth', folder_parent_id=passbolt_folder).password }}
|
||||
|
||||
# Jenkins job URL
|
||||
jenkinsUrl=https://jenkins.verdnatura.es/job/Scheduler/job/db-apply-changes-{{ db.branch }}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
[mysqld]
|
||||
|
||||
server-id = {{ serverid }}
|
||||
#bind-address = 127.0.0.1
|
||||
#event-scheduler = OFF
|
||||
#skip-log-bin
|
||||
#skip-slave-start
|
Loading…
Reference in New Issue