dockermariadbgaleramaxscale

MaxScale doesn't connect to Galera Cluster


I am working on a distributed HA cloud system and I have a Galera Cluster with 3 separated servers in Docker Swarm. It works as expected.

I have 3 separated services for the Galera members due to bootstrapping (I cannot be solved with simple replicas). Because of this, I have to have a replicated load balancer/proxy to use the cluster (One service in Swarm with 3 replicas which will be used in the connection string).

The design should be similar like that:

Design

I have tried to setup the MaxScale service but the maxctrl list servers command (Inside running container) says:

Error: Could not connect to MaxScale

Used command to start system:

docker-compose up --remove-orphans --force-recreate

I have created a minimal setup to test the Galera Cluster with MaxScale on localhost (Single node structure only for testing. The real product has 3 manager nodes and 3 db nodes). Please see below the system where I can reproduce the issue.

My docker-compose.yml file:

version: "3.8"

services:
  galera0:
      image: bitnami/mariadb-galera:10.4.31
      hostname: galera0
      networks:
        - galera_net
      volumes:
        - ./my.cnf:/opt/bitnami/mariadb/conf/my_custom.cnf:ro
        - ./init_db_for_maxscale.sql:/docker-entrypoint-initdb.d/init_db_for_maxscale.sql
      environment:
        MARIADB_GALERA_CLUSTER_NAME: my_galera
        MARIADB_GALERA_MARIABACKUP_USER: my_mariabackup_user
        MARIADB_GALERA_MARIABACKUP_PASSWORD: my_mariabackup_password
        MARIADB_ROOT_PASSWORD: my_root_password
        MARIADB_GALERA_CLUSTER_BOOTSTRAP: "yes"
        MARIADB_GALERA_FORCE_SAFETOBOOTSTRAP: "yes"
        MARIADB_USER: my_user
        MARIADB_PASSWORD: my_password
        MARIADB_DATABASE: my_database
        MARIADB_REPLICATION_USER: my_replication_user
        MARIADB_REPLICATION_PASSWORD: my_replication_password
      healthcheck:
        test: ['CMD', '/opt/bitnami/scripts/mariadb-galera/healthcheck.sh']
        interval: 15s
        timeout: 5s
        retries: 10

  galera1:
      image: bitnami/mariadb-galera:10.4.31
      hostname: galera1
      networks:
        - galera_net
      volumes:
        - ./my.cnf:/opt/bitnami/mariadb/conf/my_custom.cnf:ro
        - ./init_db_for_maxscale.sql:/docker-entrypoint-initdb.d/init_db_for_maxscale.sql
      environment:
        MARIADB_GALERA_CLUSTER_NAME: my_galera
        MARIADB_GALERA_CLUSTER_ADDRESS: gcomm://galera0:4567,0:0:0:0:4567
        MARIADB_GALERA_MARIABACKUP_USER: my_mariabackup_user
        MARIADB_GALERA_MARIABACKUP_PASSWORD: my_mariabackup_password
        MARIADB_ROOT_PASSWORD: my_root_password
        MARIADB_REPLICATION_USER: my_replication_user
        MARIADB_REPLICATION_PASSWORD: my_replication_password
        MARIADB_INIT_SLEEP_TIME: 30
      healthcheck:
        test: [ 'CMD', '/opt/bitnami/scripts/mariadb-galera/healthcheck.sh' ]
        interval: 15s
        timeout: 5s
        retries: 10
      depends_on:
        galera0:
          condition: service_healthy

  galera2:
      image: bitnami/mariadb-galera:10.4.31
      hostname: galera2
      networks:
        - galera_net
      volumes:
        - ./my.cnf:/opt/bitnami/mariadb/conf/my_custom.cnf:ro
        - ./init_db_for_maxscale.sql:/docker-entrypoint-initdb.d/init_db_for_maxscale.sql
      environment:
        MARIADB_GALERA_CLUSTER_NAME: my_galera
        MARIADB_GALERA_CLUSTER_ADDRESS: gcomm://galera0:4567,0:0:0:0:4567
        MARIADB_GALERA_MARIABACKUP_USER: my_mariabackup_user
        MARIADB_GALERA_MARIABACKUP_PASSWORD: my_mariabackup_password
        MARIADB_ROOT_PASSWORD: my_root_password
        MARIADB_REPLICATION_USER: my_replication_user
        MARIADB_REPLICATION_PASSWORD: my_replication_password
        MARIADB_INIT_SLEEP_TIME: 30
      healthcheck:
        test: [ 'CMD', '/opt/bitnami/scripts/mariadb-galera/healthcheck.sh' ]
        interval: 15s
        timeout: 5s
        retries: 10
      depends_on:
        galera0:
          condition: service_healthy

  mariadb-maxscale:
    image: mariadb/maxscale:23.08
    hostname: mariadb-maxscale
    networks:
      - galera_net
    volumes:
      - ./maxscale.cnf:/etc/maxscale.cnf
    depends_on:
      galera0:
        condition: service_healthy
      galera1:
        condition: service_healthy
      galera2:
        condition: service_healthy

