Clean up the MySQL element to make it suitable for generic use.

Change-Id: Ib3e384d6fb48e6df53a0897bcc48bbb46995a824
This commit is contained in:
Clint Byrum 2012-12-17 15:00:18 -08:00
parent 804e94b5eb
commit 05ccb5eab5
5 changed files with 30 additions and 53 deletions

View File

@ -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

View File

@ -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

View File

@ -1,24 +1,29 @@
#!/bin/bash #!/bin/bash
set -e set -uex
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 <<EOF > $sqltfile
USE mysql;
UPDATE user SET password=PASSWORD("$MYSQL_PASS") WHERE user='root';
EOF
$MYSQL_BOOTSTRAP < $sqltfile
rm -f $sqltfile
CNF=/etc/mysql/my.cnf CNF=/etc/mysql/my.cnf
cp -f $(dirname $0)/my.cnf $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 service mysql start

View File

@ -1,14 +1,14 @@
[mysql] [mysql]
port = 3306 port = 3306
socket = /var/lib/mysql/data/mysql.sock socket = /var/run/mysqld/mysqld.sock
[mysqld] [mysqld]
# GENERAL # # GENERAL #
user = mysql user = mysql
default_storage_engine = InnoDB default_storage_engine = InnoDB
socket = /var/lib/mysql/data/mysql.sock socket = /var/run/mysqld/mysqld.sock
pid_file = /var/lib/mysql/data/mysql.pid pid_file = /var/lib/mysql/mysql.pid
bind-address = 0.0.0.0 bind-address = 0.0.0.0
# MyISAM # # MyISAM #
@ -25,7 +25,7 @@ innodb = FORCE
innodb_strict_mode = 1 innodb_strict_mode = 1
# DATA STORAGE # # DATA STORAGE #
datadir = /var/lib/mysql/data/ datadir = /var/lib/mysql/
# CACHES AND LIMITS # # CACHES AND LIMITS #
tmp_table_size = 32M tmp_table_size = 32M
@ -51,13 +51,13 @@ innodb_buffer_pool_size = 592M
# LOGGING # # LOGGING #
log_error = /var/lib/mysql/data/mysql-error.log log_error = /var/log/mysql/error.log
log_queries_not_using_indexes = 1 log_queries_not_using_indexes = 1
slow_query_log = 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 server_id = 1
log_bin = /var/lib/mysql/data/mysql-bin log_bin = /var/lib/mysql/mysql-bin
expire_logs_days = 7 expire_logs_days = 7
max_binlog_size = 100M max_binlog_size = 100M
binlog_format = ROW binlog_format = ROW

View File

@ -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 <<EOF
stack
stack
EOF