2
3

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.

CoreOS/Docker で MariaDB Galera Cluster + MaxScale を動かす

Last updated at Posted at 2018-02-15

MariaDB Galera Cluster を稼働させる Dockerイメージ 等を GitHub で発見したので手元の環境で試してみました。
なお、2018-07-29現在 MaraiDB Server は 10.3.6 RC を実行できますが、MaxScale は 2.1.9 となっています。

https://github.com/toughIQ/docker-mariadb-cluster
https://hub.docker.com/r/toughiq/mariadb-cluster/
https://hub.docker.com/r/toughiq/maxscale/

Vagrant で CoreOS を起動

Vagrant を用いて VMware Workstation 12 Pro 上で CoreOS を立ち上げ、SSH で CoreOS VM に接続します。

git clone https://github.com/coreos/coreos-vagrant.git
cd coreos-vagrant
vagrant up
vagrant ssh

Swarm Node 初期化

docker swarm init --advertise-addr=192.168.8.101

NIC が複数ある場合は --advertise-addr オプションで IP アドレスを指定します。今回は1ノードで実行します。

ネットワークの作成

docker network create -d overlay mynet

Galera サービスの作成

--network オプションでさきほど作成したネットワーク名(mynet)を指定します。

docker service create --name galera \
  --network mynet \
  --replicas=1 \
  --env DB_SERVICE_NAME=galera \
  --env MYSQL_ROOT_PASSWORD=rootpass \
  --env MYSQL_DATABASE=test \
  --env MYSQL_USER=dbuser \
  --env MYSQL_PASSWORD=dbpwd \
  toughiq/mariadb-cluster:10.3

74i5ld9k69xczfyu3ut9av1jp
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

--name オプションで指定するサービス名(galera)と 環境変数 DB_SERVICE_NAME で指定する名前は一致させる必要があります。docker service ps でステータスが確認できます。

core@core-01 $ docker service ps galera
ID                  NAME                IMAGE                          NODE                DESIRED STATE       CURRENT STATE                ERROR
   PORTS
24uuqhm7p0ik        galera.1            toughiq/mariadb-cluster:10.3   core-01             Running             Running about a minute ago

クラスタをスケールさせる

Galeraノード数を3に変更します。

core@core-01 ~ $ docker service scale galera=3

galera scaled to 3
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service converged

再び docker service ps galera を実行してみます。

core@core-01 $ docker service ps galera
ID                  NAME                IMAGE                          NODE                DESIRED STATE       CURRENT STATE            ERROR               P
ORTS
24uuqhm7p0ik        galera.1            toughiq/mariadb-cluster:10.3   core-01             Running             Running 2 minutes ago
0lz0fphiqk4h        galera.2            toughiq/mariadb-cluster:10.3   core-01             Running             Running 38 seconds ago
nlyfjvmyjdtl        galera.3            toughiq/mariadb-cluster:10.3   core-01             Running             Running 38 seconds ago

MaxScale サービスを作成

docker service create --name mxs \
  --network mynet \
  --env DB_SERVICE_NAME=galera \
  --env ENABLE_ROOT_USER=1 \
  --publish 3306:3306 \
  toughiq/maxscale:2.1.9

4krr51tx9mqy9ku4t8vjgng8w
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

docker service ps で作成したサービスを確認します。

core@core-01 ~ $ docker service ps mxs
ID            NAME   IMAGE                    NODE     DESIRED STATE  CURRENT STATE           ERROR  PORTS
q96p6th7xxma  mxs.1  toughiq/maxscale:2.1.9   core-01  Running        Running 52 seconds ago

maxadmin list servers で Galera Cluster のステータスを確認

MaxScale コンテナ上で maxadmin list servers を実行して Galera Clusterのステータスを確認してみます。

まず、MaxScale コンテナのIDを確認します。

core@core-01 $ docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS
               NAMES
91f99246a5c5        toughiq/maxscale:2.1.9         "/docker-entrypoint.…"   12 minutes ago      Up 11 minutes       3306-3307/tcp, 4006/tcp, 4008/tcp, 4442/t
cp, 6603/tcp   mxs.1.2q1znps6f37wt3f8j692rx0mx
d50085824290        toughiq/mariadb-cluster:10.3   "docker-entrypoint.s…"   14 minutes ago      Up 14 minutes       3306/tcp, 4444/tcp, 4567-4568/tcp
               galera.3.nlyfjvmyjdtljj6z2q2lvd1tv
0e361381690e        toughiq/mariadb-cluster:10.3   "docker-entrypoint.s…"   14 minutes ago      Up 14 minutes       3306/tcp, 4444/tcp, 4567-4568/tcp
               galera.2.0lz0fphiqk4h619hstufbb6m0
3089a575afb0        toughiq/mariadb-cluster:10.3   "docker-entrypoint.s…"   16 minutes ago      Up 16 minutes       3306/tcp, 4444/tcp, 4567-4568/tcp
               galera.1.24uuqhm7p0ikvecb4w4yxfnd8         

MaxScale の ID は 91f99246a5c5 ですので、以下のコマンドでクラスタのステータスを確認できます。

core@core-01 ~ $ docker exec -it 91f99246a5c5 maxadmin -pmariadb list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
10.0.1.12          | 10.0.1.12       |  3306 |           0 | Slave, Synced, Running
10.0.1.11          | 10.0.1.11       |  3306 |           0 | Master, Synced, Running
10.0.1.10          | 10.0.1.10       |  3306 |           0 | Slave, Synced, Running
-------------------+-----------------+-------+-------------+--------------------

サービスの削除

docker service rm galera mxs
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?