mysql replication

This commit is contained in:
root
2020-08-06 21:40:57 +00:00
parent 619b851ce6
commit d598ee0f2f
4 changed files with 66 additions and 5 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ services:
dockerfile: Dockerfile
context: ireddocker/
image: ireddocker:0.4
container_name: iredmail-mail
container_name: iredmail
hostname: mail.recsds.spbsut.ru
env_file:
- ireddocker/iredmail-env.conf
+2 -3
View File
@@ -14,13 +14,12 @@ python-netifaces python-pycurl python-bcrypt python-dnspython python-webpy pytho
python-requests uwsgi uwsgi-plugin-python python-ldap python-mysqldb python-pymysql bzip2 acl patch cron \
tofrodos logwatch unzip bsdutils liblz4-tool distro-info-data iso-codes libapt-inst2.0 lsb-release powermgmt-base \
python-apt-common python3-apt python3-software-properties software-properties-common unattended-upgrades wget dialog libodbc1 slapd
ADD main.cvd /var/lib/clamav/main.cvd
RUN pip3 install web.py>=0.51 six>=1.15.0
ADD init-functions /lib/lsb/init-functions
ADD dockerinit.sh /dockerinit.sh
RUN ["mkdir", "/iredmail"]
RUN mkdir iredmail
ADD iredmail /iredmail
RUN ["chmod", "+x", "/dockerinit.sh"]
RUN chmod +x /dockerinit.sh
CMD ["/dockerinit.sh"]
EXPOSE 3306
+55 -1
View File
@@ -8,11 +8,16 @@ if [[ ! -f ".configured" ]]; then
set -x
: ${MYSQL_SERVER_ADDRESS:=127.0.0.1}
: ${MYSQL_MASTER_ADDRESS:=127.0.0.1}
: ${MYSQL_SLAVE_ADDRESS:=127.0.0.1}
: ${MYSQL_SERVER_ADDRESS:=$MYSQL_MASTER_ADDRESS}
: ${MYSQL_SERVER_PORT:=3306}
: ${MYSQL_ROOT_USER:=admin_iredmail}
: ${MYSQL_SLAVE_USER_PASSWD:=`eval </dev/urandom tr -dc A-Za-z0-9 | (head -c $1 &>/dev/null || head -c 20)`}
: ${MYSQL_ROOT_PASSWD:=admin_password}
: ${MYSQL_GRANT_HOST:=%}
: ${MYSQL_DATABASES:="amavis iredadmin iredapd roundcubemail"}
: ${MYSQL_USE_REPLICTION:=NO}
: ${MYSQLEXIST:=NO}
: ${CUSTOM_CERT_USE:=NO}
: ${CUSTOM_CERT_KEYFILE:=privkey.pem}
@@ -299,6 +304,51 @@ cat <<EOF >> /opt/www/roundcubemail/config/config.inc.php
// Directory setups
);
EOF
}
configure_mysql_replication() {
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS \
--execute="GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%'\
IDENTIFIED BY '$MYSQL_SLAVE_USER_PASSWD'; FLUSH PRIVILEGES;"
for i in $MYSQL_DATABASES; do
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS --execute="USE $i; FLUSH TABLES WITH READ LOCK;"
/usr/bin/mysqldump --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS $i > /tmp/$MYSQL_DATABASES.sql
mysql_bin_file=$(/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS --execute="SHOW MASTER STATUS;" | grep $i | awk '{print $2}')
mysql_position=$(/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS --execute="SHOW MASTER STATUS;" | grep $i | awk '{print $4}')
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_MASTER_ADDRESS --execute="UNLOCK TABLES;"
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_SLAVE_ADDRESS --execute="CREATE DATABASE $i;"
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_SLAVE_ADDRESS $i < /tmp/$i.sql
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_SLAVE_ADDRESS --execute="CHANGE MASTER TO MASTER_HOST='$MYSQL_MASTER_ADDRESS', \
MASTER_USER='slave_user', MASTER_PASSWORD='$MYSQL_SLAVE_USER_PASSWD', \
MASTER_LOG_FILE = '$mysql_bin_file', MASTER_LOG_POS = '$mysql_position';"
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_SLAVE_ADDRESS --execute="START SLAVE;"
done
/usr/bin/mysql --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWD \
--host=$MYSQL_SLAVE_ADDRESS --execute="START SLAVE;"
}
@@ -306,6 +356,10 @@ EOF
external_ldap_config
fi
if [[ X"${MYSQL_USE_REPLICATION}" == X'YES' || X"${MYSQL_USE_REPLICATION}" == X'yes' ]]; then
configure_mysql_replication
fi
touch /.configured
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
bases="amavis iredadmin iredapd roundcubemail"
for i in $bases; do
echo some users param with "very interesting string '$i' and other"
done