Add basic docker-compose setup

The setup contains a three node master-slave cluster with both
readwritesplit and readconnroute.

Removed the duplication of the configuration files in the README and
provided links instead.
This commit is contained in:
Markus Mäkelä
2018-04-16 14:58:22 +03:00
parent ff7f06cd66
commit 0adb4b6ffa
6 changed files with 103 additions and 90 deletions

View File

@ -4,10 +4,10 @@ This Docker image runs the latest GA version of MariaDB MaxScale.
## Building
Run the following command to build the image.
Run the following command in this directory to build the image.
```
sudo docker build -t maxscale .
docker build -t maxscale .
```
## Usage
@ -29,92 +29,30 @@ docker run --network host --rm -v /my_dir:/container_dir maxscale -f /path/to/ma
## Default configuration
```
# MaxScale documentation on GitHub:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Documentation-Contents.md
The default configuration for the MaxScale docker image can be found in
[this configuration file](./maxscale.cnf).
# Complete list of configuration options:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Getting-Started/Configuration-Guide.md
## MaxScale docker-compose setup
# Global parameters
[maxscale]
threads=auto
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Reference/MaxAdmin.md
[MaxAdmin-Service]
type=service
router=cli
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default
```
## Example base configuration
[The MaxScale docker-compose setup](./docker-compose.yml) contains MaxScale
configured with a three node master-slave cluster. To start it, run the
following commands in this directory.
```
# Global parameters
[maxscale]
threads=auto
# Monitor for the servers
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Monitors/MariaDB-Monitor.md
[MariaDB-Monitor]
type=monitor
module=mariadbmon
user=myuser
passwd=mypwd
monitor_interval=1000
# Service definitions
# Service Definition for a read-only service and a read/write splitting service.
# ReadConnRoute documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Routers/ReadConnRoute.md
[Read-Only-Service]
type=service
router=readconnroute
user=myuser
passwd=mypwd
router_options=slave
# ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.2/Documentation/Routers/ReadWriteSplit.md
[Read-Write-Service]
type=service
router=readwritesplit
user=myuser
passwd=mypwd
max_slave_connections=100%
# Listener definitions for the services
# Listeners represent the ports the services will listen on.
[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=MySQLClient
port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MySQLClient
port=4006
docker-compose build
docker-compose up -d
```
For base configurations, servers are defined at runtime. Run the following
command to create a server and link it into all services and monitors.
After MaxScale and the servers have started (takes a few minutes), you can find
the readwritesplit router on port 4006 and the readconnroute on port 4008. The
user `maxuser` with the password `maxpwd` can be used to test the cluster.
You can edit the [`maxscale.cnf.d/example.cnf`](./maxscale.cnf.d/example.cnf)
file and recreate the MaxScale container to change the configuration.
To stop the containers, execute the following command. Optionally, use the -v
flag to also remove the volumes.
```
maxctrl create server <name> <host> <port> --monitors MariaDB-Monitor --services Read-Only-Service Read-Write-Service
docker-compose down
```

34
docker/docker-compose.yml Normal file
View File

@ -0,0 +1,34 @@
version: '2'
services:
master:
image: mariadb:10.2
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/master:/docker-entrypoint-initdb.d
command: mysqld --log-bin=mariadb-bin --binlog-format=ROW --server-id=3000
slave1:
image: mariadb:10.2
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/slave:/docker-entrypoint-initdb.d
command: mysqld --log-bin=mariadb-bin --binlog-format=ROW --server-id=3001
slave2:
image: mariadb:10.2
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: Y
volumes:
- ./sql/slave:/docker-entrypoint-initdb.d
command: mysqld --log-bin=mariadb-bin --binlog-format=ROW --server-id=3002
maxscale:
build: .
container_name: maxscale
volumes:
- ./maxscale.cnf.d:/etc/maxscale.cnf.d
ports:
- "4006:4006"
- "4008:4008"

View File

@ -2,6 +2,24 @@
[maxscale]
threads=auto
[server1]
type=server
address=master
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=slave1
port=3306
protocol=MariaDBBackend
[server3]
type=server
address=slave2
port=3306
protocol=MariaDBBackend
# Monitor for the servers
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
@ -10,9 +28,10 @@ threads=auto
[MariaDB-Monitor]
type=monitor
module=mariadbmon
user=myuser
passwd=mypwd
monitor_interval=1000
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
monitor_interval=2000
# Service definitions
# Service Definition for a read-only service and a read/write splitting service.
@ -23,8 +42,9 @@ monitor_interval=1000
[Read-Only-Service]
type=service
router=readconnroute
user=myuser
passwd=mypwd
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
router_options=slave
# ReadWriteSplit documentation:
@ -33,9 +53,9 @@ router_options=slave
[Read-Write-Service]
type=service
router=readwritesplit
user=myuser
passwd=mypwd
max_slave_connections=100%
servers=server1,server2,server3
user=maxuser
passwd=maxpwd
# Listener definitions for the services
# Listeners represent the ports the services will listen on.

View File

@ -0,0 +1,10 @@
RESET MASTER;
CREATE DATABASE test;
CREATE USER 'maxuser'@'127.0.0.1' IDENTIFIED BY 'maxpwd';
CREATE USER 'maxuser'@'%' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'127.0.0.1' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'maxuser'@'%' WITH GRANT OPTION;
SET GLOBAL max_connections=10000;
SET GLOBAL gtid_strict_mode=ON;

View File

@ -0,0 +1,4 @@
CHANGE MASTER TO MASTER_HOST='master', MASTER_PORT=3306, MASTER_USER='maxuser', MASTER_PASSWORD='maxpwd', MASTER_LOG_POS=4, MASTER_LOG_FILE='mariadb-bin.000001', MASTER_CONNECT_RETRY=1;
START SLAVE;
SET GLOBAL max_connections=10000;
SET GLOBAL gtid_strict_mode=ON;

7
docker/sql/users.sql Normal file
View File

@ -0,0 +1,7 @@
RESET MASTER;
CREATE USER 'maxuser'@'127.0.0.1' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'127.0.0.1' WITH GRANT OPTION;
CREATE USER 'maxuser'@'%' IDENTIFIED BY 'maxpwd';
GRANT ALL ON *.* TO 'maxuser'@'%' WITH GRANT OPTION;