Browse Source

add new mariadb 10.4

master
Markus Bergholz 1 year ago
parent
commit
dc3a21031d
3 changed files with 168 additions and 0 deletions
  1. +9
    -0
      docker/mariadb/10.4/Dockerfile
  2. +90
    -0
      docker/mariadb/10.4/README.md
  3. +69
    -0
      docker/mariadb/10.4/start.sh

+ 9
- 0
docker/mariadb/10.4/Dockerfile View File

@ -0,0 +1,9 @@
FROM alpine:3.11
RUN apk --update --no-cache add mariadb mariadb-client mariadb-server-utils
COPY start.sh /start.sh
EXPOSE 3306
CMD ./start.sh

+ 90
- 0
docker/mariadb/10.4/README.md View File

@ -0,0 +1,90 @@
Build with `docker build -t mariadb:alpine-10.4 .`
Start with `docker run -d -p 3306:3306 --name mariadb mariadb:alpine-10.4`
Or with persistence shared folder with host: `docker run -ti --name mariadb -v $(pwd)/test:/var/lib/mysql/ -p 3306:3306 mariadb:alpine-10.4`
Init with
```
docker exec -ti mariadb mysql -e "create user 'm'@'%' identified by 'nomysql1';"
docker exec -ti mariadb mysql -e "grant all privileges on *.* to 'm'@'%' with grant option;"
```
# option
to enable slow_query_log, use `-e SLOW_LOG=true`.
Log location is `/var/lib/mysql/slow_query.log`.
to set mariadb into read only mode, use `-e READ_ONLY="--read-only"`.
server id can be set with `-e SERVER_ID=10`.
Query Cache can be enabled with `-e QUERY_CACHE=ON`.
Max allow packets with `-e MAX_ALLOW_PACKET=64M`.
Max connections with `-e MAX_CONNECTIONS=500`
# create replica from writer node
#### 1. create replica user
```sql
CREATE USER 'repl'@'%' IDENTIFIED BY 'repl';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
```
#### 2. dump
```
docker exec -ti mariadb mysqldump --master-data=1 --single-transaction --flush-privileges --routines --triggers --all-databases > writer_dump.sql
```
and mv `writer_dump.sql` into volume/mount of read replica.
#### 3. create read replica
grep informations about bin log position
```
grep "CHANGE MASTER TO MASTER_LOG_FILE" data/writer_dump.sql |head -n 1
CHANGE MASTER TO MASTER_LOG_FILE='77abd7ecc317-bin.000001', MASTER_LOG_POS=39867;
```
start read replica
```
docker run -d --rm -v $(pwd)/data:/var/lib/mysql/ --name mariadb-ro -e READ_ONLY="--read-only" --network db -e SERVER_ID=10 -p 127.0.0.1:3310:3306 markuman/mariadb:alpine-10.4
```
jump into container and apply dump
```sql
mysql < writer_dump.sql
mysql
CHANGE MASTER TO
MASTER_HOST='mariadb',
MASTER_USER='repl',
MASTER_PASSWORD='repl',
MASTER_PORT=3306,
MASTER_LOG_FILE='77abd7ecc317-bin.000001',
MASTER_LOG_POS=39867,
MASTER_CONNECT_RETRY=10;
start slave;
```
and you're done.
check with `SHOW SLAVE STATUS \G`
# proxysql
create `monitor` user for proxysql
```sql
CREATE USER 'monitor'@'%' IDENTIFIED BY 'monitor';
GRANT SELECT on sys.* to 'monitor'@'%';
```

+ 69
- 0
docker/mariadb/10.4/start.sh View File

@ -0,0 +1,69 @@
#!/bin/sh
N=$(ls -l /var/lib/mysql|head -n 1|awk '{print $2}')
if [ $N -eq 0 ]
then
echo "init mariadb"
mysql_install_db --user=mysql --datadir=/var/lib/mysql
fi
sed -i 's,skip-networking,#skip-networking,' /etc/my.cnf.d/mariadb-server.cnf
sed -i 's,#bind-address,bind-address,' /etc/my.cnf.d/mariadb-server.cnf
if [ -z ${SERVER_ID+x} ]; then
SID=1
else
SID="$SERVER_ID"
fi
if [ -z ${QUERY_CACHE+x} ]; then
QCACHE=OFF
else
QCACHE="$QUERY_CACHE"
fi
if [ -z ${INNODB_BUFFER_POOL} ]; then
IBP=256M
else
IBP="$INNODB_BUFFER_POOL"
fi
if [ -z ${MAX_ALLOW_PACKET} ]; then
MAP=16M
else
MAP="$MAX_ALLOW_PACKET"
fi
if [ -z ${MAX_CONNECTIONS} ]; then
MC=100
else
MC="$MAX_CONNECTIONS"
fi
echo "given server id $SERVER_ID"
echo "using server id $SID"
echo "query cache is $QCACHE"
echo "start mariadb"
if [ -z ${SLOW_LOG+x} ]; then
mysqld_safe --gtid-domain-id "$SID" \
--server-id "$SID" \
--innodb-buffer-pool-size="$IBP" \
--log-bin \
--query_cache_size 10M \
--query_cache_type "$QCACHE" \
--max-allowed-packet="$MAP" \
--max-connections="$MC" ${READ_ONLY}
else
mysqld_safe --gtid-domain-id "$SID" \
--server-id "$SID" \
--log-bin \
--query_cache_size 10M \
--query_cache_type "$QCACHE" \
--max-allowed-packet="$MAP" \
--max-connections="$MC" \
--slow-query-log \
--slow-query-log-file=/var/lib/mysql/slow_query.log ${READ_ONLY}
fi

Loading…
Cancel
Save