mariadb MaxScale未连接到加莱拉群集

zrfyljdw  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(113)

我在一个分布式HA云系统上工作,我有一个Galera Cluster,在Docker Swarm中有3个独立的服务器。它的工作和预期的一样。
由于 Bootstrap ,我为Galera成员提供了3个独立的服务(我无法用简单的副本解决)。正因为如此,我必须有一个复制的负载均衡器/代理来使用集群(Swarm中的一个服务有3个副本,将在连接字符串中使用)。

设计应该是这样的:

我尝试设置MaxScale服务,但maxctrl list servers命令(在运行容器内)说:
Error: Could not connect to MaxScale

启动系统所用命令:

docker-compose up --remove-orphans --force-recreate
我已经创建了一个最小的设置来测试localhost上的MaxScaleGalera Cluster(单节点结构仅用于测试)。真实的产品有3个管理器节点和3个数据库节点)。请参阅下面的系统,我可以重现的问题。

我的docker-compose.yml文件:

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.cfn内容:

########################
## 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内容:

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@'%';

我检查了所有的MariaDB容器,创建的用户可用,权限在DB中设置(基于select * from mysql. user;)。

docker container logs <maxscale_continer>命令输出(无限重复):

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

备注:

  • 我已经阅读了许多文档,正如我所看到的,IP地址用于maxscale配置中的“服务器”,但我认为它应该通过主机名(服务名称)看到MariaDB,因为相同的Docker网络。
  • 我没有打开任何端口,因为所有端口都可以在Docker网络中访问。
amrnrhlw

amrnrhlw1#

我刚刚找到了解决问题的方法。我已经用docker exec -it <container_id> cat var/log/maxscale/maxscale.log检查了MaxScale的完整日志,可以找到根本原因(我不明白为什么它在STDOUT上不可见...)

我必须在MaxScale配置中进行以下更改:

1.必须将serv_weight = 1参数更改为rank = primary。MaxScale参考
1.必须将monitor_interval = 2000更改为monitor_interval = 2000ms(缺少“ms”)

以上修改后的输出:

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 │
└──────────┴─────────┴──────┴─────────────┴─────────────────┴────────┴─────────────────┘

相关问题