From 14d10bc21087e3734d4e7ac15883c76d0cd19818 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sat, 17 Mar 2018 21:07:38 +0100 Subject: MySQL 5.7 with Galera (produced as combination of standard MySQL container and openshift-mariadb-galera by adfinis-sygroup) --- root-galera/etc/yum.repos.d/galera.repo | 11 +++ root-galera/usr/bin/peer-finder | Bin 0 -> 2987890 bytes root-galera/usr/bin/run-mysqld-galera | 64 +++++++++++++++ root-galera/usr/bin/run-mysqld-manager | 90 +++++++++++++++++++++ .../share/container-scripts/mysql/galera-common.sh | 61 ++++++++++++++ .../mysql/galera-init/60-galera-config.sh | 6 ++ .../mysql/galera-init/galera.cnf.template | 15 ++++ .../mysql/galera-init/galera.cnf.template.maria | 17 ++++ .../container-scripts/mysql/galera/cluster.cnf | 4 + .../mysql/galera/configure-galera.sh | 48 +++++++++++ .../mysql/init/50-galera-passwd-change.sh | 14 ++++ .../container-scripts/mysql/init/51-extradb.sh | 14 ++++ .../share/container-scripts/mysql/init/52-super.sh | 12 +++ .../share/container-scripts/mysql/init/53-pma.sh | 26 ++++++ 14 files changed, 382 insertions(+) create mode 100644 root-galera/etc/yum.repos.d/galera.repo create mode 100755 root-galera/usr/bin/peer-finder create mode 100755 root-galera/usr/bin/run-mysqld-galera create mode 100755 root-galera/usr/bin/run-mysqld-manager create mode 100644 root-galera/usr/share/container-scripts/mysql/galera-common.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template create mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria create mode 100644 root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf create mode 100755 root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/init/52-super.sh create mode 100644 root-galera/usr/share/container-scripts/mysql/init/53-pma.sh (limited to 'root-galera') diff --git a/root-galera/etc/yum.repos.d/galera.repo b/root-galera/etc/yum.repos.d/galera.repo new file mode 100644 index 0000000..b002165 --- /dev/null +++ b/root-galera/etc/yum.repos.d/galera.repo @@ -0,0 +1,11 @@ +[galera] +name = Galera +baseurl = http://releases.galeracluster.com/galera-3/centos/7/x86_64/ +gpgkey = http://releases.galeracluster.com/GPG-KEY-galeracluster.com +gpgcheck = 1 + +[mysql-wsrep] +name = MySQL-wsrep +baseurl = http://releases.galeracluster.com/mysql-wsrep-5.7/centos/7/x86_64/ +gpgkey = http://releases.galeracluster.com/GPG-KEY-galeracluster.com +gpgcheck = 1 diff --git a/root-galera/usr/bin/peer-finder b/root-galera/usr/bin/peer-finder new file mode 100755 index 0000000..7858f19 Binary files /dev/null and b/root-galera/usr/bin/peer-finder differ diff --git a/root-galera/usr/bin/run-mysqld-galera b/root-galera/usr/bin/run-mysqld-galera new file mode 100755 index 0000000..f1a0d76 --- /dev/null +++ b/root-galera/usr/bin/run-mysqld-galera @@ -0,0 +1,64 @@ +#!/bin/bash + +if [ -v POD_NAMESPACE ]; then + cp "${CONTAINER_SCRIPTS_PATH}/galera/cluster.cnf" /etc/my.cnf.d/ + + # Is running in Kubernetes/OpenShift, so find all other pods + # belonging to the namespace + echo "Galera: Finding peers" + [ -v MYSQL_GALERA_CLUSTER ] || MYSQL_GALERA_CLUSTER="$(hostname -f | cut -d'.' -f2)" + K8S_SVC_NAME=${MYSQL_GALERA_CLUSTER} + echo "Using service name: ${K8S_SVC_NAME}" + /usr/bin/peer-finder -on-start="${CONTAINER_SCRIPTS_PATH}/galera/configure-galera.sh" -service=${K8S_SVC_NAME} +else + echo "POD_NAMESPACE not set, spin up single node" +fi + + +export_vars=$(cgroup-limits); export $export_vars +source ${CONTAINER_SCRIPTS_PATH}/galera-common.sh +set -eu +if [[ -v DEBUG_IGNORE_SCRIPT_FAILURES ]]; then + set +e +fi + +export_setting_variables + +log_volume_info $MYSQL_DATADIR + +# pre-init files +process_extending_files ${APP_DATA}/mysql-pre-init/ ${CONTAINER_SCRIPTS_PATH}/pre-init/ + +mysql_extra_opts="" +if [ ! -d "$MYSQL_DATADIR/mysql" ]; then + initialize_galera_database "$@" + + # galera files + process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/ + + # init files + process_extending_files ${APP_DATA}/mysql-init/ ${CONTAINER_SCRIPTS_PATH}/init/ + + # Restart the MySQL server with public IP bindings + shutdown_local_mysql +else + no_cluster=$(grep -P "gcomm://$" $MYSQL_DEFAULTS_FILE/cluster.cnf | cat) + if [ -n "$no_cluster" ]; then + log_info "No cluster configured, recovering from failure..." + log_info "Allowing recovery in $MYSQL_DATADIR/grastate.dat" + sed -i'' -e 's/safe_to_bootstrap:.*/safe_to_bootstrap: 1/' $MYSQL_DATADIR/grastate.dat + mysql_extra_opts="--wsrep-new-cluster" + fi + + # galera files + process_extending_files ${APP_DATA}/mysql-galera-init/ ${CONTAINER_SCRIPTS_PATH}/galera-init/ + +# I guess we can't do that once cluster is existing... +# start_local_mysql --wsrep-on=OFF --wsrep-provider=none "$@" +fi + +unset_env_vars +log_volume_info $MYSQL_DATADIR +log_info "Running final exec - mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts $@" + +exec ${MYSQL_PREFIX}/libexec/mysqld --defaults-file=$MYSQL_DEFAULTS_FILE $mysql_extra_opts "$@" 2>&1 diff --git a/root-galera/usr/bin/run-mysqld-manager b/root-galera/usr/bin/run-mysqld-manager new file mode 100755 index 0000000..878338a --- /dev/null +++ b/root-galera/usr/bin/run-mysqld-manager @@ -0,0 +1,90 @@ +#!/bin/bash + +export TERM=xterm +function display_container_header { + echo "+=====================================================" + echo "| Container : $HOSTNAME" + echo "| OS : $( "5.6" ]] ; then + mysql $mysql_flags < /etc/my.cnf.d/galera.cnf +fi diff --git a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template new file mode 100644 index 0000000..e1013d7 --- /dev/null +++ b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template @@ -0,0 +1,15 @@ +[mysqld] +wsrep_on = ON +wsrep_provider = /usr/lib64/galera-3/libgalera_smm.so +wsrep_sst_auth=${MYSQL_GALERA_USER}:${MYSQL_GALERA_PASSWORD} +wsrep_cluster_name=${MYSQL_GALERA_CLUSTER} +#wsrep_provider_options="gcache.size=300M; gcache.page_size=300M" +wsrep_sst_method = xtrabackup-v2 +default_storage_engine = innodb +binlog_format = row + +# Performance settings +innodb_autoinc_lock_mode = 2 +innodb_flush_log_at_trx_commit = 0 +query_cache_size = 0 +query_cache_type = 0 diff --git a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria new file mode 100644 index 0000000..3adbf58 --- /dev/null +++ b/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria @@ -0,0 +1,17 @@ +[galera] +wsrep_on = ON +wsrep_provider = /usr/lib64/galera/libgalera_smm.so +wsrep_sst_method = xtrabackup-v2 +default_storage_engine = innodb +binlog_format = row +innodb_autoinc_lock_mode = 2 +innodb_flush_log_at_trx_commit = 0 +query_cache_size = 0 +query_cache_type = 0 + +wsrep_sst_auth=${MYSQL_GALERA_USER}:${MYSQL_GALERA_PASSWORD} +wsrep_cluster_name=${MYSQL_GALERA_CLUSTER} + +# By default every node is standalone +wsrep_cluster_address=gcomm:// +wsrep_node_address=127.0.0.1 diff --git a/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf b/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf new file mode 100644 index 0000000..5e9d444 --- /dev/null +++ b/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf @@ -0,0 +1,4 @@ +[mysqld] +# By default every node is standalone +wsrep_cluster_address=gcomm:// +wsrep_node_address=127.0.0.1 diff --git a/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh b/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh new file mode 100755 index 0000000..05829a4 --- /dev/null +++ b/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script writes out a mysql galera config using a list of newline seperated +# peer DNS names it accepts through stdin. + +# /etc/mysql is assumed to be a shared volume so we can modify my.cnf as required +# to keep the config up to date, without wrapping mysqld in a custom pid1. +# The config location is intentionally not /etc/mysql/my.cnf because the +# standard base image clobbers that location. +CFG=/etc/my.cnf.d/cluster.cnf + +function join { + local IFS="$1"; shift; echo "$*"; +} + +HOSTNAME=$(hostname) +while read -ra LINE; do + if [[ "${LINE}" == *"${HOSTNAME}"* ]]; then + MY_NAME=$LINE + fi + PEERS=("${PEERS[@]}" $LINE) +done + +if [ "${#PEERS[@]}" = 1 ]; then + WSREP_CLUSTER_ADDRESS="" +else + WSREP_CLUSTER_ADDRESS=$(join , "${PEERS[@]}") +fi + +sed -i -e "s|^wsrep_node_address=.*$|wsrep_node_address=${MY_NAME}|" ${CFG} +sed -i -e "s|^wsrep_cluster_address=.*$|wsrep_cluster_address=gcomm://${WSREP_CLUSTER_ADDRESS}|" ${CFG} + +# don't need a restart, we're just writing the conf in case there's an +# unexpected restart on the node. diff --git a/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh b/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh new file mode 100644 index 0000000..2844d5f --- /dev/null +++ b/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +password_change() { +mysql $mysql_flags <