MaxScale 未设置从属状态

发布于 2025-01-14 17:29:47 字数 2483 浏览 4 评论 0原文

我们希望通过 docker-compose 使用 MaxScale 和两个 MariaDB 数据库。

我们遇到的问题是我们无法通过 maxscale 实现数据库的复制。 两个数据库上均可通过 MaxScale 获得写入权限。通过 maxscale 容器中的命令 maxscale listservers,我们可以看到这两个服务器。第一个服务器的状态为Master, Running,第二个服务器的状态仅为Running

我的 docker-compose.yaml:

version: '3'
services:

  # Application
  app:
    build:
      context: .
      dockerfile: app.dockerfile
    working_dir: /var/www/project
    volumes:
      - ./project:/var/www/project
      - ./php.ini:/usr/local/etc/php/php.ini
    links:
      - database:database
    environment:
      - "DATABASE_HOST=database"
      - "DATABASE_PORT=4006"

  # Web server
  web:
    image: nginx:latest
    volumes:
      - ./vhost.conf:/etc/nginx/conf.d/default.conf
      - ./nginx-logs:/var/log/nginx
      # Inherit from app container
      - ./project:/var/www/project
      - ./php.ini:/usr/local/etc/php/php.ini
    ports:
      - 0.0.0.0:8021:80
    links:
      - app:app

  # Database
  database:
    image: mariadb:latest
    ports:
      - 0.0.0.0:3306:3306
    volumes:
      - ./database:/var/lib/mysql
      - ./database-config:/etc/mysql/
    command: mysqld --log-bin=mariadb-bin --binlog-format=ROW --server-id=3001 --log-slave-updates
    environment:
      - "MYSQL_ROOT_PASSWORD=secretDummyPassword"
      - "MYSQL_DATABASE=database"
      - "MYSQL_USER=database"
      - "MYSQL_PASSWORD=secretDummyPassword"
      - "skip-networking=0"

  #Max Scale
  maxscale:
    image: mariadb/maxscale:6.2.3
    depends_on:
      - database
    volumes:
      - ./maxscale.cnf:/etc/maxscale.cnf
    ports:
      - 0.0.0.0:4006:4006 # readwrite port
      - 0.0.0.0:4008:4008 # readonly port
      - 0.0.0.0:8989:8989 # REST API port
    links:
      - database:database

volumes:
  app: {}

我的 maxscale.cnf:

[maxscale]
threads=auto

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2
user=database
password=secretDummyPassword
auto_failover=true
auto_rejoin=true
enforce_read_only_slaves=1

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2
user=database
password=secretDummyPassword
master_failure_mode=fail_on_write

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

[server1]
type=server
address=195.XXX.123.22
port=3306
protocol=MariaDBBackend

[server2]
type=server
address=142.XXX.186.188
port=3306
protocol=MariaDBBackend

We want to use MaxScale and two MariaDB databases with docker-compose.

We have the problem that we do not achieve replication of the database via maxscale.
Write permissions are available via MaxScale on both databases. Via the command maxscale list servers in the maxscale container, we see both servers. The first server has the states Master, Running and the second server has only the state Running.

My docker-compose.yaml:

version: '3'
services:

  # Application
  app:
    build:
      context: .
      dockerfile: app.dockerfile
    working_dir: /var/www/project
    volumes:
      - ./project:/var/www/project
      - ./php.ini:/usr/local/etc/php/php.ini
    links:
      - database:database
    environment:
      - "DATABASE_HOST=database"
      - "DATABASE_PORT=4006"

  # Web server
  web:
    image: nginx:latest
    volumes:
      - ./vhost.conf:/etc/nginx/conf.d/default.conf
      - ./nginx-logs:/var/log/nginx
      # Inherit from app container
      - ./project:/var/www/project
      - ./php.ini:/usr/local/etc/php/php.ini
    ports:
      - 0.0.0.0:8021:80
    links:
      - app:app

  # Database
  database:
    image: mariadb:latest
    ports:
      - 0.0.0.0:3306:3306
    volumes:
      - ./database:/var/lib/mysql
      - ./database-config:/etc/mysql/
    command: mysqld --log-bin=mariadb-bin --binlog-format=ROW --server-id=3001 --log-slave-updates
    environment:
      - "MYSQL_ROOT_PASSWORD=secretDummyPassword"
      - "MYSQL_DATABASE=database"
      - "MYSQL_USER=database"
      - "MYSQL_PASSWORD=secretDummyPassword"
      - "skip-networking=0"

  #Max Scale
  maxscale:
    image: mariadb/maxscale:6.2.3
    depends_on:
      - database
    volumes:
      - ./maxscale.cnf:/etc/maxscale.cnf
    ports:
      - 0.0.0.0:4006:4006 # readwrite port
      - 0.0.0.0:4008:4008 # readonly port
      - 0.0.0.0:8989:8989 # REST API port
    links:
      - database:database

volumes:
  app: {}

My maxscale.cnf:

[maxscale]
threads=auto

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2
user=database
password=secretDummyPassword
auto_failover=true
auto_rejoin=true
enforce_read_only_slaves=1

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2
user=database
password=secretDummyPassword
master_failure_mode=fail_on_write

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

[server1]
type=server
address=195.XXX.123.22
port=3306
protocol=MariaDBBackend

[server2]
type=server
address=142.XXX.186.188
port=3306
protocol=MariaDBBackend

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星光不落少年眉 2025-01-21 17:29:47

如果您尚未手动配置复制,则可以在 Maxscale 容器内使用以下命令来设置服务器之间的复制:

maxctrl call command mariadbmon reset-replication MariaDB-Monitor server1

这会导致为 MariaDB-Monitor 配置的所有其他服务器开始从以下位置进行复制服务器1

注意:此命令会重置 GTID 位置,因此不应在实时系统上使用。如果您使用的是实时系统,请使用 CHANGE MASTER TO 命令具有正确的 GTID 坐标。它不会触及数据,但您会丢失历史记录(它会执行 重置主控)。


如果您希望在容器首次启动时自动配置复制,您可以在 /docker-entrypoint-initdb.d 挂载一个包含 SQL 命令的文件,MariaDB 将在启动时执行它们。对于自动化系统来说,这可能是一个更好的解决方案,并且对于测试设置来说非常方便。

If you haven't configured the replication manually, you can use the following command inside the Maxscale container to set up replication between the servers:

maxctrl call command mariadbmon reset-replication MariaDB-Monitor server1

This causes all other servers configured for the MariaDB-Monitor to start replicating from server1.

Note: this command resets the GTID positions so it should not be used on a live system. If you are using a live system, use the CHANGE MASTER TO command with the correct GTID coordinates. It won't touch the data but you'll lose the history (it does a RESET MASTER).


If you want the replication to be configured automatically when the container is first started, you can mount a file with SQL commands in it at /docker-entrypoint-initdb.d and MariaDB will execute them during startup. This is probably a better solution for automated systems and it is quite convenient for a test setup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文