From 823f5325df405286024cdf2a985732baabc0981f Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 21 Mar 2018 22:00:26 +0100 Subject: Add Dockerfile for simple Master/Slave replication and add more parametrization --- Dockerfile | 2 +- mysql/Dockerfile | 19 +++++ mysql/Makefile | 47 +++++++++++ mysql/root-galera/etc/yum.repos.d/galera.repo | 11 +++ mysql/root-galera/usr/bin/peer-finder | Bin 0 -> 2214569 bytes mysql/root-galera/usr/bin/run-mysqld-galera | 71 ++++++++++++++++ mysql/root-galera/usr/bin/run-mysqld-manager | 91 +++++++++++++++++++++ .../share/container-scripts/mysql/galera-common.sh | 61 ++++++++++++++ .../mysql/galera-init/60-galera-config.sh | 6 ++ .../mysql/galera-init/galera.cnf.template | 15 ++++ .../container-scripts/mysql/galera/cluster.cnf | 4 + .../mysql/galera/configure-galera.sh | 48 +++++++++++ .../mysql/init/50-galera-passwd-change.sh | 17 ++++ .../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 ++++++ .../mysql/pre-init/30-ands-tuning.sh | 24 ++++++ .../mysql/pre-init/ands-slave-logbin.cnf.template | 2 + .../mysql/pre-init/ands-slave.cnf.template | 5 ++ .../mysql/pre-init/ands-tuning.cnf.template | 6 ++ .../mysql/pre-init/my-master.cnf.template | 7 ++ .../mysql/pre-init/my-repl-gtid.cnf.template | 6 ++ .../mysql/pre-init/my-slave.cnf.template | 7 ++ root-galera/etc/yum.repos.d/galera.repo | 11 --- root-galera/usr/bin/peer-finder | Bin 2214569 -> 0 bytes root-galera/usr/bin/run-mysqld-galera | 69 ---------------- 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 | 21 ----- .../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 ------ 37 files changed, 500 insertions(+), 394 deletions(-) create mode 100644 mysql/Dockerfile create mode 100644 mysql/Makefile create mode 100644 mysql/root-galera/etc/yum.repos.d/galera.repo create mode 100755 mysql/root-galera/usr/bin/peer-finder create mode 100755 mysql/root-galera/usr/bin/run-mysqld-galera create mode 100755 mysql/root-galera/usr/bin/run-mysqld-manager create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/galera-common.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf create mode 100755 mysql/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/init/52-super.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/init/53-pma.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/30-ands-tuning.sh create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave-logbin.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-tuning.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-master.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-repl-gtid.cnf.template create mode 100644 mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-slave.cnf.template delete mode 100644 root-galera/etc/yum.repos.d/galera.repo delete mode 100755 root-galera/usr/bin/peer-finder delete mode 100755 root-galera/usr/bin/run-mysqld-galera delete mode 100755 root-galera/usr/bin/run-mysqld-manager delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-common.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/60-galera-config.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria delete mode 100644 root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf delete mode 100755 root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/51-extradb.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/52-super.sh delete mode 100644 root-galera/usr/share/container-scripts/mysql/init/53-pma.sh diff --git a/Dockerfile b/Dockerfile index 02c5ca3..c61419a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN INSTALL_PKGS="galera-3 mysql-wsrep-5.7 iproute rsync which socat percona-xtr rpm -V $INSTALL_PKGS && \ yum clean all -COPY root-galera / +COPY mysql/root-galera / ENV MYSQL_PREFIX=/usr \ ENABLED_COLLECTIONS="" diff --git a/mysql/Dockerfile b/mysql/Dockerfile new file mode 100644 index 0000000..66aa7a0 --- /dev/null +++ b/mysql/Dockerfile @@ -0,0 +1,19 @@ +FROM centos/mysql-57-centos7 + +USER root + +RUN INSTALL_PKGS="iproute rsync which socat percona-xtrabackup-24 bind-utils policycoreutils" && \ + yum install -y epel-release && \ + yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + yum install -y --setopt=tsflags=nodocs mc && \ + rpm -V $INSTALL_PKGS && \ + yum clean all + +COPY root-galera / + +RUN rm -rf /etc/my.cnf.d/* && \ + cp --remove-destination $(readlink /etc/my.cnf) /etc/my.cnf && \ + /usr/libexec/container-setup && rpm-file-permissions + +USER 27 diff --git a/mysql/Makefile b/mysql/Makefile new file mode 100644 index 0000000..fcf088d --- /dev/null +++ b/mysql/Makefile @@ -0,0 +1,47 @@ +all: build +install: push + +.PHONY: rebuild build push start stop restart bash peer-finder + + +build: Dockerfile + docker build --tag chsa/mysql:5.7 . + +rebuild: Dockerfile + docker build --no-cache --tag chsa/mysql:5.7 . + +push: build + docker push chsa/mysql:5.7 + +login: + docker login -u `oc whoami` -p `oc whoami -t` docker-registry-default.kaas.kit.edu + +kaas: build login + docker tag chsa/mysql:5.7 docker-registry-default.kaas.kit.edu/adei/mysql:5.7 + docker push docker-registry-default.kaas.kit.edu/adei/mysql:5.7 + + +start: build + if [ `docker ps | grep chsa/mysql | wc -l` -eq 0 ]; then \ + if [ `docker ps -a | grep mysql | wc -l` -gt 0 ]; then \ + echo "Removing the stalled copy..." ;\ + docker stop mysql ;\ + docker rm mysql ;\ + fi ;\ + docker run --name mysql -t -d chsa/mysql:5.7 ;\ + else \ + echo "Already running..." ;\ + fi + +stop: + @if [ `docker ps | grep mysql | wc -l` -gt 0 ]; then \ + docker stop mysql ;\ + docker rm mysql ;\ + fi + +restart: + make stop + make start + +bash: build + docker exec -it mysql /bin/bash diff --git a/mysql/root-galera/etc/yum.repos.d/galera.repo b/mysql/root-galera/etc/yum.repos.d/galera.repo new file mode 100644 index 0000000..b002165 --- /dev/null +++ b/mysql/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/mysql/root-galera/usr/bin/peer-finder b/mysql/root-galera/usr/bin/peer-finder new file mode 100755 index 0000000..af52ee1 Binary files /dev/null and b/mysql/root-galera/usr/bin/peer-finder differ diff --git a/mysql/root-galera/usr/bin/run-mysqld-galera b/mysql/root-galera/usr/bin/run-mysqld-galera new file mode 100755 index 0000000..1890209 --- /dev/null +++ b/mysql/root-galera/usr/bin/run-mysqld-galera @@ -0,0 +1,71 @@ +#!/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" -a ! -d "$MYSQL_DATADIR/.sst" ]; 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}.d/cluster.cnf | cat) + if [ -n "$no_cluster" ]; then + log_info "Configuration: $MYSQL_DEFAULTS_FILE" + log_info "No cluster is configured yet, trying to recover from failure..." + log_info "Allowing recovery in $MYSQL_DATADIR/grastate.dat" +# This seems a bad idea. If another pod is marked safe to bootstrap we may end up in conflict, I guess.... +# Keep it manual for now +# sed -i'' 's/safe_to_bootstrap:.*/safe_to_bootstrap: 1/' $MYSQL_DATADIR/grastate.dat +# This seems unneeded +# mysql_extra_opts="--wsrep-new-cluster" + else + log_info "Configuration: $MYSQL_DEFAULTS_FILE" + log_info "Cluster is configured. Trying to join..." + 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/mysql/root-galera/usr/bin/run-mysqld-manager b/mysql/root-galera/usr/bin/run-mysqld-manager new file mode 100755 index 0000000..91f3c9c --- /dev/null +++ b/mysql/root-galera/usr/bin/run-mysqld-manager @@ -0,0 +1,91 @@ +#!/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/mysql/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template new file mode 100644 index 0000000..c64a8cc --- /dev/null +++ b/mysql/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=500M; gcache.page_size=500M" +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/mysql/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf b/mysql/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf new file mode 100644 index 0000000..5e9d444 --- /dev/null +++ b/mysql/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/mysql/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh b/mysql/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh new file mode 100755 index 0000000..05829a4 --- /dev/null +++ b/mysql/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/mysql/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh b/mysql/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh new file mode 100644 index 0000000..5789bde --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +password_change() { +mysql $mysql_flags < /etc/my.cnf.d/ands-tuning.cnf + +if [ -v MYSQL_RUNNING_AS_SLAVE ] ; then + log_info 'Processing basic Ands configuration for replication (slave only) files ...' + envsubst < ${CONTAINER_SCRIPTS_PATH}/pre-init/ands-slave.cnf.template > /etc/my.cnf.d/ands-slave.cnf + + if [ $MYSQL_LOG_BIN -ne 0 ]; then + log_info 'Enabling log-bin in slave configuration files ...' + envsubst < ${CONTAINER_SCRIPTS_PATH}/pre-init/ands-slave-logbin.cnf.template > /etc/my.cnf.d/ands-slave-logbin.cnf + fi +fi + diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave-logbin.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave-logbin.cnf.template new file mode 100644 index 0000000..78c42e8 --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave-logbin.cnf.template @@ -0,0 +1,2 @@ +[mysqld] +log_bin = ${MYSQL_DATADIR}/mysql-bin.log diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave.cnf.template new file mode 100644 index 0000000..eae1e6a --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-slave.cnf.template @@ -0,0 +1,5 @@ +[mysqld] +slave_parallel_type=LOGICAL_CLOCK +slave_parallel_workers=${MYSQL_SLAVE_WORKERS} +log_slave_updates=${MYSQL_LOG_SLAVE_UPDATES} +slave_skip_errors=${MYSQL_SLAVE_SKIP_ERRORS} diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-tuning.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-tuning.cnf.template new file mode 100644 index 0000000..c5991df --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/ands-tuning.cnf.template @@ -0,0 +1,6 @@ +[mysqld] +sync_binlog=${MYSQL_SYNC_BINLOG} +binlog_group_commit_sync_delay=${MYSQL_BINLOG_SYNC_DELAY} +binlog_group_commit_sync_no_delay_count=${MYSQL_BINLOG_NODELAY_COUNT} +innodb_flush_log_at_trx_commit=${MYSQL_FLUSH_LOG_TYPE} +innodb_flush_log_at_timeout=${MYSQL_FLUSH_LOG_TIMEOUT} diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-master.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-master.cnf.template new file mode 100644 index 0000000..7c4c511 --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-master.cnf.template @@ -0,0 +1,7 @@ +[mysqld] + +server-id = ${MYSQL_SERVER_ID} +log_bin = ${MYSQL_DATADIR}/mysql-bin.log +#binlog_do_db = mysql +#binlog_do_db = ${MYSQL_DATABASE} +binlog_format = ${MYSQL_BINLOG_FORMAT} diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-repl-gtid.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-repl-gtid.cnf.template new file mode 100644 index 0000000..5e985ec --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-repl-gtid.cnf.template @@ -0,0 +1,6 @@ +[mysqld] + +gtid_mode = ON +#log-slave-updates = ON +enforce-gtid-consistency = ON + diff --git a/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-slave.cnf.template b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-slave.cnf.template new file mode 100644 index 0000000..879b94a --- /dev/null +++ b/mysql/root-galera/usr/share/container-scripts/mysql/pre-init/my-slave.cnf.template @@ -0,0 +1,7 @@ +[mysqld] + +server-id = ${MYSQL_SERVER_ID} +#log_bin = ${MYSQL_DATADIR}/mysql-bin.log +relay-log = ${MYSQL_DATADIR}/mysql-relay-bin.log +#binlog_do_db = mysql +#binlog_do_db = ${MYSQL_DATABASE} diff --git a/root-galera/etc/yum.repos.d/galera.repo b/root-galera/etc/yum.repos.d/galera.repo deleted file mode 100644 index b002165..0000000 --- a/root-galera/etc/yum.repos.d/galera.repo +++ /dev/null @@ -1,11 +0,0 @@ -[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 deleted file mode 100755 index af52ee1..0000000 Binary files a/root-galera/usr/bin/peer-finder and /dev/null differ diff --git a/root-galera/usr/bin/run-mysqld-galera b/root-galera/usr/bin/run-mysqld-galera deleted file mode 100755 index 9ff6c26..0000000 --- a/root-galera/usr/bin/run-mysqld-galera +++ /dev/null @@ -1,69 +0,0 @@ -#!/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}.d/cluster.cnf | cat) - if [ -n "$no_cluster" ]; then - log_info "Configuration: $MYSQL_DEFAULTS_FILE" - log_info "No cluster is configured yet, trying to recover from failure..." - log_info "Allowing recovery in $MYSQL_DATADIR/grastate.dat" - sed -i'' 's/safe_to_bootstrap:.*/safe_to_bootstrap: 1/' $MYSQL_DATADIR/grastate.dat -# This seems unneeded -# mysql_extra_opts="--wsrep-new-cluster" - else - log_info "Configuration: $MYSQL_DEFAULTS_FILE" - log_info "Cluster is configured. Trying to join..." - 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 deleted file mode 100755 index 878338a..0000000 --- a/root-galera/usr/bin/run-mysqld-manager +++ /dev/null @@ -1,90 +0,0 @@ -#!/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 deleted file mode 100644 index b45dc85..0000000 --- a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template +++ /dev/null @@ -1,21 +0,0 @@ -[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=500M; gcache.page_size=500M" -wsrep_sst_method = xtrabackup-v2 -default_storage_engine = innodb -binlog_format = row - -#MySQL tuning -#max_threads = 128 -#key_buffer_size = 1024K -#sort_buffer_size = 1024K -#read_buffer_size = 1024K - -# 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 deleted file mode 100644 index 3adbf58..0000000 --- a/root-galera/usr/share/container-scripts/mysql/galera-init/galera.cnf.template.maria +++ /dev/null @@ -1,17 +0,0 @@ -[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 deleted file mode 100644 index 5e9d444..0000000 --- a/root-galera/usr/share/container-scripts/mysql/galera/cluster.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[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 deleted file mode 100755 index 05829a4..0000000 --- a/root-galera/usr/share/container-scripts/mysql/galera/configure-galera.sh +++ /dev/null @@ -1,48 +0,0 @@ -#! /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 deleted file mode 100644 index 2844d5f..0000000 --- a/root-galera/usr/share/container-scripts/mysql/init/50-galera-passwd-change.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -password_change() { -mysql $mysql_flags <