networks:
  galera_net: {}

maxscale.cnf content:

########################
## Server list
########################

[mariadb1]
type            = server
address         = galera0
port            = 3306
protocol        = MariaDBBackend
serv_weight     = 1

[mariadb2]
type            = server
address         = galera1
port            = 3306
protocol        = MariaDBBackend
serv_weight     = 1

[mariadb3]
type            = server
address         = galera2
port            = 3306
protocol        = MariaDBBackend
serv_weight     = 1

#########################
## MaxScale configuration
#########################

[MaxScale]
threads                 = auto
log_augmentation        = 1
ms_timestamp            = 1
syslog                  = 1
# log_debug               = 1

#########################
# Monitor for the servers
#########################

[MariaDB-Monitor]
type                    = monitor
module                  = mariadbmon
servers                 = mariadb1,mariadb2,mariadb3
user                    = maxscale
password                = my_s3cret
# auto_failover           = true
# auto_rejoin             = true
# enforce_read_only_slaves = 1
monitor_interval        = 2000

#########################
## Service definitions for read/write splitting and read-only services.
#########################

[Read-Write-Service]
type            = service
router          = readwritesplit
servers         = mariadb1,mariadb2,mariadb3
user            = maxscale
password        = my_s3cret
# max_slave_connections           = 100%
# max_sescmd_history              = 1500
# causal_reads                    = true
# causal_reads_timeout            = 10
# transaction_replay              = true
# transaction_replay_max_size     = 1Mi
# delayed_retry                   = true
# master_reconnection             = true
# master_failure_mode             = fail_on_write
# max_slave_replication_lag       = 3

[Read-Only-Service]
type            = service
router          = readconnroute
servers         = mariadb1,mariadb2,mariadb3
router_options  = slave
user            = maxscale
password        = my_s3cret

##########################
## Listener definitions for the service
## Listeners represent the ports the service will listen on.
##########################

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

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

init_db_for_maxscale.sql content:

CREATE USER IF NOT EXISTS 'maxscale'@'%' IDENTIFIED BY 'my_s3cret';
GRANT SELECT ON mysql.user TO 'maxscale'@'%';
GRANT SELECT ON mysql.db TO 'maxscale'@'%';
GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.procs_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'%';
GRANT SHOW DATABASES ON *.* TO 'maxscale'@'%';

GRANT ALL PRIVILEGES ON *.* TO maxscale@'%';

I checked all the MariaDB containers and the created user is available and the permissions are set in the DB (based on select * from mysql. user;).

