From 05ccb5eab5bbc8914a166da68d7b144192fbd157 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Mon, 17 Dec 2012 15:00:18 -0800 Subject: [PATCH] Clean up the MySQL element to make it suitable for generic use. Change-Id: Ib3e384d6fb48e6df53a0897bcc48bbb46995a824 --- elements/mysql/first-boot.d/05-ipforwarding | 5 --- elements/mysql/first-boot.d/10-ntp | 11 ------ elements/mysql/first-boot.d/50-mysql | 41 ++++++++++++--------- elements/mysql/first-boot.d/my.cnf | 14 +++---- elements/mysql/install.d/50-user | 12 ------ 5 files changed, 30 insertions(+), 53 deletions(-) delete mode 100755 elements/mysql/first-boot.d/05-ipforwarding delete mode 100755 elements/mysql/first-boot.d/10-ntp delete mode 100755 elements/mysql/install.d/50-user diff --git a/elements/mysql/first-boot.d/05-ipforwarding b/elements/mysql/first-boot.d/05-ipforwarding deleted file mode 100755 index 4824cfcf..00000000 --- a/elements/mysql/first-boot.d/05-ipforwarding +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e -set -o xtrace -sed -i -r 's/^\s*#(net\.ipv4\.ip_forward=1.*)/\1/' /etc/sysctl.conf -echo 1 > /proc/sys/net/ipv4/ip_forward diff --git a/elements/mysql/first-boot.d/10-ntp b/elements/mysql/first-boot.d/10-ntp deleted file mode 100755 index 860e3fb2..00000000 --- a/elements/mysql/first-boot.d/10-ntp +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -ntpfile=`mktemp` -cat << EOF > $ntpfile -server ntp.ubuntu.com iburst -server 127.127.1.0 -fudge 127.127.1.0 stratum 10 -EOF - -mv /etc/ntp.conf /etc/ntp.conf.orig -mv $ntpfile /etc/ntp.conf -service ntp restart diff --git a/elements/mysql/first-boot.d/50-mysql b/elements/mysql/first-boot.d/50-mysql index 8aa6ec3c..1f188571 100755 --- a/elements/mysql/first-boot.d/50-mysql +++ b/elements/mysql/first-boot.d/50-mysql @@ -1,24 +1,29 @@ #!/bin/bash -set -e -set -o xtrace - -# get MYSQL_PASS and HOST_IP -source $(dirname $0)/defaults - -service mysql stop || true - -MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables" - -sqltfile=`mktemp` -cat < $sqltfile -USE mysql; -UPDATE user SET password=PASSWORD("$MYSQL_PASS") WHERE user='root'; -EOF -$MYSQL_BOOTSTRAP < $sqltfile -rm -f $sqltfile +set -uex CNF=/etc/mysql/my.cnf cp -f $(dirname $0)/my.cnf $CNF -sed -i "s/^bind-address=.*/bind-address=$HOST_IP/" $CNF +sed -i "s/^bind-address=.*/bind-address=0.0.0.0/" $CNF + +D_SYS_MAINT="--defaults-file=/etc/mysql/debian.cnf" + +# Since we will be clearing out ib_*, make sure there aren't any innodb tables. +if mysqladmin $D_SYS_MAINT ping ; then + innodb_tables=$(mysql $D_SYS_MAINT -N -e "SELECT count(*) FROM information_schema.TABLES WHERE ENGINE LIKE 'InnoDB'") + if [ -n "$innodb_tables" -a $innodb_tables -gt 0 ] ; then + echo Found $innodb_tables InnoDB tables. Any existing data may be lost. ABORT! + exit 1 + fi + service mysql stop +fi + + +# The new my.cnf may not jive with default innodb sizes, so just backup and clear out ib files +if [ -n "$(ls /var/lib/mysql/ib_*)" ] ; then + BACKUP_DIR=/var/backups/mysql-$(date +%Y%m%d%H%M%S) + mkdir -p $BACKUP_DIR + chmod 700 $BACKUP_DIR + mv -f /var/lib/mysql/ib_* $BACKUP_DIR +fi service mysql start diff --git a/elements/mysql/first-boot.d/my.cnf b/elements/mysql/first-boot.d/my.cnf index 10d8c071..6ca4bd4b 100644 --- a/elements/mysql/first-boot.d/my.cnf +++ b/elements/mysql/first-boot.d/my.cnf @@ -1,14 +1,14 @@ [mysql] port = 3306 -socket = /var/lib/mysql/data/mysql.sock +socket = /var/run/mysqld/mysqld.sock [mysqld] # GENERAL # user = mysql default_storage_engine = InnoDB -socket = /var/lib/mysql/data/mysql.sock -pid_file = /var/lib/mysql/data/mysql.pid +socket = /var/run/mysqld/mysqld.sock +pid_file = /var/lib/mysql/mysql.pid bind-address = 0.0.0.0 # MyISAM # @@ -25,7 +25,7 @@ innodb = FORCE innodb_strict_mode = 1 # DATA STORAGE # -datadir = /var/lib/mysql/data/ +datadir = /var/lib/mysql/ # CACHES AND LIMITS # tmp_table_size = 32M @@ -51,13 +51,13 @@ innodb_buffer_pool_size = 592M # LOGGING # -log_error = /var/lib/mysql/data/mysql-error.log +log_error = /var/log/mysql/error.log log_queries_not_using_indexes = 1 slow_query_log = 1 -slow_query_log_file = /var/lib/mysql/data/mysql-slow.log +slow_query_log_file = /var/log/mysql/mysql-slow.log server_id = 1 -log_bin = /var/lib/mysql/data/mysql-bin +log_bin = /var/lib/mysql/mysql-bin expire_logs_days = 7 max_binlog_size = 100M binlog_format = ROW diff --git a/elements/mysql/install.d/50-user b/elements/mysql/install.d/50-user deleted file mode 100755 index 872ddb94..00000000 --- a/elements/mysql/install.d/50-user +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Add the stack user we recommend folk use. - -set -e -set -o xtrace - -useradd -G admin -m stack -s /bin/bash -passwd stack <