Help us understand the problem. What is going on with this article?

MariaDB Galera ClusterをDockerで動かしてみる

CentOS 7
MariaDB 10.4

フォルダ構成
|--docker-compose.yml
|--dockerfiles
|  |--cluster
|  |--cluster.cnf
|  |--mariadb.repo

MariaDB 10.4でgaleraのバージョンが4になったため「galera」ではなく「galera-4」を指定

/dockerfile/cluster
FROM centos:7
ADD mariadb.repo /etc/yum.repos.d/mariadb.repo
RUN yum install -y -q MariaDB-server MariaDB-client galera-4 sudo

ADD cluster.cnf /etc/my.cnf.d/my.cnf

galera4のパスが異なるため「wsrep_provider」の指定で、
「galera」のところを「galera-4」にしています

/dockerfile/cluster.cnf
[mysqld]
default_storage_engine=InnoDB
log-bin=/var/lib/mysql/mysql-bin-log
binlog_format=ROW
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
transaction-isolation = READ-COMMITTED
innodb_flush_log_at_trx_commit=0

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name=DBCLUSTER
wsrep_sst_method=rsync
wsrep_slave_threads=2
wsrep_cluster_address=gcomm://node-1,node-2,node-3
/dockerfile/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
docker-compose.yml
version: "3.3"
services:
  node-1:
    build:
      context: ./dockerfiles
      dockerfile: cluster
    ports:
      - "4001:3306"
    command: sudo -u mysql mysqld --wsrep-new-cluster

  node-2:
    build:
      context: ./dockerfiles
      dockerfile: cluster
    ports:
      - "4002:3306"
    links:
      - node-1
    command: sudo -u mysql mysqld

  node-3:
    build:
      context: ./dockerfiles
      dockerfile: cluster
    ports:
      - "4003:3306"
    links:
      - node-1
    command: sudo -u mysql mysqld
$ docker-compose up -d

$ docker-compose exec node-1 mysql -e "create database test_db"
$ docker-compose exec node-2 mysql -e "show databases"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| test_db            |
+--------------------+

$ docker-compose exec node-3 mysql -e "show databases"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| test_db            |
+--------------------+
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away