如何在具有持久数据的多个节点上的Docker群中创建Percona XtraDB集群

时间:2019-01-27 12:49:59

标签: database docker docker-swarm percona

我想在Docker Swarm中使用生产环境中的持久数据设置PXC集群。

我的Ansible代码如下:

version: '3.7'

services:
  pxc_cluster:
    image: percona/percona-xtradb-cluster:5.7
    hostname: pxc_cluster
    environment:
      - CLUSTER_NAME={{ db.cluster_name }}
      - MYSQL_ROOT_PASSWORD={{ db.root_pass }}
      - MYSQL_DATABASE={{ db.percona.prod.name }}
      - MYSQL_USER={{ db.user }}
      - MYSQL_PASSWORD={{ db.pass }}
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      update_config:
        parallelism: 1
        delay: 10s
        failure_action: continue
        monitor: 30s
    networks:
      - percona-net

{% for n in range(1, 4) %}
  pxc{{n}}:
    image: percona/percona-xtradb-cluster:5.7
    hostname: pxc{{ n }}
    environment:
      - CLUSTER_NAME={{ db.cluster_name }}
      - CLUSTER_JOIN=pxc_cluster
      - MYSQL_ROOT_PASSWORD={{ db.root_pass }}
      - MYSQL_DATABASE={{ db.percona.prod.name }}
      - MYSQL_USER={{ db.user }}
      - MYSQL_PASSWORD={{ db.pass }}
    depends_on:
      - pxc_cluster
    volumes:
      - hdb_data{{ n }}:/var/lib/mysql
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      update_config:
        parallelism: 1
        delay: 10s
        failure_action: continue
        monitor: 30s
      placement:
        constraints:
          - node.labels.env == prod
          - node.labels.percona == pxc{{ n }}
    networks:
      - percona-net
{% endfor %}

  adminer:
    image: adminer
    deploy:
      restart_policy:
        condition: any
    networks:
      - percona-net
      - vpn-net

networks:
  percona-net:
    name: name_percona-net
  vpn-net:
    external:
      name: name_vpn-net

volumes:
{% for n in range(1, 4) %}
  hdb_data{{ n }}:
    driver: local
{% endfor %}

但是问题是,如果具有pxc_cluster的服务器出现故障,那么群集也会发生故障。随着群集的消失,服务器是否可以访问也无关紧要。 另外,如果pxc_cluster具有持久性数据,这也无济于事。

要在具有3个不同节点的HA上拥有3个数据库的集群,我该怎么办?

此致

Astin

0 个答案:

没有答案