MySQL Cluster on docker-compose

MySQL Cluster是一个高性能、可扩展、集群化数据库产品。MySQL Cluster是一个基于NDB Cluster存储引擎的完整分布式数据库系统,采用无共享的数据存储技术,实时同步且支持快速故障切换、事务。NDB是一种in-memory的存储引擎,它具有可用性高和数据一致性好的特点。

MySQL Cluster可由多台服务器组成的、同时对外提供数据管理服务的分布式集群系统。

MySQL Cluster分为三类节点:

  • 数据节点(Data Nodes):用于存储集群的数据。实现底层数据存储的功能,保存Cluster 的数据。
  • SQL节点(SQL Nodes):向外提供一个标准的SQL语言编程接口。SQL节点负责向数据节点传送访问请求。
  • 管理节点(NDB Management Server):负责整个Cluster 集群中各个节点的管理工作,包括集群的配置,启动关闭各节点,以及实施数据的备份恢复等。

下面docker中创建一个5节点集群,1个管理节点management1,2个数据节点ndb1,ndb2,2个sql节点mysql1,mysql2

启动脚本见mysql-cluster

docker-compose.yaml

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
version: '3'

networks:
    mysql_cluster_net:
        driver: bridge
        ipam:
            driver: default
            config:
            - subnet: 172.16.38.0/24

services:
    management1:
      container_name: "management1"
      image: mysql/mysql-cluster:8.0.17
      networks:
          mysql_cluster_net:
              ipv4_address: 172.16.38.102
      volumes:
          - ./cnf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
          - node1-data:/var/lib/mysql
      expose:
          - "1186"
          - "2202"
          - "3306"
          - "33060"
      command: 
          - ndb_mgmd

    ndb1:
      container_name: "ndb1"
      image: mysql/mysql-cluster:8.0.17
      networks:
          mysql_cluster_net:
              ipv4_address: 172.16.38.103
      volumes:
          - ./cnf/my.cnf:/etc/my.cnf
          - node2-data:/var/lib/mysql
      expose:
          - "1186"
          - "2202"
          - "3306"
          - "33060"
      command: 
          - ndbd
      depends_on:
          - management1

    ndb2:
      container_name: "ndb2"
      image: mysql/mysql-cluster:8.0.17
      networks:
          mysql_cluster_net:
              ipv4_address: 172.16.38.104
      volumes:
          - ./cnf/my.cnf:/etc/my.cnf
          - node3-data:/var/lib/mysql
      expose:
          - "1186"
          - "2202"
          - "3306"
          - "33060"
      command: 
          - ndbd
      depends_on:
          - management1

    mysql1:
      container_name: "mysql1"
      image: mysql/mysql-cluster:8.0.17
      networks:
          mysql_cluster_net:
              ipv4_address: 172.16.38.115
      volumes:
          - ./cnf/my.cnf:/etc/my.cnf
          - node4-data:/var/lib/mysql
          - ./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/
      expose:
          - "1186"
          - "2202"
          - "3306"
          - "33060"
      environment:
          - MYSQL_ROOT_PASSWORD=000000
      command: 
          - mysqld
      depends_on:
          - management1
          - ndb1
          - ndb2

    mysql2:
      container_name: "mysql2"
      image: mysql/mysql-cluster:8.0.17
      networks:
          mysql_cluster_net:
              ipv4_address: 172.16.38.116
      volumes:
          - ./cnf/my.cnf:/etc/my.cnf
          - node5-data:/var/lib/mysql
          - ./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/
      expose:
          - "1186"
          - "2202"
          - "3306"
          - "33060"
      environment:
          - MYSQL_ROOT_PASSWORD=000000
      command: 
          - mysqld
      depends_on:
          - management1
          - ndb1
          - ndb2
          - mysql1

volumes:
    node1-data:
    node2-data:
    node3-data:
    node4-data:
    node5-data:

参考