Envoi des éléments docker des serveurs
This commit is contained in:
parent
8f0f825025
commit
fcd506177a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/.project
|
80
compose/dev/docker-compose.yml
Executable file
80
compose/dev/docker-compose.yml
Executable file
@ -0,0 +1,80 @@
|
|||||||
|
version: '2'
|
||||||
|
services:
|
||||||
|
gogs:
|
||||||
|
container_name: gogs
|
||||||
|
image: gogs/gogs:0.9.97
|
||||||
|
ports:
|
||||||
|
- "10022:22"
|
||||||
|
- "10080:3000"
|
||||||
|
volumes:
|
||||||
|
- /media/disk02/gogs/data:/data
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
||||||
|
bigdata:
|
||||||
|
container_name: bigdata
|
||||||
|
image: scores/mariadb101:201602
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
mem_limit: 16g
|
||||||
|
volumes:
|
||||||
|
- /media/bigdata-vol1:/var/lib/mysql
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
||||||
|
environment:
|
||||||
|
MARIADB_PASS: scores
|
||||||
|
sphinx:
|
||||||
|
container_name: sphinx
|
||||||
|
image: scores/sphinxsearch:20160302
|
||||||
|
ports:
|
||||||
|
- "9306:9306"
|
||||||
|
- "9312:9312"
|
||||||
|
mem_limit: 16g
|
||||||
|
volumes:
|
||||||
|
- /media/disk02/sphinxsearch/data:/var/lib/sphinxsearch
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
||||||
|
environment:
|
||||||
|
MYSQL_HOST: 192.168.78.249
|
||||||
|
MYSQL_USER: sphinx
|
||||||
|
MYSQL_PASS: indexer
|
||||||
|
SLAVE: 1
|
||||||
|
INDEX_ACT: 1
|
||||||
|
INDEX_CIBLAGE: 1
|
||||||
|
INDEX_DIR: 1
|
||||||
|
INDEX_ENT: 1
|
||||||
|
INDEX_DIR: 1
|
||||||
|
INDEX_HISTO: 1
|
||||||
|
app-db:
|
||||||
|
container_name: app-db
|
||||||
|
image: scores/mariadb101:201602
|
||||||
|
ports:
|
||||||
|
- "3307:3306"
|
||||||
|
mem_limit: 1g
|
||||||
|
volumes:
|
||||||
|
- /media/disk02/appsdb:/var/lib/mysql
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
||||||
|
environment:
|
||||||
|
MARIADB_PASS: scores
|
||||||
|
app-imapproxy:
|
||||||
|
container_name: app-imapproxy
|
||||||
|
image: scores/imapproxy:201601
|
||||||
|
ports:
|
||||||
|
- "1143:143"
|
||||||
|
environment:
|
||||||
|
SERVER_HOSTNAME: "imap.online.net"
|
||||||
|
ENABLE_SELECT_CACHE: "yes"
|
||||||
|
FORCE_TLS: "no"
|
||||||
|
|
12
compose/sd-25137/docker-compose.yml
Executable file
12
compose/sd-25137/docker-compose.yml
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
sphinx:
|
||||||
|
container_name: sphinx
|
||||||
|
image: scores/sphinxsearch
|
||||||
|
ports:
|
||||||
|
- "9306:9306"
|
||||||
|
- "9312:9312"
|
||||||
|
volumes:
|
||||||
|
- /media/disk02/sphinxsearch/data:/var/lib/sphinxsearch
|
||||||
|
log_driver: "json-file"
|
||||||
|
log_opt:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
12
compose/sd-48233/docker-compose.yml
Executable file
12
compose/sd-48233/docker-compose.yml
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
bigdata:
|
||||||
|
container_name: bigdata03
|
||||||
|
image: scores/mariadb55
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
mem_limit: 68719476736
|
||||||
|
volumes:
|
||||||
|
- /media/docker-data/bigdata-vol1:/var/lib/mysql
|
||||||
|
log_driver: "json-file"
|
||||||
|
log_opt:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
13
compose/vmmanager5/docker-compose.yml
Executable file
13
compose/vmmanager5/docker-compose.yml
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
bigdata:
|
||||||
|
container_name: bigdata
|
||||||
|
image: scores/mariadb55:v48
|
||||||
|
ports:
|
||||||
|
- "13306:3306"
|
||||||
|
- "3306:3306"
|
||||||
|
mem_limit: 68719476736
|
||||||
|
volumes:
|
||||||
|
- /mnt/part01/bigdata02:/var/lib/mysql
|
||||||
|
log_driver: "json-file"
|
||||||
|
log_opt:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
34
templates/mariadb/10.0/Dockerfile
Executable file
34
templates/mariadb/10.0/Dockerfile
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
ENV TERM xterm
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
RUN apt-get -y install software-properties-common && \
|
||||||
|
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db && \
|
||||||
|
add-apt-repository 'deb [arch=amd64,i386] http://mirror6.layerjet.com/mariadb/repo/10.0/ubuntu trusty main' && \
|
||||||
|
apt-get update && apt-get -y upgrade && apt-get install -y mariadb-server-10.0 pwgen && \
|
||||||
|
rm -rf /var/lib/mysql/* && \
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
sed -i -e 's/log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/#log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -e 's/log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/#log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -r 's/syslog/log_error=\/var\/log\/errorlog.err/' /etc/mysql/conf.d/mysqld_safe_syslog.cnf && \
|
||||||
|
ln -s /dev/stderr /var/log/errorlog.err && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
# Add MySQL configuration
|
||||||
|
ADD *.cnf /etc/mysql/conf.d/
|
||||||
|
RUN chmod 644 /etc/mysql/conf.d/*.cnf
|
||||||
|
|
||||||
|
# Add cli to run
|
||||||
|
ADD init_user.sh /home/init_user.sh
|
||||||
|
ADD run.sh /home/run.sh
|
||||||
|
RUN chmod 775 /home/*.sh
|
||||||
|
|
||||||
|
# Add VOLUMEs to allow backup of config and databases
|
||||||
|
VOLUME ["/etc/mysql", "/var/lib/mysql"]
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
CMD ["/home/run.sh"]
|
||||||
|
|
32
templates/mariadb/10.0/init_user.sh
Executable file
32
templates/mariadb/10.0/init_user.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
RET=1
|
||||||
|
while [[ RET -ne 0 ]]; do
|
||||||
|
echo "=> Waiting for confirmation of MariaDB service startup"
|
||||||
|
sleep 5
|
||||||
|
mysql -uroot -e "status" > /dev/null 2>&1
|
||||||
|
RET=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
PASS=${MARIADB_PASS:-$(pwgen -s 12 1)}
|
||||||
|
_word=$( [ ${MARIADB_PASS} ] && echo "preset" || echo "random" )
|
||||||
|
echo "=> Creating MariaDB admin user with ${_word} password"
|
||||||
|
|
||||||
|
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'"
|
||||||
|
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
|
||||||
|
|
||||||
|
echo "=> Done!"
|
||||||
|
|
||||||
|
echo "========================================================================"
|
||||||
|
echo "You can now connect to this MariaDB Server using:"
|
||||||
|
echo ""
|
||||||
|
echo " mysql -uadmin -p$PASS -h<host> -P<port>"
|
||||||
|
echo ""
|
||||||
|
echo "Please remember to change the above password as soon as possible!"
|
||||||
|
echo "MariaDB user 'root' has no password but only allows local connections"
|
||||||
|
echo "========================================================================"
|
||||||
|
|
||||||
|
mysqladmin -uroot shutdown
|
6
templates/mariadb/10.0/my.cnf
Executable file
6
templates/mariadb/10.0/my.cnf
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
[mysqld]
|
||||||
|
bind-address=0.0.0.0
|
||||||
|
skip_name_resolve
|
||||||
|
skip_external_locking
|
||||||
|
#server-id
|
||||||
|
#log-bin
|
17
templates/mariadb/10.0/run.sh
Executable file
17
templates/mariadb/10.0/run.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/mysql"
|
||||||
|
|
||||||
|
if [[ ! -d $VOLUME_HOME/mysql ]]; then
|
||||||
|
echo "=> An empty or uninitialized MariaDB volume is detected in $VOLUME_HOME"
|
||||||
|
echo "=> Installing MariaDB ..."
|
||||||
|
mysql_install_db > /dev/null 2>&1
|
||||||
|
echo "=> Done!"
|
||||||
|
/home/init_user.sh
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of MariaDB"
|
||||||
|
fi
|
||||||
|
|
||||||
|
/home/init_config.sh
|
||||||
|
|
||||||
|
exec mysqld_safe
|
32
templates/mariadb/10.1/Dockerfile
Executable file
32
templates/mariadb/10.1/Dockerfile
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
ENV TERM xterm
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
RUN apt-get update && apt-get -y install software-properties-common && \
|
||||||
|
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db && \
|
||||||
|
add-apt-repository 'deb [arch=amd64,i386] http://ftp.igh.cnrs.fr/pub/mariadb/repo/10.1/ubuntu trusty main' && \
|
||||||
|
apt-get update && apt-get -y upgrade && apt-get -y install mariadb-server-10.1 pwgen && \
|
||||||
|
rm -rf /var/lib/mysql/* && \
|
||||||
|
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
||||||
|
sed -i -e 's/log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/#log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -e 's/log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/#log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -r 's/syslog/log_error=\/var\/log\/errorlog.err/' /etc/mysql/conf.d/mysqld_safe_syslog.cnf && \
|
||||||
|
ln -s /dev/stderr /var/log/errorlog.err && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
# Add MySQL configuration
|
||||||
|
ADD *.cnf /etc/mysql/conf.d/
|
||||||
|
RUN chmod 644 /etc/mysql/conf.d/*.cnf
|
||||||
|
|
||||||
|
# Add cli to run
|
||||||
|
ADD init_user.sh /home/init_user.sh
|
||||||
|
ADD run.sh /home/run.sh
|
||||||
|
RUN chmod 775 /home/*.sh
|
||||||
|
|
||||||
|
# Add VOLUMEs to allow backup of config and databases
|
||||||
|
VOLUME ["/etc/mysql", "/var/lib/mysql"]
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
CMD ["/home/run.sh"]
|
32
templates/mariadb/10.1/init_user.sh
Executable file
32
templates/mariadb/10.1/init_user.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
RET=1
|
||||||
|
while [[ RET -ne 0 ]]; do
|
||||||
|
echo "=> Waiting for confirmation of MariaDB service startup"
|
||||||
|
sleep 5
|
||||||
|
mysql -uroot -e "status" > /dev/null 2>&1
|
||||||
|
RET=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
PASS=${MARIADB_PASS:-$(pwgen -s 12 1)}
|
||||||
|
_word=$( [ ${MARIADB_PASS} ] && echo "preset" || echo "random" )
|
||||||
|
echo "=> Creating MariaDB admin user with ${_word} password"
|
||||||
|
|
||||||
|
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'"
|
||||||
|
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
|
||||||
|
|
||||||
|
echo "=> Done!"
|
||||||
|
|
||||||
|
echo "========================================================================"
|
||||||
|
echo "You can now connect to this MariaDB Server using:"
|
||||||
|
echo ""
|
||||||
|
echo " mysql -uadmin -p$PASS -h<host> -P<port>"
|
||||||
|
echo ""
|
||||||
|
echo "Please remember to change the above password as soon as possible!"
|
||||||
|
echo "MariaDB user 'root' has no password but only allows local connections"
|
||||||
|
echo "========================================================================"
|
||||||
|
|
||||||
|
mysqladmin -uroot shutdown
|
6
templates/mariadb/10.1/my.cnf
Executable file
6
templates/mariadb/10.1/my.cnf
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
[mysqld]
|
||||||
|
bind-address=0.0.0.0
|
||||||
|
skip_name_resolve
|
||||||
|
skip_external_locking
|
||||||
|
#server-id
|
||||||
|
#log-bin
|
15
templates/mariadb/10.1/run.sh
Executable file
15
templates/mariadb/10.1/run.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/mysql"
|
||||||
|
|
||||||
|
if [[ ! -d $VOLUME_HOME/mysql ]]; then
|
||||||
|
echo "=> An empty or uninitialized MariaDB volume is detected in $VOLUME_HOME"
|
||||||
|
echo "=> Installing MariaDB ..."
|
||||||
|
mysql_install_db > /dev/null 2>&1
|
||||||
|
echo "=> Done!"
|
||||||
|
/home/init_user.sh
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of MariaDB"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec mysqld_safe
|
32
templates/mariadb/5.5/Dockerfile
Executable file
32
templates/mariadb/5.5/Dockerfile
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
ENV TERM xterm
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
RUN apt-get update && apt-get -y install software-properties-common && \
|
||||||
|
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db && \
|
||||||
|
add-apt-repository 'deb [arch=amd64,i386] http://ftp.igh.cnrs.fr/pub/mariadb/repo/5.5/ubuntu trusty main' && \
|
||||||
|
apt-get update && apt-get -y upgrade && apt-get -y install mariadb-server-5.5 pwgen && \
|
||||||
|
rm -rf /var/lib/mysql/* && \
|
||||||
|
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
||||||
|
sed -i -e 's/log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/#log_bin[ \t]*= \/var\/log\/mysql\/mariadb-bin/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -e 's/log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/#log_bin_index[ \t]*= \/var\/log\/mysql\/mariadb-bin.index/g' /etc/mysql/my.cnf && \
|
||||||
|
sed -i -r 's/syslog/log_error=\/var\/log\/errorlog.err/' /etc/mysql/conf.d/mysqld_safe_syslog.cnf && \
|
||||||
|
ln -s /dev/stderr /var/log/errorlog.err && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
# Add MySQL configuration
|
||||||
|
ADD *.cnf /etc/mysql/conf.d/
|
||||||
|
RUN chmod 644 /etc/mysql/conf.d/*.cnf
|
||||||
|
|
||||||
|
# Add cli to run
|
||||||
|
ADD init_user.sh /home/init_user.sh
|
||||||
|
ADD run.sh /home/run.sh
|
||||||
|
RUN chmod 775 /home/*.sh
|
||||||
|
|
||||||
|
# Add VOLUMEs to allow backup of config and databases
|
||||||
|
VOLUME ["/etc/mysql", "/var/lib/mysql"]
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
CMD ["/home/run.sh"]
|
32
templates/mariadb/5.5/init_user.sh
Executable file
32
templates/mariadb/5.5/init_user.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
RET=1
|
||||||
|
while [[ RET -ne 0 ]]; do
|
||||||
|
echo "=> Waiting for confirmation of MariaDB service startup"
|
||||||
|
sleep 5
|
||||||
|
mysql -uroot -e "status" > /dev/null 2>&1
|
||||||
|
RET=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
PASS=${MARIADB_PASS:-$(pwgen -s 12 1)}
|
||||||
|
_word=$( [ ${MARIADB_PASS} ] && echo "preset" || echo "random" )
|
||||||
|
echo "=> Creating MariaDB admin user with ${_word} password"
|
||||||
|
|
||||||
|
mysql -uroot -e "CREATE USER 'admin'@'%' IDENTIFIED BY '$PASS'"
|
||||||
|
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION"
|
||||||
|
|
||||||
|
echo "=> Done!"
|
||||||
|
|
||||||
|
echo "========================================================================"
|
||||||
|
echo "You can now connect to this MariaDB Server using:"
|
||||||
|
echo ""
|
||||||
|
echo " mysql -uadmin -p$PASS -h<host> -P<port>"
|
||||||
|
echo ""
|
||||||
|
echo "Please remember to change the above password as soon as possible!"
|
||||||
|
echo "MariaDB user 'root' has no password but only allows local connections"
|
||||||
|
echo "========================================================================"
|
||||||
|
|
||||||
|
mysqladmin -uroot shutdown
|
6
templates/mariadb/5.5/my.cnf
Executable file
6
templates/mariadb/5.5/my.cnf
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
[mysqld]
|
||||||
|
bind-address=0.0.0.0
|
||||||
|
skip-name-resolve
|
||||||
|
skip_external_locking
|
||||||
|
#server-id
|
||||||
|
#log-bin
|
15
templates/mariadb/5.5/run.sh
Executable file
15
templates/mariadb/5.5/run.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/mysql"
|
||||||
|
|
||||||
|
if [[ ! -d $VOLUME_HOME/mysql ]]; then
|
||||||
|
echo "=> An empty or uninitialized MariaDB volume is detected in $VOLUME_HOME"
|
||||||
|
echo "=> Installing MariaDB ..."
|
||||||
|
mysql_install_db > /dev/null 2>&1
|
||||||
|
echo "=> Done!"
|
||||||
|
/home/init_user.sh
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of MariaDB"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec mysqld_safe
|
67
templates/mariadb/README.md
Executable file
67
templates/mariadb/README.md
Executable file
@ -0,0 +1,67 @@
|
|||||||
|
docker-mariadb
|
||||||
|
====================
|
||||||
|
|
||||||
|
Base docker image to run a MariaDB database server
|
||||||
|
|
||||||
|
MariaDB version
|
||||||
|
---------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
To create the image `scores/mariadb`, execute the following command on the tutum-docker-mariadb folder:
|
||||||
|
|
||||||
|
docker build -t scores/mariadb .
|
||||||
|
|
||||||
|
To run the image and bind to port 3306:
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 scores/mariadb
|
||||||
|
|
||||||
|
The first time that you run your container, a new user `admin` with all privileges
|
||||||
|
will be created in MariaDB with a random password. To get the password, check the logs
|
||||||
|
of the container by running:
|
||||||
|
|
||||||
|
docker logs <CONTAINER_ID>
|
||||||
|
|
||||||
|
You will see an output like the following:
|
||||||
|
|
||||||
|
========================================================================
|
||||||
|
You can now connect to this MariaDB Server using:
|
||||||
|
|
||||||
|
mysql -uadmin -pxVN33tWOhM3u -h<host> -P<port>
|
||||||
|
|
||||||
|
Please remember to change the above password as soon as possible!
|
||||||
|
MariaDB user 'root' has no password but only allows local connections
|
||||||
|
========================================================================
|
||||||
|
|
||||||
|
|
||||||
|
In this case, `xVN33tWOhM3u` is the password assigned to the `admin` user.
|
||||||
|
|
||||||
|
Done!
|
||||||
|
|
||||||
|
|
||||||
|
Setting a specific password for the admin account
|
||||||
|
-------------------------------------------------
|
||||||
|
|
||||||
|
If you want to use a preset password instead of a random generated one, you can
|
||||||
|
set the environment variable `MARIADB_PASS` to your specific password when running the container:
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 -e MARIADB_PASS="mypass" scores/mariadb
|
||||||
|
|
||||||
|
|
||||||
|
Mounting the database file volume from other containers
|
||||||
|
------------------------------------------------------
|
||||||
|
|
||||||
|
One way to persist the database data is to store database files in another container.
|
||||||
|
To do so, first create a container that holds database files:
|
||||||
|
|
||||||
|
docker run -d -v /var/lib/mysql --name db_vol -p 22:22 tutum/ubuntu-trusty
|
||||||
|
|
||||||
|
This will create a new ssh-enabled container and use its folder `/var/lib/mysql` to store MariaDB database files.
|
||||||
|
You can specify any name of the container by using `--name` option, which will be used in next step.
|
||||||
|
|
||||||
|
After this you can start your MariaDB image using volumes in the container created above (put the name of container in `--volumes-from`)
|
||||||
|
|
||||||
|
docker run -d --volumes-from db_vol -p 3306:3306 scores/mariadb
|
62
templates/mariadb/config/default.my.cnf.txt
Executable file
62
templates/mariadb/config/default.my.cnf.txt
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
[mysqld]
|
||||||
|
#
|
||||||
|
# * Fine Tuning
|
||||||
|
#
|
||||||
|
max_connections = 100
|
||||||
|
connect_timeout = 5
|
||||||
|
wait_timeout = 7200
|
||||||
|
max_allowed_packet = 16M
|
||||||
|
thread_cache_size = 128
|
||||||
|
join_buffer_size = 64M
|
||||||
|
sort_buffer_size = 64M
|
||||||
|
bulk_insert_buffer_size = 256M
|
||||||
|
tmp_table_size = 16G
|
||||||
|
max_heap_table_size = 16G
|
||||||
|
|
||||||
|
#
|
||||||
|
# * MyISAM
|
||||||
|
#
|
||||||
|
myisam_recover = BACKUP
|
||||||
|
key_buffer_size = 4G
|
||||||
|
table_open_cache = 1000
|
||||||
|
table_definition_cache = 2000
|
||||||
|
concurrent_insert = 2
|
||||||
|
low_priority_updates = 1
|
||||||
|
read_buffer_size = 64M
|
||||||
|
read_rnd_buffer_size = 64M
|
||||||
|
myisam_sort_buffer_size = 512M
|
||||||
|
myisam_repair_threads = 4
|
||||||
|
|
||||||
|
#
|
||||||
|
# * Aria
|
||||||
|
#
|
||||||
|
aria_repair_threads = 4
|
||||||
|
|
||||||
|
#
|
||||||
|
# * Query Cache Configuration
|
||||||
|
#
|
||||||
|
query_cache_limit = 4M
|
||||||
|
query_cache_size = 64M
|
||||||
|
query_cache_min_res_unit = 4K
|
||||||
|
query_cache_type = 1
|
||||||
|
|
||||||
|
#
|
||||||
|
# * InnoDB
|
||||||
|
#
|
||||||
|
innodb_log_file_size = 48M
|
||||||
|
innodb_buffer_pool_size = 256M
|
||||||
|
innodb_log_buffer_size = 8M
|
||||||
|
innodb_file_per_table = 1
|
||||||
|
innodb_open_files = 400
|
||||||
|
innodb_io_capacity = 400
|
||||||
|
innodb_flush_method = O_DIRECT
|
||||||
|
|
||||||
|
#
|
||||||
|
# * Logging
|
||||||
|
#
|
||||||
|
#log-queries-not-using-indexes
|
||||||
|
#log-slow-admin-statements
|
||||||
|
slow_query_log = 0
|
||||||
|
slow_query_log_file = /var/lib/mysql/slow.log
|
||||||
|
long_query_time = 10
|
||||||
|
|
12
templates/mariadb/config/master.my.cnf.txt
Executable file
12
templates/mariadb/config/master.my.cnf.txt
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
[mysqld]
|
||||||
|
#
|
||||||
|
# * Replication
|
||||||
|
#
|
||||||
|
server-id = 11
|
||||||
|
binlog_format = MIXED
|
||||||
|
log_bin = /var/lib/mysql/log-bin
|
||||||
|
log_bin_index = /var/lib/mysql/log-bin.index
|
||||||
|
# not fab for performance, but safer
|
||||||
|
#sync_binlog = 1
|
||||||
|
expire_logs_days = 10
|
||||||
|
max_binlog_size = 1G
|
76
templates/mariadb/config/slave.my.cnf.txt
Executable file
76
templates/mariadb/config/slave.my.cnf.txt
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
[mysqld]
|
||||||
|
#
|
||||||
|
# * Replication
|
||||||
|
#
|
||||||
|
server-id = 112
|
||||||
|
binlog_format = MIXED
|
||||||
|
log_bin = /var/lib/mysql/log-bin
|
||||||
|
log_bin_index = /var/lib/mysql/log-bin.index
|
||||||
|
# not fab for performance, but safer
|
||||||
|
#sync_binlog = 1
|
||||||
|
expire_logs_days = 10
|
||||||
|
max_binlog_size = 1G
|
||||||
|
# slaves
|
||||||
|
relay_log = /var/lib/mysql/relay-bin
|
||||||
|
relay_log_index = /var/lib/mysql/relay-bin.index
|
||||||
|
relay_log_info_file = /var/lib/mysql/relay-bin.info
|
||||||
|
#log_slave_updates
|
||||||
|
#read_only
|
||||||
|
slave_compressed_protocol = 1
|
||||||
|
slave_exec_mode = IDEMPOTENT
|
||||||
|
slave-skip-errors = 1062
|
||||||
|
|
||||||
|
|
||||||
|
# Replication table
|
||||||
|
replicate-do-db=backoffice
|
||||||
|
replicate-wild-do-table=backoffice.%
|
||||||
|
replicate-do-db=boamp
|
||||||
|
replicate-wild-do-table=boamp.%
|
||||||
|
replicate-do-db=bopi
|
||||||
|
replicate-wild-do-table=bopi.%
|
||||||
|
replicate-do-db=bottin
|
||||||
|
replicate-wild-do-table=bottin.%
|
||||||
|
replicate-do-db=ciblage
|
||||||
|
replicate-wild-do-table=ciblage.%
|
||||||
|
replicate-do-db=execution
|
||||||
|
replicate-wild-do-table=execution.%
|
||||||
|
replicate-do-db=facturation
|
||||||
|
replicate-wild-do-table=facturation.%
|
||||||
|
replicate-do-db=histobodacc
|
||||||
|
replicate-wild-do-table=histobodacc.%
|
||||||
|
replicate-do-db=historiques
|
||||||
|
replicate-wild-do-table=historiques.%
|
||||||
|
replicate-do-db=insee
|
||||||
|
replicate-wild-do-table=insee.%
|
||||||
|
replicate-do-db=jo
|
||||||
|
replicate-wild-do-table=jo.%
|
||||||
|
replicate-do-db=modelisation
|
||||||
|
replicate-wild-do-table=modelisation.%
|
||||||
|
replicate-do-db=npaipp
|
||||||
|
replicate-wild-do-table=npaipp.%
|
||||||
|
replicate-do-db=octde
|
||||||
|
replicate-wild-do-table=octde.%
|
||||||
|
replicate-do-db=phpcrawl
|
||||||
|
replicate-wild-do-table=phpcrawl.%
|
||||||
|
replicate-do-db=phplist
|
||||||
|
replicate-wild-do-table=phplist.%
|
||||||
|
replicate-do-db=pollutions
|
||||||
|
replicate-wild-do-table=pollutions.%
|
||||||
|
replicate-do-db=presse
|
||||||
|
replicate-wild-do-table=presse.%
|
||||||
|
replicate-do-db=recuptables
|
||||||
|
replicate-wild-do-table=recuptables.%
|
||||||
|
replicate-do-db=sante
|
||||||
|
replicate-wild-do-table=sante.%
|
||||||
|
replicate-do-db=sdv1
|
||||||
|
replicate-wild-do-table=sdv1.%
|
||||||
|
replicate-do-db=sugarcrm
|
||||||
|
replicate-wild-do-table=sugarcrm.%
|
||||||
|
replicate-do-db=telephonie
|
||||||
|
replicate-wild-do-table=telephonie.%
|
||||||
|
replicate-do-db=tmp
|
||||||
|
replicate-wild-do-table=tmp.%
|
||||||
|
replicate-do-db=villes
|
||||||
|
replicate-wild-do-table=villes.%
|
||||||
|
replicate-do-db=webfiler
|
||||||
|
replicate-wild-do-table=webfiler.%
|
33
templates/mysql/5.5/Dockerfile
Executable file
33
templates/mysql/5.5/Dockerfile
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
# Add MySQL configuration
|
||||||
|
ADD my.cnf /etc/mysql/conf.d/my.cnf
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get -yq install mysql-server-5.5 pwgen && \
|
||||||
|
rm /etc/mysql/conf.d/mysqld_safe_syslog.cnf && \
|
||||||
|
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf; fi && \
|
||||||
|
mysql_install_db > /dev/null 2>&1 && \
|
||||||
|
touch /var/lib/mysql/.EMPTY_DB && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
# Add MySQL scripts
|
||||||
|
ADD sql_import.sh /sql_import.sh
|
||||||
|
ADD run.sh /run.sh
|
||||||
|
RUN chmod 775 /home/*.sh
|
||||||
|
|
||||||
|
ENV MYSQL_USER=admin \
|
||||||
|
MYSQL_PASS=**Random** \
|
||||||
|
REPLICATION_MASTER=**False** \
|
||||||
|
REPLICATION_SLAVE=**False** \
|
||||||
|
REPLICATION_USER=replica \
|
||||||
|
REPLICATION_PASS=replica \
|
||||||
|
ON_CREATE_DB=**False**
|
||||||
|
|
||||||
|
# Add VOLUMEs to allow backup of config and databases
|
||||||
|
VOLUME ["/etc/mysql", "/var/lib/mysql"]
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
CMD ["/run.sh"]
|
4
templates/mysql/5.5/docker-compose.yml
Executable file
4
templates/mysql/5.5/docker-compose.yml
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
bigdata:
|
||||||
|
image: scores/mysql:5.5
|
||||||
|
environment:
|
||||||
|
MYSQL_PASS: "**ChangeMe**"
|
6
templates/mysql/5.5/my.cnf
Executable file
6
templates/mysql/5.5/my.cnf
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
[mysqld]
|
||||||
|
bind-address=0.0.0.0
|
||||||
|
# http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/
|
||||||
|
skip_name_resolve
|
||||||
|
#server-id
|
||||||
|
#log-bin
|
186
templates/mysql/5.5/run.sh
Executable file
186
templates/mysql/5.5/run.sh
Executable file
@ -0,0 +1,186 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -m
|
||||||
|
set -e
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/mysql"
|
||||||
|
CONF_FILE="/etc/mysql/conf.d/my.cnf"
|
||||||
|
LOG="/var/log/mysql/error.log"
|
||||||
|
|
||||||
|
# Set permission of config file
|
||||||
|
chmod 644 ${CONF_FILE}
|
||||||
|
|
||||||
|
StartMySQL ()
|
||||||
|
{
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
# Time out in 1 minute
|
||||||
|
LOOP_LIMIT=60
|
||||||
|
for (( i=0 ; ; i++ )); do
|
||||||
|
if [ ${i} -eq ${LOOP_LIMIT} ]; then
|
||||||
|
echo "Time out. Error log is shown as below:"
|
||||||
|
tail -n 100 ${LOG}
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..."
|
||||||
|
sleep 1
|
||||||
|
mysql -uroot -e "status" > /dev/null 2>&1 && break
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateMySQLUser()
|
||||||
|
{
|
||||||
|
if [ "$MYSQL_PASS" = "**Random**" ]; then
|
||||||
|
unset MYSQL_PASS
|
||||||
|
fi
|
||||||
|
|
||||||
|
PASS=${MYSQL_PASS:-$(pwgen -s 12 1)}
|
||||||
|
_word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" )
|
||||||
|
echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password"
|
||||||
|
|
||||||
|
mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'"
|
||||||
|
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION"
|
||||||
|
echo "=> Done!"
|
||||||
|
echo "========================================================================"
|
||||||
|
echo "You can now connect to this MySQL Server using:"
|
||||||
|
echo ""
|
||||||
|
echo " mysql -u$MYSQL_USER -p$PASS -h<host> -P<port>"
|
||||||
|
echo ""
|
||||||
|
echo "Please remember to change the above password as soon as possible!"
|
||||||
|
echo "MySQL user 'root' has no password but only allows local connections"
|
||||||
|
echo "========================================================================"
|
||||||
|
}
|
||||||
|
|
||||||
|
OnCreateDB()
|
||||||
|
{
|
||||||
|
if [ "$ON_CREATE_DB" = "**False**" ]; then
|
||||||
|
unset ON_CREATE_DB
|
||||||
|
else
|
||||||
|
echo "Creating MySQL database ${ON_CREATE_DB}"
|
||||||
|
mysql -uroot -e "CREATE DATABASE IF NOT EXISTS ${ON_CREATE_DB};"
|
||||||
|
echo "Database created!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImportSql()
|
||||||
|
{
|
||||||
|
for FILE in ${STARTUP_SQL}; do
|
||||||
|
echo "=> Importing SQL file ${FILE}"
|
||||||
|
mysql -uroot < "${FILE}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
if [ ${REPLICATION_MASTER} == "**False**" ]; then
|
||||||
|
unset REPLICATION_MASTER
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${REPLICATION_SLAVE} == "**False**" ]; then
|
||||||
|
unset REPLICATION_SLAVE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize empty data volume and create MySQL user
|
||||||
|
if [[ ! -d $VOLUME_HOME/mysql ]]; then
|
||||||
|
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
|
||||||
|
echo "=> Installing MySQL ..."
|
||||||
|
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
|
||||||
|
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
|
||||||
|
fi
|
||||||
|
mysql_install_db || exit 1
|
||||||
|
touch /var/lib/mysql/.EMPTY_DB
|
||||||
|
echo "=> Done!"
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of MySQL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - MASTER
|
||||||
|
if [ -n "${REPLICATION_MASTER}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as master (1/2) ..."
|
||||||
|
if [ ! -f /replication_set.1 ]; then
|
||||||
|
RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})"
|
||||||
|
echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}"
|
||||||
|
sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE}
|
||||||
|
sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE}
|
||||||
|
touch /replication_set.1
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication master already configured, skip"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - SLAVE
|
||||||
|
if [ -n "${REPLICATION_SLAVE}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as slave (1/2) ..."
|
||||||
|
if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then
|
||||||
|
if [ ! -f /replication_set.1 ]; then
|
||||||
|
RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})"
|
||||||
|
echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}"
|
||||||
|
sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE}
|
||||||
|
sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE}
|
||||||
|
touch /replication_set.1
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication slave already configured, skip"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "=> Starting MySQL ..."
|
||||||
|
StartMySQL
|
||||||
|
tail -F $LOG &
|
||||||
|
|
||||||
|
# Create admin user and pre create database
|
||||||
|
if [ -f /var/lib/mysql/.EMPTY_DB ]; then
|
||||||
|
echo "=> Creating admin user ..."
|
||||||
|
CreateMySQLUser
|
||||||
|
OnCreateDB
|
||||||
|
rm /var/lib/mysql/.EMPTY_DB
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Import Startup SQL
|
||||||
|
if [ -n "${STARTUP_SQL}" ]; then
|
||||||
|
if [ ! -f /sql_imported ]; then
|
||||||
|
echo "=> Initializing DB with ${STARTUP_SQL}"
|
||||||
|
ImportSql
|
||||||
|
touch /sql_imported
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - MASTER
|
||||||
|
if [ -n "${REPLICATION_MASTER}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as master (2/2) ..."
|
||||||
|
if [ ! -f /replication_set.2 ]; then
|
||||||
|
echo "=> Creating a log user ${REPLICATION_USER}:${REPLICATION_PASS}"
|
||||||
|
mysql -uroot -e "CREATE USER '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASS}'"
|
||||||
|
mysql -uroot -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%'"
|
||||||
|
mysql -uroot -e "reset master"
|
||||||
|
echo "=> Done!"
|
||||||
|
touch /replication_set.2
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication master already configured, skip"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - SLAVE
|
||||||
|
if [ -n "${REPLICATION_SLAVE}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as slave (2/2) ..."
|
||||||
|
if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then
|
||||||
|
if [ ! -f /replication_set.2 ]; then
|
||||||
|
echo "=> Setting master connection info on slave"
|
||||||
|
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30"
|
||||||
|
mysql -uroot -e "start slave"
|
||||||
|
echo "=> Done!"
|
||||||
|
touch /replication_set.2
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication slave already configured, skip"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
fg
|
51
templates/mysql/5.5/sql-slaveusers.sql
Executable file
51
templates/mysql/5.5/sql-slaveusers.sql
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
/* Rambouillet*/
|
||||||
|
|
||||||
|
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
|
||||||
|
|
||||||
|
CREATE USER 'root'@'192.168.3.%' IDENTIFIED BY 'zsu1amtj';
|
||||||
|
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.3.%' WITH GRANT OPTION;
|
||||||
|
|
||||||
|
CREATE USER 'cacti'@'192.168.3.%' IDENTIFIED BY 'zsu1amtj';
|
||||||
|
GRANT PROCESS, SUPER ON *.* TO 'cacti'@'192.168.3.%';
|
||||||
|
|
||||||
|
CREATE USER 'repl'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
|
||||||
|
CREATE USER 'backoffice'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'backoffice'@'192.168.3.%';
|
||||||
|
CREATE USER 'batchuser'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'batchuser'@'192.168.3.%';
|
||||||
|
CREATE USER 'ciblage'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'ciblage'@'192.168.3.%';
|
||||||
|
CREATE USER 'sphinx'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'sphinx'@'192.168.3.%';
|
||||||
|
CREATE USER 'wsuser'@'192.168.3.%' IDENTIFIED BY 'wspass2012';
|
||||||
|
GRANT ALL ON *.* TO 'wsuser'@'192.168.3.%';
|
||||||
|
CREATE USER 'sugarcrm'@'192.168.3.%' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'sugarcrm'@'192.168.3.%';
|
||||||
|
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
|
||||||
|
/* sd-48233 195.154.170.169 */
|
||||||
|
|
||||||
|
CREATE USER 'root'@'78.31.45.206' IDENTIFIED BY 'zsu1amtj';
|
||||||
|
GRANT ALL PRIVILEGES ON *.* TO 'root'@'78.31.45.206' WITH GRANT OPTION;
|
||||||
|
|
||||||
|
CREATE USER 'wsuser'@'78.31.45.206' IDENTIFIED BY 'wspass2012';
|
||||||
|
GRANT SELECT ON *.* TO 'wsuser'@'78.31.45.206';
|
||||||
|
|
||||||
|
CREATE USER 'backoffice'@'195.154.251.56' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'backoffice'@'195.154.251.56';
|
||||||
|
CREATE USER 'batchuser'@'195.154.251.56' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'batchuser'@'195.154.251.56';
|
||||||
|
CREATE USER 'ciblage'@'195.154.251.56' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'ciblage'@'195.154.251.56';
|
||||||
|
CREATE USER 'sphinx'@'195.154.251.56' IDENTIFIED BY 'indexer';
|
||||||
|
GRANT ALL ON *.* TO 'sphinx'@'195.154.251.56';
|
||||||
|
CREATE USER 'wsuser'@'195.154.251.56' IDENTIFIED BY 'wspass2012';
|
||||||
|
GRANT ALL ON *.* TO 'wsuser'@'195.154.251.56';
|
||||||
|
CREATE USER 'sugarcrm'@'195.154.251.56' IDENTIFIED BY 'scores';
|
||||||
|
GRANT ALL ON *.* TO 'sugarcrm'@'195.154.251.56';
|
||||||
|
|
||||||
|
FLUSH PRIVILEGES;
|
28
templates/mysql/5.5/sql_import.sh
Executable file
28
templates/mysql/5.5/sql_import.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ $# -ne 3 ]]; then
|
||||||
|
echo "Usage: $0 <username> <password> </path/to/sql_file.sql>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=> Starting MySQL Server"
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
PID=$!
|
||||||
|
|
||||||
|
RET=1
|
||||||
|
while [[ RET -ne 0 ]]; do
|
||||||
|
echo "=> Waiting for confirmation of MySQL service startup"
|
||||||
|
sleep 5
|
||||||
|
mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1
|
||||||
|
RET=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " Started with PID ${PID}"
|
||||||
|
|
||||||
|
echo "=> Importing SQL file"
|
||||||
|
mysql -u"$1" -p"$2" < "$3"
|
||||||
|
|
||||||
|
echo "=> Stopping MySQL Server"
|
||||||
|
mysqladmin -u"$1" -p"$2" shutdown
|
||||||
|
|
||||||
|
echo "=> Done!"
|
32
templates/mysql/5.6/Dockerfile
Executable file
32
templates/mysql/5.6/Dockerfile
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
# Add MySQL configuration
|
||||||
|
ADD my.cnf /etc/mysql/conf.d/my.cnf
|
||||||
|
ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get -yq install mysql-server-5.6 pwgen && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
rm /etc/mysql/conf.d/mysqld_safe_syslog.cnf && \
|
||||||
|
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf; fi && \
|
||||||
|
mysql_install_db > /dev/null 2>&1 && \
|
||||||
|
touch /var/lib/mysql/.EMPTY_DB && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
# Add MySQL scripts
|
||||||
|
ADD import_sql.sh /import_sql.sh
|
||||||
|
ADD run.sh /run.sh
|
||||||
|
|
||||||
|
ENV MYSQL_USER=admin \
|
||||||
|
MYSQL_PASS=**Random** \
|
||||||
|
ON_CREATE_DB=**False** \
|
||||||
|
REPLICATION_MASTER=**False** \
|
||||||
|
REPLICATION_SLAVE=**False** \
|
||||||
|
REPLICATION_USER=replica \
|
||||||
|
REPLICATION_PASS=replica
|
||||||
|
|
||||||
|
# Add VOLUMEs to allow backup of config and databases
|
||||||
|
VOLUME ["/etc/mysql", "/var/lib/mysql"]
|
||||||
|
|
||||||
|
EXPOSE 3306
|
||||||
|
CMD ["/run.sh"]
|
4
templates/mysql/5.6/docker-compose.yml
Executable file
4
templates/mysql/5.6/docker-compose.yml
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
db:
|
||||||
|
image: tutum/mysql:5.6
|
||||||
|
environment:
|
||||||
|
MYSQL_PASS: "**ChangeMe**"
|
28
templates/mysql/5.6/import_sql.sh
Executable file
28
templates/mysql/5.6/import_sql.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ $# -ne 3 ]]; then
|
||||||
|
echo "Usage: $0 <username> <password> </path/to/sql_file.sql>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=> Starting MySQL Server"
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
PID=$!
|
||||||
|
|
||||||
|
RET=1
|
||||||
|
while [[ RET -ne 0 ]]; do
|
||||||
|
echo "=> Waiting for confirmation of MySQL service startup"
|
||||||
|
sleep 5
|
||||||
|
mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1
|
||||||
|
RET=$?
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " Started with PID ${PID}"
|
||||||
|
|
||||||
|
echo "=> Importing SQL file"
|
||||||
|
mysql -u"$1" -p"$2" < "$3"
|
||||||
|
|
||||||
|
echo "=> Stopping MySQL Server"
|
||||||
|
mysqladmin -u"$1" -p"$2" shutdown
|
||||||
|
|
||||||
|
echo "=> Done!"
|
6
templates/mysql/5.6/my.cnf
Executable file
6
templates/mysql/5.6/my.cnf
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
[mysqld]
|
||||||
|
bind-address=0.0.0.0
|
||||||
|
# http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/
|
||||||
|
skip_name_resolve
|
||||||
|
#server-id
|
||||||
|
#log-bin
|
7
templates/mysql/5.6/mysqld_charset.cnf
Executable file
7
templates/mysql/5.6/mysqld_charset.cnf
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
[mysqld]
|
||||||
|
character_set_server=utf8
|
||||||
|
character_set_filesystem=utf8
|
||||||
|
collation-server=utf8_general_ci
|
||||||
|
init-connect='SET NAMES utf8'
|
||||||
|
init_connect='SET collation_connection = utf8_general_ci'
|
||||||
|
skip-character-set-client-handshake
|
187
templates/mysql/5.6/run.sh
Executable file
187
templates/mysql/5.6/run.sh
Executable file
@ -0,0 +1,187 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -m
|
||||||
|
set -e
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/mysql"
|
||||||
|
CONF_FILE="/etc/mysql/conf.d/my.cnf"
|
||||||
|
LOG="/var/log/mysql/error.log"
|
||||||
|
|
||||||
|
# Set permission of config file
|
||||||
|
chmod 644 ${CONF_FILE}
|
||||||
|
chmod 644 /etc/mysql/conf.d/mysqld_charset.cnf
|
||||||
|
|
||||||
|
StartMySQL ()
|
||||||
|
{
|
||||||
|
/usr/bin/mysqld_safe > /dev/null 2>&1 &
|
||||||
|
# Time out in 1 minute
|
||||||
|
LOOP_LIMIT=60
|
||||||
|
for (( i=0 ; ; i++ )); do
|
||||||
|
if [ ${i} -eq ${LOOP_LIMIT} ]; then
|
||||||
|
echo "Time out. Error log is shown as below:"
|
||||||
|
tail -n 100 ${LOG}
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "=> Waiting for confirmation of MySQL service startup, trying ${i}/${LOOP_LIMIT} ..."
|
||||||
|
sleep 1
|
||||||
|
mysql -uroot -e "status" > /dev/null 2>&1 && break
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateMySQLUser()
|
||||||
|
{
|
||||||
|
if [ "$MYSQL_PASS" = "**Random**" ]; then
|
||||||
|
unset MYSQL_PASS
|
||||||
|
fi
|
||||||
|
|
||||||
|
PASS=${MYSQL_PASS:-$(pwgen -s 12 1)}
|
||||||
|
_word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" )
|
||||||
|
echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password"
|
||||||
|
|
||||||
|
mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'"
|
||||||
|
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION"
|
||||||
|
echo "=> Done!"
|
||||||
|
echo "========================================================================"
|
||||||
|
echo "You can now connect to this MySQL Server using:"
|
||||||
|
echo ""
|
||||||
|
echo " mysql -u$MYSQL_USER -p$PASS -h<host> -P<port>"
|
||||||
|
echo ""
|
||||||
|
echo "Please remember to change the above password as soon as possible!"
|
||||||
|
echo "MySQL user 'root' has no password but only allows local connections"
|
||||||
|
echo "========================================================================"
|
||||||
|
}
|
||||||
|
|
||||||
|
OnCreateDB()
|
||||||
|
{
|
||||||
|
if [ "$ON_CREATE_DB" = "**False**" ]; then
|
||||||
|
unset ON_CREATE_DB
|
||||||
|
else
|
||||||
|
echo "Creating MySQL database ${ON_CREATE_DB}"
|
||||||
|
mysql -uroot -e "CREATE DATABASE IF NOT EXISTS ${ON_CREATE_DB};"
|
||||||
|
echo "Database created!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImportSql()
|
||||||
|
{
|
||||||
|
for FILE in ${STARTUP_SQL}; do
|
||||||
|
echo "=> Importing SQL file ${FILE}"
|
||||||
|
mysql -uroot < "${FILE}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
if [ ${REPLICATION_MASTER} == "**False**" ]; then
|
||||||
|
unset REPLICATION_MASTER
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${REPLICATION_SLAVE} == "**False**" ]; then
|
||||||
|
unset REPLICATION_SLAVE
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize empty data volume and create MySQL user
|
||||||
|
if [[ ! -d $VOLUME_HOME/mysql ]]; then
|
||||||
|
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
|
||||||
|
echo "=> Installing MySQL ..."
|
||||||
|
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
|
||||||
|
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
|
||||||
|
fi
|
||||||
|
mysql_install_db || exit 1
|
||||||
|
touch /var/lib/mysql/.EMPTY_DB
|
||||||
|
echo "=> Done!"
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of MySQL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - MASTER
|
||||||
|
if [ -n "${REPLICATION_MASTER}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as master (1/2) ..."
|
||||||
|
if [ ! -f /replication_set.1 ]; then
|
||||||
|
RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})"
|
||||||
|
echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}"
|
||||||
|
sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE}
|
||||||
|
sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE}
|
||||||
|
touch /replication_set.1
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication master already configured, skip"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - SLAVE
|
||||||
|
if [ -n "${REPLICATION_SLAVE}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as slave (1/2) ..."
|
||||||
|
if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then
|
||||||
|
if [ ! -f /replication_set.1 ]; then
|
||||||
|
RAND="$(date +%s | rev | cut -c 1-2)$(echo ${RANDOM})"
|
||||||
|
echo "=> Writting configuration file '${CONF_FILE}' with server-id=${RAND}"
|
||||||
|
sed -i "s/^#server-id.*/server-id = ${RAND}/" ${CONF_FILE}
|
||||||
|
sed -i "s/^#log-bin.*/log-bin = mysql-bin/" ${CONF_FILE}
|
||||||
|
touch /replication_set.1
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication slave already configured, skip"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
echo "=> Starting MySQL ..."
|
||||||
|
StartMySQL
|
||||||
|
tail -F $LOG &
|
||||||
|
|
||||||
|
# Create admin user and pre create database
|
||||||
|
if [ -f /var/lib/mysql/.EMPTY_DB ]; then
|
||||||
|
echo "=> Creating admin user ..."
|
||||||
|
CreateMySQLUser
|
||||||
|
OnCreateDB
|
||||||
|
rm /var/lib/mysql/.EMPTY_DB
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Import Startup SQL
|
||||||
|
if [ -n "${STARTUP_SQL}" ]; then
|
||||||
|
if [ ! -f /sql_imported ]; then
|
||||||
|
echo "=> Initializing DB with ${STARTUP_SQL}"
|
||||||
|
ImportSql
|
||||||
|
touch /sql_imported
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - MASTER
|
||||||
|
if [ -n "${REPLICATION_MASTER}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as master (2/2) ..."
|
||||||
|
if [ ! -f /replication_set.2 ]; then
|
||||||
|
echo "=> Creating a log user ${REPLICATION_USER}:${REPLICATION_PASS}"
|
||||||
|
mysql -uroot -e "CREATE USER '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASS}'"
|
||||||
|
mysql -uroot -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%'"
|
||||||
|
mysql -uroot -e "reset master"
|
||||||
|
echo "=> Done!"
|
||||||
|
touch /replication_set.2
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication master already configured, skip"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set MySQL REPLICATION - SLAVE
|
||||||
|
if [ -n "${REPLICATION_SLAVE}" ]; then
|
||||||
|
echo "=> Configuring MySQL replication as slave (2/2) ..."
|
||||||
|
if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ] && [ -n "${MYSQL_PORT_3306_TCP_PORT}" ]; then
|
||||||
|
if [ ! -f /replication_set.2 ]; then
|
||||||
|
echo "=> Setting master connection info on slave"
|
||||||
|
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30"
|
||||||
|
mysql -uroot -e "start slave"
|
||||||
|
echo "=> Done!"
|
||||||
|
touch /replication_set.2
|
||||||
|
else
|
||||||
|
echo "=> MySQL replication slave already configured, skip"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "=> Cannot configure slave, please link it to another MySQL container with alias as 'mysql'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
fg
|
164
templates/mysql/README.md
Executable file
164
templates/mysql/README.md
Executable file
@ -0,0 +1,164 @@
|
|||||||
|
tutum-docker-mysql
|
||||||
|
==================
|
||||||
|
|
||||||
|
[![Deploy to Tutum](https://s.tutum.co/deploy-to-tutum.svg)](https://dashboard.tutum.co/stack/deploy/)
|
||||||
|
|
||||||
|
Base docker image to run a MySQL database server
|
||||||
|
|
||||||
|
|
||||||
|
MySQL version
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Different versions are built from different folders. If you want to use MariaDB, please check our `tutum/mariadb` image: https://github.com/tutumcloud/tutum-docker-mariadb
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
To create the image `tutum/mysql`, execute the following command on the tutum-mysql folder:
|
||||||
|
|
||||||
|
docker build -t tutum/mysql 5.5/
|
||||||
|
|
||||||
|
To run the image and bind to port 3306:
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 tutum/mysql
|
||||||
|
|
||||||
|
The first time that you run your container, a new user `admin` with all privileges
|
||||||
|
will be created in MySQL with a random password. To get the password, check the logs
|
||||||
|
of the container by running:
|
||||||
|
|
||||||
|
docker logs <CONTAINER_ID>
|
||||||
|
|
||||||
|
You will see an output like the following:
|
||||||
|
|
||||||
|
========================================================================
|
||||||
|
You can now connect to this MySQL Server using:
|
||||||
|
|
||||||
|
mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>
|
||||||
|
|
||||||
|
Please remember to change the above password as soon as possible!
|
||||||
|
MySQL user 'root' has no password but only allows local connections.
|
||||||
|
========================================================================
|
||||||
|
|
||||||
|
In this case, `47nnf4FweaKu` is the password allocated to the `admin` user.
|
||||||
|
|
||||||
|
Remember that the `root` user has no password, but it's only accessible from within the container.
|
||||||
|
|
||||||
|
You can now test your deployment:
|
||||||
|
|
||||||
|
mysql -uadmin -p
|
||||||
|
|
||||||
|
Done!
|
||||||
|
|
||||||
|
|
||||||
|
Setting a specific password for the admin account
|
||||||
|
-------------------------------------------------
|
||||||
|
|
||||||
|
If you want to use a preset password instead of a random generated one, you can
|
||||||
|
set the environment variable `MYSQL_PASS` to your specific password when running the container:
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql
|
||||||
|
|
||||||
|
You can now test your deployment:
|
||||||
|
|
||||||
|
mysql -uadmin -p"mypass"
|
||||||
|
|
||||||
|
The admin username can also be set via the `MYSQL_USER` environment variable.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Creating a database on container creation
|
||||||
|
-------------------------------------------------
|
||||||
|
|
||||||
|
If you want a database to be created inside the container when you start it up
|
||||||
|
for the first time you can set the environment variable `ON_CREATE_DB` to a string
|
||||||
|
that names the database.
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 -e ON_CREATE_DB="newdatabase" tutum/mysql
|
||||||
|
|
||||||
|
|
||||||
|
Mounting the database file volume
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
In order to persist the database data, you can mount a local folder from the host
|
||||||
|
on the container to store the database files. To do so:
|
||||||
|
|
||||||
|
docker run -d -v /path/in/host:/var/lib/mysql tutum/mysql /bin/bash -c "/usr/bin/mysql_install_db"
|
||||||
|
|
||||||
|
This will mount the local folder `/path/in/host` inside the docker in `/var/lib/mysql` (where MySQL will store the database files by default). `mysql_install_db` creates the initial database structure.
|
||||||
|
|
||||||
|
Remember that this will mean that your host must have `/path/in/host` available when you run your docker image!
|
||||||
|
|
||||||
|
After this you can start your MySQL image, but this time using `/path/in/host` as the database folder:
|
||||||
|
|
||||||
|
docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql tutum/mysql
|
||||||
|
|
||||||
|
|
||||||
|
Mounting the database file volume from other containers
|
||||||
|
------------------------------------------------------
|
||||||
|
|
||||||
|
Another way to persist the database data is to store database files in another container.
|
||||||
|
To do so, first create a container that holds database files:
|
||||||
|
|
||||||
|
docker run -d -v /var/lib/mysql --name db_vol -p 22:22 tutum/ubuntu-trusty
|
||||||
|
|
||||||
|
This will create a new ssh-enabled container and use its folder `/var/lib/mysql` to store MySQL database files.
|
||||||
|
You can specify any name of the container by using `--name` option, which will be used in next step.
|
||||||
|
|
||||||
|
After this you can start your MySQL image using volumes in the container created above (put the name of container in `--volumes-from`)
|
||||||
|
|
||||||
|
docker run -d --volumes-from db_vol -p 3306:3306 tutum/mysql
|
||||||
|
|
||||||
|
|
||||||
|
Migrating an existing MySQL Server
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
In order to migrate your current MySQL server, perform the following commands from your current server:
|
||||||
|
|
||||||
|
To dump your databases structure:
|
||||||
|
|
||||||
|
mysqldump -u<user> -p --opt -d -B <database name(s)> > /tmp/dbserver_schema.sql
|
||||||
|
|
||||||
|
To dump your database data:
|
||||||
|
|
||||||
|
mysqldump -u<user> -p --quick --single-transaction -t -n -B <database name(s)> > /tmp/dbserver_data.sql
|
||||||
|
|
||||||
|
To import a SQL backup which is stored for example in the folder `/tmp` in the host, run the following:
|
||||||
|
|
||||||
|
sudo docker run -d -v /tmp:/tmp tutum/mysql /bin/bash -c "/import_sql.sh <user> <pass> /tmp/<dump.sql>"
|
||||||
|
|
||||||
|
Also, you can start the new database initializing it with the SQL file:
|
||||||
|
|
||||||
|
sudo docker run -d -v /path/in/host:/var/lib/mysql -e STARTUP_SQL="/tmp/<dump.sql>" tutum/mysql
|
||||||
|
|
||||||
|
Where `<user>` and `<pass>` are the database username and password set earlier and `<dump.sql>` is the name of the SQL file to be imported.
|
||||||
|
|
||||||
|
|
||||||
|
Replication - Master/Slave
|
||||||
|
-------------------------
|
||||||
|
To use MySQL replication, please set environment variable `REPLICATION_MASTER`/`REPLICATION_SLAVE` to `true`. Also, on master side, you may want to specify `REPLICATION_USER` and `REPLICATION_PASS` for the account to perform replication, the default value is `replica:replica`
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
- Master MySQL
|
||||||
|
-
|
||||||
|
docker run -d -e REPLICATION_MASTER=true -e REPLICATION_PASS=mypass -p 3306:3306 --name mysql tutum/mysql
|
||||||
|
|
||||||
|
- Example on Slave MySQL:
|
||||||
|
-
|
||||||
|
docker run -d -e REPLICATION_SLAVE=true -p 3307:3306 --link mysql:mysql tutum/mysql
|
||||||
|
|
||||||
|
Now you can access port `3306` and `3307` for the master/slave MySQL.
|
||||||
|
|
||||||
|
Environment variables
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
`MYSQL_USER`: Set a specific username for the admin account (default 'admin').
|
||||||
|
|
||||||
|
`MYSQL_PASS`: Set a specific password for the admin account.
|
||||||
|
|
||||||
|
`STARTUP_SQL`: Defines one or more SQL scripts separated by spaces to initialize the database. Note that the scripts must be inside the container, so you may need to mount them.
|
||||||
|
|
||||||
|
Compatibility Issues
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
- Volume created by MySQL 5.6 cannot be used in MySQL 5.5 Images or MariaDB images.
|
51
templates/mysql/test.sh
Executable file
51
templates/mysql/test.sh
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "=> Building mysql 5.5 image"
|
||||||
|
docker build -t mysql-5.5 5.5/
|
||||||
|
|
||||||
|
echo "=> Testing if mysql is running on 5.5"
|
||||||
|
docker run -d -p 13306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.5; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P13306 ping | grep -c "mysqld is alive"
|
||||||
|
|
||||||
|
echo "=> Testing replication on mysql 5.5"
|
||||||
|
docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 13307:3306 --name mysql55master mysql-5.5; sleep 10
|
||||||
|
docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 13308:3306 --link mysql55master:mysql mysql-5.5; sleep 10
|
||||||
|
docker logs mysql55master | grep "repl:repl"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P13307 -e "show master status\G;" | grep "mysql-bin.*"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P13308 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P13308 -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes"
|
||||||
|
|
||||||
|
echo "=> Testing avolume on mysql 5.5"
|
||||||
|
mkdir vol55
|
||||||
|
docker run --name mysql55.1 -d -p 13309:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" -v $(pwd)/vol55:/var/lib/mysql mysql-5.5; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P13309 ping | grep -c "mysqld is alive"
|
||||||
|
docker stop mysql55.1
|
||||||
|
docker run -d -p 13310:3306 -v $(pwd)/vol55:/var/lib/mysql mysql-5.5; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P13310 ping | grep -c "mysqld is alive"
|
||||||
|
|
||||||
|
echo "=> Building mysql 5.6 image"
|
||||||
|
docker build -t mysql-5.6 5.6/
|
||||||
|
|
||||||
|
echo "=> Testing if mysql is running on 5.6"
|
||||||
|
docker run -d -p 23306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.6; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P13307 ping | grep -c "mysqld is alive"
|
||||||
|
|
||||||
|
echo "=> Testing replication on mysql 5.6"
|
||||||
|
docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_MASTER=true -e REPLICATION_USER=repl -e REPLICATION_PASS=repl -p 23307:3306 --name mysql56master mysql-5.6; sleep 10
|
||||||
|
docker run -d -e MYSQL_USER=user -e MYSQL_PASS=test -e REPLICATION_SLAVE=true -p 23308:3306 --link mysql56master:mysql mysql-5.6; sleep 10
|
||||||
|
docker logs mysql56master | grep "repl:repl"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P23307 -e "show master status\G;" | grep "mysql-bin.*"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P23308 -e "show slave status\G;" | grep "Slave_IO_Running.*Yes"
|
||||||
|
mysql -uuser -ptest -h127.0.0.1 -P23308 -e "show slave status\G;" | grep "Slave_SQL_Running.*Yes"
|
||||||
|
|
||||||
|
echo "=> Testing volume on mysql 5.6"
|
||||||
|
mkdir vol56
|
||||||
|
docker run --name mysql56.1 -d -p 23309:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" -v $(pwd)/vol56:/var/lib/mysql mysql-5.6; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P23309 ping | grep -c "mysqld is alive"
|
||||||
|
docker stop mysql56.1
|
||||||
|
docker run -d -p 23310:3306 -v $(pwd)/vol56:/var/lib/mysql mysql-5.6; sleep 10
|
||||||
|
mysqladmin -uuser -ptest -h127.0.0.1 -P23310 ping | grep -c "mysqld is alive"
|
||||||
|
|
||||||
|
echo "=>Done"
|
41
templates/sphinxsearch/Dockerfile
Executable file
41
templates/sphinxsearch/Dockerfile
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
|
||||||
|
ENV TERM xterm
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
RUN apt-get -y install software-properties-common && add-apt-repository ppa:builds/sphinxsearch-rel22 && \
|
||||||
|
apt-get update && apt-get -y upgrade && \
|
||||||
|
apt-get -y install nano supervisor mariadb-client libstemmer0d sphinxsearch logrotate && \
|
||||||
|
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
|
||||||
|
echo "Europe/Paris" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
|
||||||
|
|
||||||
|
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
ADD logrotate-sphinxsearch /etc/logrotate.d/sphinxsearch
|
||||||
|
ADD cron-sphinxsearch /etc/cron.d/sphinxsearch
|
||||||
|
|
||||||
|
# Add cli to run
|
||||||
|
ADD run.sh /home/run.sh
|
||||||
|
RUN chmod 775 /home/*.sh
|
||||||
|
|
||||||
|
ADD sdsphinx.tar.gz /home/
|
||||||
|
RUN cp /home/sdsphinx/config/sphinx.conf /etc/sphinxsearch/sphinx.conf && \
|
||||||
|
mkdir -p /var/lib/sphinxsearch/log && mkdir -p /var/lib/sphinxsearch/idx && \
|
||||||
|
chmod 775 /home/sdsphinx/indexer/*.sh
|
||||||
|
|
||||||
|
# Add VOLUMEs
|
||||||
|
VOLUME ["/etc/cron.d", "/etc/sphinxsearch", "/var/lib/sphinxsearch"]
|
||||||
|
|
||||||
|
# Environnement variables
|
||||||
|
ENV MYSQL_HOST=192.168.3.30 \
|
||||||
|
MYSQL_USER=sphinx \
|
||||||
|
MYSQL_PASS=indexer \
|
||||||
|
SLAVE=0 \
|
||||||
|
INDEX_ACT=0 \
|
||||||
|
INDEX_CIBLAGE=0 \
|
||||||
|
INDEX_DIR=0 \
|
||||||
|
INDEX_ENT=0 \
|
||||||
|
INDEX_DIR=0 \
|
||||||
|
INDEX_HISTO=0
|
||||||
|
|
||||||
|
EXPOSE 9306 9312
|
||||||
|
CMD ["/usr/bin/supervisord"]
|
50
templates/sphinxsearch/README
Executable file
50
templates/sphinxsearch/README
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
Sphinx Search Engine in Docker
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Build
|
||||||
|
-----
|
||||||
|
docker build -t scores/sphinxsearch:version .
|
||||||
|
|
||||||
|
|
||||||
|
Launch
|
||||||
|
------
|
||||||
|
|
||||||
|
Exemple d'un fichier docker-compose.yml
|
||||||
|
|
||||||
|
sphinx:
|
||||||
|
container_name: sphinx
|
||||||
|
image: scores/sphinxsearch
|
||||||
|
ports:
|
||||||
|
- "9306:9306"
|
||||||
|
- "9312:9312"
|
||||||
|
mem_limit: 17196646400
|
||||||
|
volumes:
|
||||||
|
- /media/disk02/sphinxsearch/data:/var/lib/sphinxsearch
|
||||||
|
log_driver: "json-file"
|
||||||
|
log_opt:
|
||||||
|
max-size: "500m"
|
||||||
|
max-file: "9"
|
||||||
|
environment:
|
||||||
|
MYSQL_HOST: 192.168.78.249
|
||||||
|
MYSQL_USER: sphinx
|
||||||
|
MYSQL_PASS: indexer
|
||||||
|
SLAVE: 1
|
||||||
|
INDEX_ACT: 1
|
||||||
|
INDEX_CIBLAGE: 1
|
||||||
|
INDEX_DIR: 1
|
||||||
|
INDEX_ENT: 1
|
||||||
|
INDEX_DIR: 1
|
||||||
|
INDEX_HISTO: 1
|
||||||
|
|
||||||
|
|
||||||
|
Configuration crontab
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
Find the volume where crontab is store <...>/cron.d/sphinxsearch
|
||||||
|
|
||||||
|
Uncomment the lines for which there must be an execution
|
||||||
|
|
||||||
|
docker-compose stop sphinx
|
||||||
|
docker-compose start sphinx
|
||||||
|
|
||||||
|
|
13
templates/sphinxsearch/cron-sphinxsearch
Executable file
13
templates/sphinxsearch/cron-sphinxsearch
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#
|
||||||
|
# --- Lancement de l'indexation sphinx
|
||||||
|
#
|
||||||
|
|
||||||
|
# --- Master Configuration
|
||||||
|
#01 12,18,23 * * * root /home/sdsphinx/indexer/indexer-act.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
||||||
|
#01 */1 * * * root /home/sdsphinx/indexer/indexer-dir.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
||||||
|
#01 */1 * * * root /home/sdsphinx/indexer/indexer-ent.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
||||||
|
|
||||||
|
# --- Slave Configuration
|
||||||
|
#01 12,18,23 * * * root /home/sdsphinx/indexer/indexer-act.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
||||||
|
#01 */1 * * * root /home/sdsphinx/indexer/slave-dir.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
||||||
|
#01 */1 * * * root /home/sdsphinx/indexer/slave-ent.sh >> /var/lib/sphinxsearch/log/cron.log 2>&1
|
10
templates/sphinxsearch/logrotate-sphinxsearch
Executable file
10
templates/sphinxsearch/logrotate-sphinxsearch
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
/var/lib/sphinxsearch/log/query.log
|
||||||
|
/var/lib/sphinxsearch/log/indexer.log
|
||||||
|
{
|
||||||
|
rotate 7
|
||||||
|
weekly
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
delaycompress
|
||||||
|
compress
|
||||||
|
}
|
69
templates/sphinxsearch/run.sh
Executable file
69
templates/sphinxsearch/run.sh
Executable file
@ -0,0 +1,69 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VOLUME_HOME="/var/lib/sphinxsearch"
|
||||||
|
|
||||||
|
# --- Configure
|
||||||
|
if [[ ! -f sphinx.conf ]]; then
|
||||||
|
touch sphinx.init.conf
|
||||||
|
touch sphinx.conf
|
||||||
|
|
||||||
|
if [ ${INDEX_ACT} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/act.conf >> sphinx.init.conf
|
||||||
|
cat /home/sdsphinx/config/act.conf >> sphinx.conf
|
||||||
|
fi
|
||||||
|
if [ ${INDEX_CIBLAGE} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/ciblage.conf >> sphinx.init.conf
|
||||||
|
if [ ${SLAVE} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/ciblage.conf >> sphinx.conf
|
||||||
|
else
|
||||||
|
cat /home/sdsphinx/config/ciblagetmp.conf >> sphinx.conf
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ ${INDEX_DIR} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/dir.conf >> sphinx.init.conf
|
||||||
|
if [ ${SLAVE} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/dir.conf >> sphinx.conf
|
||||||
|
else
|
||||||
|
cat /home/sdsphinx/config/dirtmp.conf >> sphinx.conf
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ ${INDEX_ENT} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/ent.conf >> sphinx.init.conf
|
||||||
|
if [ ${SLAVE} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/ent.conf >> sphinx.conf
|
||||||
|
else
|
||||||
|
cat /home/sdsphinx/config/enttmp.conf >> sphinx.conf
|
||||||
|
fi
|
||||||
|
cp -v /home/sdsphinx/config/stopwords-ent.txt /etc/sphinxsearch/
|
||||||
|
cp -v /home/sdsphinx/config/wordforms-ent.txt /etc/sphinxsearch/
|
||||||
|
fi
|
||||||
|
if [ ${INDEX_HISTO} -eq 1 ]; then
|
||||||
|
cat /home/sdsphinx/config/histo.conf >> sphinx.init.conf
|
||||||
|
cat /home/sdsphinx/config/histo.conf >> sphinx.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Assign vars
|
||||||
|
sed -i -e "s/sql_host = ENV_MYSQLHOST/sql_host = $MYSQL_HOST/" sphinx*.conf
|
||||||
|
sed -i -e "s/sql_user = ENV_MYSQLUSER/sql_user = $MYSQL_USER/" sphinx*.conf
|
||||||
|
sed -i -e "s/sql_pass = ENV_MYSQLPASS/sql_pass = $MYSQL_PASS/" sphinx*.conf
|
||||||
|
|
||||||
|
sed -i -e "s/MYSQL_HOST=ENV_MYSQLHOST/MYSQL_HOST=$MYSQL_HOST/" /home/sdsphinx/indexer/*.sh
|
||||||
|
sed -i -e "s/MYSQL_USER=ENV_MYSQLUSER/MYSQL_USER=$MYSQL_USER/" /home/sdsphinx/indexer/*.sh
|
||||||
|
sed -i -e "s/MYSQL_PASS=ENV_MYSQLPASS/MYSQL_PASS=$MYSQL_PASS/" /home/sdsphinx/indexer/*.sh
|
||||||
|
|
||||||
|
cat sphinx.init.conf /home/sdsphinx/config/sphinx.conf > /etc/sphinxsearch/sphinx.init.conf
|
||||||
|
cat sphinx.conf /home/sdsphinx/config/sphinx.conf > /etc/sphinxsearch/sphinx.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Init
|
||||||
|
if [[ ! -d $VOLUME_HOME/idx ]]; then
|
||||||
|
echo "=> An empty or uninitialized SPHINXSEARCH volume is detected in $VOLUME_HOME"
|
||||||
|
mkdir -p /var/lib/sphinxsearch/log && mkdir -p /var/lib/sphinxsearch/idx
|
||||||
|
echo "=> Creation index ..."
|
||||||
|
/usr/bin/indexer --config /etc/sphinxsearch/sphinx.init.conf --all
|
||||||
|
echo "=> Done!"
|
||||||
|
else
|
||||||
|
echo "=> Using an existing volume of SphinxSearch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec /usr/bin/searchd --nodetach
|
BIN
templates/sphinxsearch/sdsphinx.tar.gz
Executable file
BIN
templates/sphinxsearch/sdsphinx.tar.gz
Executable file
Binary file not shown.
14
templates/sphinxsearch/supervisord.conf
Executable file
14
templates/sphinxsearch/supervisord.conf
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
|
||||||
|
[program:crond]
|
||||||
|
command=cron -f
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
redirect_stderr=true
|
||||||
|
|
||||||
|
[program:sphinxsearch]
|
||||||
|
command=/home/run.sh
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
redirect_stderr=true
|
Loading…
Reference in New Issue
Block a user