diff --git a/flavours/mysql/README.md b/flavours/mysql/README.md new file mode 100644 index 00000000..39a6ab8c --- /dev/null +++ b/flavours/mysql/README.md @@ -0,0 +1,3 @@ +Sets up a MySQL server install in the image. + +TODO: auto-tune settings based on host resources or metadata service. diff --git a/flavours/mysql/first-boot.d/05-ipforwarding b/flavours/mysql/first-boot.d/05-ipforwarding new file mode 100755 index 00000000..4824cfcf --- /dev/null +++ b/flavours/mysql/first-boot.d/05-ipforwarding @@ -0,0 +1,5 @@ +#!/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/flavours/mysql/first-boot.d/10-ntp b/flavours/mysql/first-boot.d/10-ntp new file mode 100755 index 00000000..860e3fb2 --- /dev/null +++ b/flavours/mysql/first-boot.d/10-ntp @@ -0,0 +1,11 @@ +#!/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/flavours/mysql/first-boot.d/50-mysql b/flavours/mysql/first-boot.d/50-mysql new file mode 100755 index 00000000..8aa6ec3c --- /dev/null +++ b/flavours/mysql/first-boot.d/50-mysql @@ -0,0 +1,24 @@ +#!/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 + +CNF=/etc/mysql/my.cnf +cp -f $(dirname $0)/my.cnf $CNF +sed -i "s/^bind-address=.*/bind-address=$HOST_IP/" $CNF + +service mysql start diff --git a/flavours/mysql/first-boot.d/defaults b/flavours/mysql/first-boot.d/defaults new file mode 100644 index 00000000..2c497d00 --- /dev/null +++ b/flavours/mysql/first-boot.d/defaults @@ -0,0 +1,15 @@ +set -e + +MYSQL_PASS=${MYSQL_PASS:-password} + +# HOST_IP +# Find the interface used for the default route +HOST_IP_IFACE=${HOST_IP_IFACE:-$(ip route | sed -n '/^default/{ s/.*dev \(\w\+\)\s\+.*/\1/; p; }')} +# Search for an IP unless an explicit is set by ``HOST_IP`` environment variable +HOST_IP=`LC_ALL=C ip -f inet addr show ${HOST_IP_IFACE} | awk '/inet/ {split($2,parts,"/"); print parts[1]}'` + + +# XXX: get all these from metadata service eventually +IB_BUF_POOL=100M +IB_LOG_FILE_SIZE=10M + diff --git a/flavours/mysql/first-boot.d/my.cnf b/flavours/mysql/first-boot.d/my.cnf new file mode 100644 index 00000000..10d8c071 --- /dev/null +++ b/flavours/mysql/first-boot.d/my.cnf @@ -0,0 +1,63 @@ +[mysql] +port = 3306 +socket = /var/lib/mysql/data/mysql.sock + +[mysqld] + +# GENERAL # +user = mysql +default_storage_engine = InnoDB +socket = /var/lib/mysql/data/mysql.sock +pid_file = /var/lib/mysql/data/mysql.pid +bind-address = 0.0.0.0 + +# MyISAM # +key_buffer_size = 32M +myisam_recover = FORCE,BACKUP + +# SAFETY # +max_allowed_packet = 16M +max_connect_errors = 1000000 +skip_name_resolve +sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY +sysdate_is_now = 1 +innodb = FORCE +innodb_strict_mode = 1 + +# DATA STORAGE # +datadir = /var/lib/mysql/data/ + +# CACHES AND LIMITS # +tmp_table_size = 32M +max_heap_table_size = 32M +query_cache_type = 0 +query_cache_size = 0 +max_connections = 500 +thread_cache_size = 50 +open_files_limit = 65535 +table_definition_cache = 4096 +table_open_cache = 4096 + +# INNODB # +innodb_flush_method = O_DIRECT +innodb_log_files_in_group = 2 +innodb_log_file_size = 64M +innodb_flush_log_at_trx_commit = 2 +innodb_file_per_table = 1 +innodb_buffer_pool_size = 592M +# TODO +# innodb_read_io_threads +# innodb_write_io_threads + + +# LOGGING # +log_error = /var/lib/mysql/data/mysql-error.log +log_queries_not_using_indexes = 1 +slow_query_log = 1 +slow_query_log_file = /var/lib/mysql/data/mysql-slow.log + +server_id = 1 +log_bin = /var/lib/mysql/data/mysql-bin +expire_logs_days = 7 +max_binlog_size = 100M +binlog_format = ROW diff --git a/flavours/mysql/install.d/10-mysql b/flavours/mysql/install.d/10-mysql new file mode 100755 index 00000000..129fc9fc --- /dev/null +++ b/flavours/mysql/install.d/10-mysql @@ -0,0 +1,9 @@ +#!/bin/sh + +# Install controller base requiered packages + +set -e +set -o xtrace + +#DEBIAN_FRONTEND=noninteractive apt-get -y install sysstat mytop percona-toolkit percona-server-server-5.5 percona-server-client-5.5 +DEBIAN_FRONTEND=noninteractive apt-get -y install sysstat mytop percona-toolkit mysql-server-5.5 mysql-client-5.5 diff --git a/flavours/mysql/install.d/50-user b/flavours/mysql/install.d/50-user new file mode 100755 index 00000000..872ddb94 --- /dev/null +++ b/flavours/mysql/install.d/50-user @@ -0,0 +1,12 @@ +#!/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 < /etc/apt/sources.list.d/percona +#deb http://repo.percona.com/apt $VER main +#deb-src http://repo.percona.com/apt $VER main +#EOL