diff --git a/compose/mariadb.yml b/compose/mariadb.yml new file mode 100644 index 0000000000..d93c7b26c5 --- /dev/null +++ b/compose/mariadb.yml @@ -0,0 +1,14 @@ +mariadbdata: + image: kollaglue/centos-rdo-mariadb-data + volumes: + - /var/lib/mysql:/var/lib/mysql + net: "host" + privileged: true +mariadbapp: + image: kollaglue/centos-rdo-mariadb-app + env_file: + - openstack.env + volumes_from: + - mariadbdata + net: "host" + privileged: true diff --git a/docker/mariadb-app/Dockerfile b/docker/mariadb-app/Dockerfile new file mode 100644 index 0000000000..692fd2bb05 --- /dev/null +++ b/docker/mariadb-app/Dockerfile @@ -0,0 +1,18 @@ +FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%base +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +# Install packages +# TODO check if hostname pkg is needed. +RUN yum -y install mariadb \ + mariadb-server \ + MySQL-python \ + hostname \ + && yum clean all + +# Add mysql configuration scripts +ADD config-mysql.sh /opt/kolla/config-mysql.sh +ADD mysql-entrypoint.sh /opt/kolla/mysql-entrypoint.sh + +# start mysql +ENTRYPOINT ["/opt/kolla/mysql-entrypoint.sh"] +CMD ["mysqld_safe"] diff --git a/docker/mariadb/build b/docker/mariadb-app/build similarity index 100% rename from docker/mariadb/build rename to docker/mariadb-app/build diff --git a/docker/mariadb-app/config-mysql.sh b/docker/mariadb-app/config-mysql.sh new file mode 100755 index 0000000000..5819000c5e --- /dev/null +++ b/docker/mariadb-app/config-mysql.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. /opt/kolla/kolla-common.sh + +: ${BIND_ADDRESS:=$PUBLIC_IP} +: ${DB_ROOT_PASSWORD:=$DB_ROOT_PASSWORD} +: ${DEFAULT_STORAGE_ENGINE:=innodb} +: ${COLLATION_SERVER:=utf8_general_ci} +: ${INIT_CONNECT:=SET NAMES utf8} +: ${CHAR_SET_SERVER:=utf8} +: ${INNODB_FILE_PER_TABLE:=true} +: ${DATADIR:=/var/lib/mysql} +: ${TEMP_FILE:='/tmp/mysql-first-time.sql'} + +server_cnf=/etc/my.cnf.d/server.cnf + +crudini --set $server_cnf mysqld bind-address $BIND_ADDRESS +crudini --set $server_cnf mysqld default-storage-engine $DEFAULT_STORAGE_ENGINE +crudini --set $server_cnf mysqld collation-server $COLLATION_SERVER +crudini --set $server_cnf mysqld init-connect "'${INIT_CONNECT}'" +crudini --set $server_cnf mysqld character-set-server $CHAR_SET_SERVER +if [ "${INNODB_FILE_PER_TABLE}" == "true" ] || ["${INNODB_FILE_PER_TABLE}" == "True" ] ; then + crudini --set $server_cnf mysqld innodb_file_per_table 1 +fi diff --git a/docker/mariadb-app/mysql-entrypoint.sh b/docker/mariadb-app/mysql-entrypoint.sh new file mode 100755 index 0000000000..1b4a559f1b --- /dev/null +++ b/docker/mariadb-app/mysql-entrypoint.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -e + +# Configure MySQL settings +. /opt/kolla/config-mysql.sh + +if [ -z "$(ls -A /var/lib/mysql)" -a "${1%_safe}" = 'mysqld' ]; then + PATH=/usr/libexec:$PATH + export PATH + + if [ -z "$MARIADB_ROOT_PASSWORD" ]; then + echo >&2 'error: database is uninitialized and MARIADB_ROOT_PASSWORD not set' + echo >&2 ' Did you forget to add -e MARIADB_ROOT_PASSWORD=... ?' + exit 1 + fi + + mysql_install_db --user=mysql --datadir="$DATADIR" + + # These statements _must_ be on individual lines, and _must_ end with + # semicolons (no line breaks or comments are permitted). + # TODO proper SQL escaping on ALL the things D: + TEMP_FILE='/tmp/mysql-first-time.sql' + cat > "$TEMP_FILE" <<-EOSQL + DELETE FROM mysql.user ; + CREATE USER 'root'@'%' IDENTIFIED BY '${MARIADB_ROOT_PASSWORD}' ; + GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; + DROP DATABASE IF EXISTS test ; + EOSQL + + if [ "$MARIADB_DATABASE" ]; then + echo "CREATE DATABASE IF NOT EXISTS $MARIADB_DATABASE ;" >> "$TEMP_FILE" + fi + + if [ "$MARIADB_USER" -a "$MARIADB_PASSWORD" ]; then + echo "CREATE USER '$MARIADB_USER'@'%' IDENTIFIED BY '$MARIADB_PASSWORD' ;" >> "$TEMP_FILE" + + if [ "$MARIADB_DATABASE" ]; then + echo "GRANT ALL ON $MARIADB_DATABASE.* TO '$MARIADB_USER'@'%' ;" >> "$TEMP_FILE" + fi + fi + + echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE" + + set -- "$@" --init-file="$TEMP_FILE" +fi + +chown -R mysql:mysql "$DATADIR" + +exec "$@" diff --git a/docker/mariadb-data/Dockerfile b/docker/mariadb-data/Dockerfile new file mode 100644 index 0000000000..4f1a9b455c --- /dev/null +++ b/docker/mariadb-data/Dockerfile @@ -0,0 +1,6 @@ +FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%base +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +# Command needed to start the data container. +# Note: data containers do not need to be persistent. +CMD ["/bin/sh"] diff --git a/docker/mariadb-data/build b/docker/mariadb-data/build new file mode 120000 index 0000000000..d2accf7d39 --- /dev/null +++ b/docker/mariadb-data/build @@ -0,0 +1 @@ +../../tools/build-docker-image \ No newline at end of file diff --git a/docker/mariadb/Dockerfile b/docker/mariadb/Dockerfile deleted file mode 100644 index b0aa27bbd4..0000000000 --- a/docker/mariadb/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM %%KOLLA_NAMESPACE%%/%%KOLLA_PREFIX%%base -MAINTAINER Kolla Project (https://launchpad.net/kolla) - -RUN yum -y install mariadb-galera-server hostname; yum clean all -ADD /entrypoint.sh /entrypoint.sh - -VOLUME /var/lib/mysql -VOLUME /var/log/mariadb - -EXPOSE 3306 - -ENTRYPOINT ["/entrypoint.sh"] -CMD ["mysqld_safe"] diff --git a/docker/mariadb/entrypoint.sh b/docker/mariadb/entrypoint.sh deleted file mode 100755 index 898823352d..0000000000 --- a/docker/mariadb/entrypoint.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -set -e - -: ${MYSQL_ROOT_PASSWORD:=$DB_ROOT_PASSWORD} - -if [ -z "$(ls -A /var/lib/mysql)" -a "${1%_safe}" = 'mysqld' ]; then - PATH=/usr/libexec:$PATH - export PATH - - if [ -z "$MYSQL_ROOT_PASSWORD" ]; then - echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set' - echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?' - exit 1 - fi - - mysql_install_db --user=mysql --datadir=/var/lib/mysql - - # These statements _must_ be on individual lines, and _must_ end with - # semicolons (no line breaks or comments are permitted). - # TODO proper SQL escaping on ALL the things D: - TEMP_FILE='/tmp/mysql-first-time.sql' - cat > "$TEMP_FILE" <<-EOSQL - DELETE FROM mysql.user ; - CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; - GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; - DROP DATABASE IF EXISTS test ; - EOSQL - - if [ "$MYSQL_DATABASE" ]; then - echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE ;" >> "$TEMP_FILE" - fi - - if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then - echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$TEMP_FILE" - - if [ "$MYSQL_DATABASE" ]; then - echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%' ;" >> "$TEMP_FILE" - fi - fi - - echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE" - - set -- "$@" --init-file="$TEMP_FILE" -fi - -chown -R mysql:mysql /var/lib/mysql -exec "$@" diff --git a/docs/database-container-set.md b/docs/database-container-set.md new file mode 100644 index 0000000000..b4a16388a5 --- /dev/null +++ b/docs/database-container-set.md @@ -0,0 +1,50 @@ +MariaDB Container Set +===================== + +The MariaDB database application has been organized into two containers, +known as a [container-set][] within the Kolla project. One container runs +the MariaDB application and the other stores the actual data. + +Operational efficiencies and service stability is provided by +separating the application from the stored data. For example, stored data +can be backed-up or restored without touching the MariaDB application +component. + +The containers work in a cooperative fashion by using [docker-compose][] +(aka Fig) to ensure the containers are co-located on the same host. +With docker-compose, you can manage the containers collectively +as a single unit. + +Here is a sample docker-compose yaml file for using both MariaDB containers: + +``` +mariadbdata: + image: kollaglue/centos-rdo-mariadb-data + volumes: + - /var/lib/mysql:/var/lib/mysql + - /var/log/mariadb:/var/log/mariadb + net: "host" + privileged: true +mariadbapp: + image: kollaglue/centos-rdo-mariadb-app + env_file: + - openstack.env + volumes_from: + - mariadbdata + net: "host" + ports: + - "3306:3306" + privileged: true +``` + +In addition to the MariaDB application being organized across two containers, the data +container follows the [data-only container][] design pattern. In this design pattern, +a dedicated container is used to perform a host mount and separate application +container(s) mount volumes from the data-only container instead of performing the host +mount directly. In the example above, the MariaDbApp container mounts the /var/lib/mysql +and /var/log/mariadb volumes through the MariaDbData container instead of mounting +these directly to the Docker host. + +[docker-compose]: http://www.fig.sh/ +[container-set]: https://review.openstack.org/#/c/153798/ +[data-only container]: http://www.tech-d.net/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/ diff --git a/docs/integration-guide.md b/docs/integration-guide.md index d1127896d4..19abe6f658 100644 --- a/docs/integration-guide.md +++ b/docs/integration-guide.md @@ -42,7 +42,6 @@ all containers. This allows a simple method of ensuring every type of node ### Environment Variable KEY/VALUE pairs ADMIN_TENANT_NAME= - tenant name - DB_ROOT_PASSWORD= - defines the MYSQL root password FLAT_INTERFACE= GLANCE_API_SERVICE_HOST= - address where glance API is running> GLANCE_DB_NAME= - DB name of glance service @@ -58,8 +57,8 @@ all containers. This allows a simple method of ensuring every type of node KEYSTONE_AUTH_PROTOCOL= - The keystone authentication protocol KEYSTONE_DB_PASSWORD= - The password used to access Keystone in the DB KEYSTONE_PUBLIC_SERVICE_HOST= - The IP address where Keystone is running - MARIADB_SERVICE_HOST= - The IP Address where mariadb is running - MYSQL_ROOT_PASSWORD= - The MYSQL password + MARIADB_ROOT_PASSWORD= - defines the MariaDB root password + MARIADB_SERVICE_HOST= - The IP Address where Mariadb is running NETWORK_MANAGER= - Use Nova or Neutron networking NOVA_API_SERVICE_HOST= - The IP Address where the Nova API Service is hosted NOVA_DB_NAME= - The name of the nova entry in the database diff --git a/tools/genenv b/tools/genenv index 91ac42cc43..c2e59e8209 100755 --- a/tools/genenv +++ b/tools/genenv @@ -21,7 +21,7 @@ echo MY_DEV=$MY_DEV # Database HOST_IP=$MY_IP -MYSQL_ROOT_PASSWORD=kolla +MARIADB_ROOT_PASSWORD=kolla PASSWORD=12345 # Host @@ -72,7 +72,7 @@ EOF cat > ./compose/openstack.env <