1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MaxscaleのDockerイメージをdocker-composeで起動時にログ出力を標準出力からファイル出力に変更

Last updated at Posted at 2019-08-27

MariaDB 10.4.8
Maxscale 2.4.2

git clone https://github.com/mariadb-corporation/maxscale-docker.git
cd maxscale-docker
cd maxscale

ログを標準出力からファイルに変更する場合

maxscale.cnfを追加

maxscale.cnf
[maxscale]
threads=auto
admin_host=0.0.0.0
logdir=/var/log/maxscale

[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

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=maxuser
password=maxpwd
auto_failover=true
auto_rejoin=true
enforce_read_only_slaves=1

[Read-Only-Service]
type=service
router=readconnroute
servers=server1,server2,server3
user=maxuser
password=maxpwd
router_options=slave

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxuser
password=maxpwd
master_failure_mode=fail_on_write

[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=mariadbclient
port=4008

[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=mariadbclient
port=4006

docker-compose.yml編集
・mariadb:10.3 → 10.4.8
・mariadb/maxscale:latest → maxscale:2.4.2
・maxscaleに「command: ["maxscale", "-d", "-U", "maxscale", "-l", "file"]」を追加

docker-compose.yml
version: '2'
services:
    master:
        image: mariadb:10.4.8
        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
        ports:
            - "4001:3306"

    slave1:
        image: mariadb:10.4.8
        depends_on:
            - master
        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 --log-slave-updates
        ports:
            - "4002:3306"

    slave2:
        image: mariadb:10.4.8
        depends_on:
            - master
        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 --log-slave-updates
        ports:
            - "4003:3306"

    maxscale:
        image: mariadb/maxscale:2.4.2-0
        depends_on:
            - master
            - slave1
            - slave2
        volumes:
            - ./maxscale.cnf:/etc/maxscale.cnf
        command: ["maxscale", "-d", "-U", "maxscale", "-l", "file"]
        ports:
            - "4006:4006"  # readwrite port
            - "4008:4008"  # readonly port
            - "8989:8989"  # REST API port
docker-compose up -d
docker-compose exec maxscale maxctrl list servers

┌─────────┬─────────┬──────┬─────────────┬─────────────────┬──────────┐
│ Server  │ Address │ Port │ Connections │ State           │ GTID     │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server1 │ master  │ 3306 │ 0           │ Master, Running │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server2 │ slave1  │ 3306 │ 0           │ Slave, Running  │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server3 │ slave2  │ 3306 │ 0           │ Slave, Running  │ 0-3000-5 │
└─────────┴─────────┴──────┴─────────────┴─────────────────┴──────────┘

docker stop maxscale_master_1
docker-compose exec maxscale maxctrl list servers

┌─────────┬─────────┬──────┬─────────────┬─────────────────┬──────────┐
│ Server  │ Address │ Port │ Connections │ State           │ GTID     │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server1 │ master  │ 3306 │ 0           │ Down            │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server2 │ slave1  │ 3306 │ 0           │ Master, Running │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server3 │ slave2  │ 3306 │ 0           │ Slave, Running  │ 0-3000-5 │
└─────────┴─────────┴──────┴─────────────┴─────────────────┴──────────┘

docker start maxscale_master_1
docker-compose exec maxscale maxctrl list servers

┌─────────┬─────────┬──────┬─────────────┬─────────────────┬──────────┐
│ Server  │ Address │ Port │ Connections │ State           │ GTID     │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server1 │ master  │ 3306 │ 0           │ Slave, Running  │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server2 │ slave1  │ 3306 │ 0           │ Master, Running │ 0-3000-5 │
├─────────┼─────────┼──────┼─────────────┼─────────────────┼──────────┤
│ server3 │ slave2  │ 3306 │ 0           │ Slave, Running  │ 0-3000-5 │
└─────────┴─────────┴──────┴─────────────┴─────────────────┴──────────┘

docker exec -t maxscale_maxscale_1 bash
ls /var/log/maxscale

maxscale.log

cat /var/log/maxscale/maxscale.log

# ログの出力例
2019-09-04 17:43:23   notice : Starting a total of 2 services...
2019-09-04 17:43:23   error  : [Read-Write-Service] Failed to connect to server 'server1' ([master]:3306) when checking authentication user credentials and permissions: 2002 Can't connect to MySQL server on 'master' (115)
2019-09-04 17:43:23   error  : [Read-Write-Service] Failed to connect to server 'server2' ([slave1]:3306) when checking authentication user credentials and permissions: 2002 Can't connect to MySQL server on 'slave1' (115)
2019-09-04 17:43:23   error  : Monitor was unable to connect to server server1[master:3306] : 'Can't connect to MySQL server on 'master' (115)'
2019-09-04 17:43:23   error  : [Read-Write-Service] Failed to connect to server 'server3' ([slave2]:3306) when checking authentication user credentials and permissions: 2002 Can't connect to MySQL server on 'slave2' (115)
2019-09-04 17:43:23   error  : Failure loading users data from backend [master:3306] for service [Read-Write-Service]. MySQL error 2002, Can't connect to MySQL server on 'master' (115)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?