docker container logs <maxscale_continer> command output (It's repeated infinitely):

mariadb-maxscale_1  | Starting...
mariadb-maxscale_1  | MaxScale PID = 1698
mariadb-maxscale_1  | 
mariadb-maxscale_1  | Awakened by User defined signal 1
mariadb-maxscale_1  | 'maxscale' monitor action done
mariadb-maxscale_1  | 'maxscale' process is not running
mariadb-maxscale_1  | 'maxscale' trying to restart
mariadb-maxscale_1  | 'maxscale' start: '/usr/bin/maxscale-restart'
mariadb-maxscale_1  | 'mariadb-maxscale' unmonitor on user request
mariadb-maxscale_1  | 'maxscale' unmonitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened
mariadb-maxscale_1  | 'mariadb-maxscale' monitor on user request
mariadb-maxscale_1  | 'maxscale' monitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened
mariadb-maxscale_1  | 'mariadb-maxscale' monitor action done
mariadb-maxscale_1  | Awakened by User defined signal 1
mariadb-maxscale_1  | 'maxscale' failed to start (exit status 0) -- '/usr/bin/maxscale-restart': Stopping...
mariadb-maxscale_1  | Starting...
mariadb-maxscale_1  | MaxScale PID = 1713
mariadb-maxscale_1  | 
mariadb-maxscale_1  | 'maxscale' monitor action done
mariadb-maxscale_1  | 'maxscale' trying to restart
mariadb-maxscale_1  | 'maxscale' process is not running
mariadb-maxscale_1  | 'maxscale' start: '/usr/bin/maxscale-restart'
mariadb-maxscale_1  | 'mariadb-maxscale' unmonitor on user request
mariadb-maxscale_1  | 'maxscale' unmonitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened
mariadb-maxscale_1  | 'mariadb-maxscale' monitor on user request
mariadb-maxscale_1  | 'maxscale' monitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened
mariadb-maxscale_1  | 'maxscale' failed to start (exit status 0) -- '/usr/bin/maxscale-restart': Stopping...
mariadb-maxscale_1  | Starting...
mariadb-maxscale_1  | MaxScale PID = 1728
mariadb-maxscale_1  | 
mariadb-maxscale_1  | 'mariadb-maxscale' monitor action done
mariadb-maxscale_1  | Awakened by User defined signal 1
mariadb-maxscale_1  | 'maxscale' monitor action done
mariadb-maxscale_1  | 'maxscale' process is not running
mariadb-maxscale_1  | 'maxscale' trying to restart
mariadb-maxscale_1  | 'maxscale' start: '/usr/bin/maxscale-restart'
mariadb-maxscale_1  | 'mariadb-maxscale' unmonitor on user request
mariadb-maxscale_1  | 'maxscale' unmonitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened
mariadb-maxscale_1  | 'mariadb-maxscale' monitor on user request
mariadb-maxscale_1  | 'maxscale' monitor on user request
mariadb-maxscale_1  | Monit daemon with PID 12 awakened

Notes:


Solution

  • I have just found the solution for my problem. I have checked the full log of MaxScale with docker exec -it <container_id> cat var/log/maxscale/maxscale.log where the root-cause can be found (I don't understand why it isn't visible on STDOUT...)

    I had to do the following changes in MaxScale config:

    1. The serv_weight = 1 parameter had to be changed to rank = primary. MaxScale ref.

    2. The monitor_interval = 2000 has to be changed to monitor_interval = 2000ms (The "ms" was missing)

    Output after above changes:

     maxctrl list servers
    ┌──────────┬─────────┬──────┬─────────────┬─────────────────┬────────┬─────────────────┐
    │ Server   │ Address │ Port │ Connections │ State           │ GTID   │ Monitor         │
    ├──────────┼─────────┼──────┼─────────────┼─────────────────┼────────┼─────────────────┤
    │ mariadb1 │ galera0 │ 3306 │ 0           │ Master, Running │ 0-1-65 │ MariaDB-Monitor │
    ├──────────┼─────────┼──────┼─────────────┼─────────────────┼────────┼─────────────────┤
    │ mariadb2 │ galera1 │ 3306 │ 0           │ Running         │ 0-1-65 │ MariaDB-Monitor │
    ├──────────┼─────────┼──────┼─────────────┼─────────────────┼────────┼─────────────────┤
    │ mariadb3 │ galera2 │ 3306 │ 0           │ Running         │ 0-1-65 │ MariaDB-Monitor │
    └──────────┴─────────┴──────┴─────────────┴─────────────────┴────────┴─────────────────┘