Dockerでsignal18/replication-managerを動かしてみる

AWS Workspaces
Amazon Linux2
Docker、docker-composeインストール済

signal18/replication-manager:2.1
MariaDB 10.4.10
Maxscale 2.2.5

# 準備
```
$ git clone https://github.com/aleks-v-k/mariadb-ha.git
```

# 変更するファイル

docker-compose.yml、maxscale.cnf、config.toml

```
/mariadb-ha-test
|--docker-compose.yml
|--maxscale
|  |--maxscale.cnf
|--replication-manager
|  |--config.toml
```

## ファイルの中身を以下の内容に変更

```docker-compose.yml
version: "2.4"

services:
  replicationmanager:
    image: signal18/replication-manager:2.1
    command: ["replication-manager", "monitor", "--config", "/etc/replication-manager/config/config.toml", "--verbose"]
    volumes:
      - ./replication-manager:/etc/replication-manager/config
    ports:
      - "10001:10001"
      - "10005:10005"
    depends_on:
      - setup_a

  maxscale:
    image: asosso/maxscale:2.2.5
    volumes:
      - ./maxscale:/etc/maxscale.d
    ports:
      - "4006:4006"
      - "6603:6603"
    depends_on:
      - replicationmanager

  setup_a:
    image: mariadb:10.4.10
    restart: "no"
    entrypoint: ""
    command: "/setup/setup.sh cluster_a foo.bar mariadb_a1 mariadb_a2 mariadb_a3"
    volumes:
      - ./setup:/setup
    depends_on:
      # Docker stack deploy healthcheck in V3 docker-compose.yml not working in CoreOS Alpha 1339.0.0 #1848
      # https://github.com/coreos/bugs/issues/1848
      # Can this work with v3 of docker compose? #3
      # https://github.com/peter-evans/docker-compose-healthcheck/issues/3
      mariadb_a1: { condition: service_healthy }
      mariadb_a2: { condition: service_healthy }
      mariadb_a3: { condition: service_healthy }

  mariadb_a1:
    image: mariadb:10.4.10
    command: ["mysqld", "--server-id=11", "--gtid-domain-id=10"]
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    volumes:
      - ./mariadb:/etc/mysql/conf.d
    healthcheck:
      test: "mysqladmin -h 127.0.0.1 status || exit 1"
      interval: "5s"
      timeout: "1s"
      retries: 10

  mariadb_a2:
    image: mariadb:10.4.10
    command: ["mysqld", "--server-id=12", "--gtid-domain-id=10"]
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    volumes:
      - ./mariadb:/etc/mysql/conf.d
    healthcheck:
      test: "mysqladmin -h 127.0.0.1 status || exit 1"
      interval: "5s"
      timeout: "1s"
      retries: 10

  mariadb_a3:
    image: mariadb:10.4.10
    command: ["mysqld", "--server-id=13", "--gtid-domain-id=10"]
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    volumes:
      - ./mariadb:/etc/mysql/conf.d
    healthcheck:
      test: "mysqladmin -h 127.0.0.1 status || exit 1"
      interval: "5s"
      timeout: "1s"
      retries: 10
```

```maxscale/maxscale.cnf 
[MaxScale]
log_warning = 1
log_info = 1
log_notice = 1
log_debug = 1
admin_host=0.0.0.0

[MaxAdmin]
type=service
router=cli

[MaxAdmin-Unix-Listener]
type=listener
service=MaxAdmin
protocol=maxscaled
socket=default

[MaxAdmin-Inet-Listener]
type=listener
service=MaxAdmin
protocol=maxscaled
address=0.0.0.0
port=6603

[Cluster-A-Router]
type=service
router=readwritesplit
servers=mariadb_a1,mariadb_a2,mariadb_a3
weightby=serv_weight
master_failure_mode=fail_on_write
max_slave_replication_lag=2
user=maxscale
password=maxscale
enable_root_user=true

[Cluster-A-Listener]
type=listener
service=Cluster-A-Router
protocol=mariadbclient
address=0.0.0.0
port=4006

[Cluster-A-Monitor]
type=monitor
module=mariadbmon
servers=mariadb_a1,mariadb_a2,mariadb_a3
user=replmon
passwd=replmon
monitor_interval=500
backend_write_timeout=1
detect_stale_master=true

[mariadb_a1]
type=server
protocol=mariadbbackend
address=mariadb_a1
port=3306
serv_weight=1

[mariadb_a2]
type=server
protocol=mariadbbackend
address=mariadb_a2
port=3306
serv_weight=1

[mariadb_a3]
type=server
protocol=mariadbbackend
address=mariadb_a3
port=3306
serv_weight=1
```

```replication-manager/config.toml 
[Default]
http-server = true
http-bind-address = "0.0.0.0"
http-auth = false
api-credential = "admin:admin"

log-level = 2
verbose = 1

[cluster_a]
title = "Cluster-A"

db-servers-hosts = "mariadb_a1,mariadb_a2,mariadb_a3"
db-servers-credential = "replmon:replmon"

replication-credential = "replicator:replicator"
replication-source-name = "cluster_a"

failover-mode = "automatic"
failover-limit = 3
failover-time-limit = 10
failover-at-sync = false
failover-max-slave-delay = 1
failover-falsepositive-heartbeat = false
failover-falsepositive-heartbeat-timeout = 1
failover-falsepositive-ping-counter = 1
failover-falsepositive-maxscale = true
failover-falsepositive-maxscale-timeout = 2

maxscale = true
maxscale-servers = "maxscale"
maxscale-port = "6603"
maxscale-user = "admin"
maxscale-pass = "mariadb"
maxscale-read-port = "4006"
maxscale-write-port = "4006"
maxscale-read-write-port = "4006"
```

## 起動

```
$ docker-compose up -d
```

## 動作確認

ブラウザ起動
http://localhost:10001 にアクセス
admin/adminでログイン
![login.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/2a2e8f79-12ba-74a0-88fc-9c6f1b46b1b3.png)

**DASHBOARD**
![dashboard1.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/01082741-7950-c0c4-0fed-a2c23c764757.png)
![dashboard2.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/9bc256d9-398b-f0a5-ef20-f04eb0b04df1.png)
**ALERTS**
![alert.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/678eda48-d5bb-31b2-6eb0-f2e5d861e122.png)
**PROXIES**
![proxies1.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/f506863b-0063-f5bf-8fb3-038d3539e216.png)
![proxies2.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/b6179c60-3e44-d99a-ac2c-9137a80843d9.png)
**SETTINGS**
![settings.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/e1874ee7-86b5-9367-86fa-9a5a212db409.png)
**SHARDS**
![shards.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/62c5d651-e618-0a4b-0174-94c6739389fb.png)

## 課題

Maxscale 2.3.xおよび2.4.xの場合は以下の画面の表示が以下のようになる。
まだ対応していない可能性あり

**ALERTS**
![error1.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/de42837f-cf92-c9a4-a729-5cb3f489b101.png)
**PROXIES**
![error2.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/208807/2a6e975f-df5e-f834-ddd7-4e5e6686d4b2.png)


## 参考URL

[signal18/replication-manager](https://github.com/signal18/replication-manager)
[DockerHubの公開されているイメージ](https://hub.docker.com/r/signal18/replication-manager/)
[MariaDB HA Test](https://github.com/erasys/mariadb-ha-test)