Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mariadb tuning #793

Merged
merged 4 commits into from Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions images/mariadb-galera/Dockerfile
Expand Up @@ -91,8 +91,7 @@ RUN apk add --no-cache --virtual .common-run-deps \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/*

COPY docker-entrypoint.bash /lagoon/entrypoints/9999-mariadb-entrypoint
COPY maxscale-entrypoint.sh /lagoon/entrypoints/80-maxscale
COPY entrypoints/ /lagoon/entrypoints/
COPY maxscale.sql /docker-entrypoint-initdb.d/maxscale.sql
COPY maxscale.cnf /etc/maxscale.cnf
COPY maxscale-start.sh /usr/local/bin/maxscale-start
Expand All @@ -106,6 +105,7 @@ RUN for i in /var/run/mysqld /var/lib/mysql /etc/mysql/conf.d /docker-entrypoint
do mkdir -p $i; /bin/fix-permissions $i; \
done && \
/bin/fix-permissions /etc/maxscale.cnf && \
/bin/fix-permissions /etc/mysql && \
ln -s /var/lib/mysql/.my.cnf /home/.my.cnf && \
sed -i 's/#!\/bin\/bash -ue/#!\/bin\/bash -e/' /usr/bin/wsrep_sst_rsync

Expand All @@ -116,6 +116,9 @@ COPY root/usr/share/container-scripts/mysql/configure-galera.sh /usr/share/conta

RUN /bin/fix-permissions /usr/share/container-scripts/mysql/

RUN touch /var/log/mariadb-slow.log && /bin/fix-permissions /var/log/mariadb-slow.log \
&& touch /var/log/mariadb-queries.log && /bin/fix-permissions /var/log/mariadb-queries.log

### we cannot start mysql as root, we add the user mysql to the group root and change the user of the Docker Image to this user
RUN addgroup mysql root
USER mysql
Expand Down
13 changes: 13 additions & 0 deletions images/mariadb-galera/entrypoints/150-mariadb-performance.bash
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eo pipefail

if [ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]; then
# only set if not already defined
if [ -z ${MARIADB_INNODB_BUFFER_POOL_SIZE+x} ]; then
export MARIADB_INNODB_BUFFER_POOL_SIZE=1024M
fi
if [ -z ${MARIADB_INNODB_LOG_FILE_SIZE+x} ]; then
export MARIADB_INNODB_LOG_FILE_SIZE=256M
fi
fi
Expand Up @@ -129,5 +129,3 @@ EOF
echo "done, now starting daemon"

fi

exec $@
17 changes: 9 additions & 8 deletions images/mariadb-galera/my.cnf
Expand Up @@ -9,34 +9,35 @@ socket = /run/mysqld/mysqld.sock
[mysqld]
port = 3306
socket = /run/mysqld/mysqld.sock
character_set_server = utf8mb4
collation_server = utf8mb4_bin
character_set_server = ${MARIADB_CHARSET:-utf8mb4}
collation_server = ${MARIADB_COLLATION:-utf8mb4_bin}
expire_logs_days = 10
ignore_db_dirs=backup
innodb_buffer_pool_size = 256M
innodb_buffer_pool_size = ${MARIADB_INNODB_BUFFER_POOL_SIZE:-256M}
innodb_buffer_pool_instances = ${MARIADB_INNODB_BUFFER_POOL_INSTANCES:-1}
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 100M
innodb_log_file_size = ${MARIADB_INNODB_LOG_FILE_SIZE:-64M}
join_buffer_size = 2M
key_buffer_size = 16M
max_allowed_packet = 64M
max_binlog_size = 100M
max_connections = 400
max_heap_table_size = 512M
myisam-recover-options = BACKUP
query_cache_limit = 1M
query_cache_size = 128M
query_cache_size = 0
query_cache_type = 0
skip-external-locking
skip_name_resolve = 1
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log
table_open_cache = 200000
thread_cache_size = 8
thread_stack = 256K
tmp_table_size = 512M
tmpdir = /tmp
transaction-isolation = READ-COMMITTED
skip-name-resolve
optimizer_search_depth = 0
innodb_flush_log_at_trx_commit = 0

!includedir /etc/mysql/conf.d
15 changes: 4 additions & 11 deletions images/mariadb/Dockerfile
Expand Up @@ -28,10 +28,6 @@ ENV MARIADB_DATABASE=lagoon \
MARIADB_PASSWORD=lagoon \
MARIADB_ROOT_PASSWORD=Lag00n

# fix some environmental items
RUN mkdir -p /usr/include/bits; mkdir -p /usr/
COPY root/usr/include/bits/wordsize.h /usr/include/bits/wordsize.h

RUN \
apk add --no-cache --virtual .common-run-deps \
bash \
Expand All @@ -47,24 +43,21 @@ RUN \
rm -rf /var/lib/mysql/* /etc/mysql/; \
curl -sSL http://mysqltuner.pl/ -o mysqltuner.pl

COPY logging.bash /lagoon/entrypoints/10-mariadb-logging
COPY envplate.bash /lagoon/entrypoints/20-mariadb-envplate
COPY docker-entrypoint.bash /lagoon/entrypoints/9999-mariadb-entrypoint
COPY entrypoints/ /lagoon/entrypoints/
COPY mysql-backup.sh /lagoon/
COPY my.cnf /etc/mysql/my.cnf

RUN for i in /var/run/mysqld /var/lib/mysql /etc/mysql/conf.d /docker-entrypoint-initdb.d/ "${BACKUPS_DIR}"; \
do mkdir -p $i; chown mysql $i; /bin/fix-permissions $i; \
done && \
ln -s /var/lib/mysql/.my.cnf /home/.my.cnf && \
sed -i 's/#!\/bin\/bash -ue/#!\/bin\/bash -e/' /usr/bin/wsrep_sst_rsync
ln -s /var/lib/mysql/.my.cnf /home/.my.cnf

COPY root/usr/share/container-scripts/mysql/readiness-probe.sh /usr/share/container-scripts/mysql/readiness-probe.sh
RUN /bin/fix-permissions /usr/share/container-scripts/mysql/ \
&& /bin/fix-permissions /etc/mysql

RUN touch /var/log/mariadb-slow.log && /bin/fix-permissions /var/log/mariadb-slow.log
RUN touch /var/log/mariadb-queries.log && /bin/fix-permissions /var/log/mariadb-queries.log
RUN touch /var/log/mariadb-slow.log && /bin/fix-permissions /var/log/mariadb-slow.log \
&& touch /var/log/mariadb-queries.log && /bin/fix-permissions /var/log/mariadb-queries.log

# We cannot start mysql as root, we add the user mysql to the group root and
# change the user of the Docker Image to this user.
Expand Down
24 changes: 24 additions & 0 deletions images/mariadb/entrypoints/100-mariadb-logging.bash
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -eo pipefail

if [ -n "$MARIADB_LOG_SLOW" ]; then
echo "MARIADB_LOG_SLOW set, logging to /etc/mysql/conf.d/log-slow.cnf"
cat <<EOF > /etc/mysql/conf.d/log-slow.cnf
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mariadb-slow.log
EOF
fi


if [ -n "$MARIADB_LOG_QUERIES" ]; then
echo "MARIADB_LOG_QUERIES set, logging to /etc/mysql/conf.d/log-queries.cnf"
cat <<EOF > /etc/mysql/conf.d/log-queries.cnf

[mysqld]
general-log
log-output=file
general-log-file=/var/log/mariadb-queries.log
EOF
fi
13 changes: 13 additions & 0 deletions images/mariadb/entrypoints/150-mariadb-performance.bash
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eo pipefail

if [ "$LAGOON_ENVIRONMENT_TYPE" == "production" ]; then
# only set if not already defined
if [ -z ${MARIADB_INNODB_BUFFER_POOL_SIZE+x} ]; then
export MARIADB_INNODB_BUFFER_POOL_SIZE=1024M
fi
if [ -z ${MARIADB_INNODB_LOG_FILE_SIZE+x} ]; then
export MARIADB_INNODB_LOG_FILE_SIZE=256M
fi
fi
5 changes: 5 additions & 0 deletions images/mariadb/entrypoints/200-mariadb-envplate.bash
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eo pipefail

/bin/ep /etc/mysql/*
Expand Up @@ -112,5 +112,3 @@ EOF
echo "done, now starting daemon"

fi

exec $@
15 changes: 7 additions & 8 deletions images/mariadb/my.cnf
Expand Up @@ -13,24 +13,21 @@ character_set_server = ${MARIADB_CHARSET:-utf8mb4}
collation_server = ${MARIADB_COLLATION:-utf8mb4_bin}
expire_logs_days = 10
ignore_db_dirs=backup
innodb_buffer_pool_size = 256M
innodb_buffer_pool_size = ${MARIADB_INNODB_BUFFER_POOL_SIZE:-256M}
innodb_buffer_pool_instances = ${MARIADB_INNODB_BUFFER_POOL_INSTANCES:-1}
innodb_file_format = Barracuda
# If you want to have a single file, rather than 1 file per table, set this to
# be false. You can do this in an override file in `/etc/mysql/conf.d`
# @see https://mariadb.com/kb/en/library/xtradbinnodb-server-system-variables/#innodb_file_per_table
# innodb_file_per_table = false
innodb_large_prefix = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 100M
innodb_log_file_size = ${MARIADB_INNODB_LOG_FILE_SIZE:-64M}
join_buffer_size = 2M
key_buffer_size = 16M
max_allowed_packet = 64M
max_binlog_size = 100M
max_connections = 400
max_heap_table_size = 512M
myisam-recover-options = BACKUP
query_cache_limit = 1M
query_cache_size = 128M
query_cache_size = 0
query_cache_type = 0
skip-external-locking
skip_name_resolve = 1
table_open_cache = 200000
Expand All @@ -40,5 +37,7 @@ tmp_table_size = 512M
tmpdir = /tmp
transaction-isolation = READ-COMMITTED
skip-name-resolve
optimizer_search_depth = 0
innodb_flush_log_at_trx_commit = 0

!includedir /etc/mysql/conf.d
13 changes: 0 additions & 13 deletions images/mariadb/root/usr/include/bits/wordsize.h

This file was deleted.

Expand Up @@ -85,6 +85,8 @@ objects:
exec:
command:
- /usr/share/container-scripts/mysql/readiness-probe.sh
failureThreshold: 100
periodSeconds: 10
initialDelaySeconds: 15
timeoutSeconds: 5
volumeMounts:
Expand Down