基于Docker的Mysql Cluster集群

参考

使用Docker创建Cluster步骤

实例目标:一个管理节点,二个数据节点,二个mysqlserver节点

  1. Create a docker network
docker network create cluster — subnet=192.168.0.0/16
  1. 修改管理节点的集群配置文件
    从https://github.com/mysql/mysql-docker/tree/mysql-cluster下载对应版本的my-cluster.cnf
    在结尾新增如下配置, 目的是增加一个mysqlserver节点
[mysqld]
NodeId=5
hostname=192.168.0.11
  1. Create the manager node

    -v 参数自行调整

docker run -d --net=cluster --name=management1 --ip=192.168.0.2 -v C:\docker\mysql\mysql-cluster.cnf:/etc/mysql-cluster.cnf mysql/mysql-cluster ndb_mgmd
  1. Create the data nodes

    集群配置文件中需要创建两个数据节点, 按指定的hostname参数自行调整--ip参数

docker run -d --net=cluster --name=ndb1 --ip=192.168.0.3 mysql/mysql-cluster ndbd
docker run -d --net=cluster --name=ndb2 --ip=192.168.0.4 mysql/mysql-cluster ndbd
  1. Create the Mysql nodes

    集群配置文件中需要创建两个mysql节点, 按指定的hostname参数自行调整--ip参数

docker run -d --net=cluster --name=mysql1 --ip=192.168.0.10 -e MYSQL_ROOT_PASSWORD=123 mysql/mysql-cluster mysqld
docker run -d --net=cluster --name=mysql2 --ip=192.168.0.11 -e MYSQL_ROOT_PASSWORD=123 mysql/mysql-cluster mysqld
  1. 在管理节点查看集群状态
docker run -it --net=cluster mysql/mysql-cluster ndb_mgm

运行show命令,打印集群状态

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.0.3  (mysql-5.7.27 ndb-7.6.11, Nodegroup: 0, *)
id=3    @192.168.0.4  (mysql-5.7.27 ndb-7.6.11, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.2  (mysql-5.7.27 ndb-7.6.11)

[mysqld(API)]   2 node(s)
id=4    @192.168.0.10  (mysql-5.7.27 ndb-7.6.11)
id=5    @192.168.0.11  (mysql-5.7.27 ndb-7.6.11)

my.cnf

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

[mysqld]
ndbcluster
ndb-connectstring=192.168.0.2
user=mysql

[mysql_cluster]
ndb-connectstring=192.168.0.2

mysql-cluster.cnf

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M


[ndb_mgmd]
NodeId=1
hostname=192.168.0.2
datadir=/var/lib/mysql

[ndbd]
NodeId=2
hostname=192.168.0.3
datadir=/var/lib/mysql

[ndbd]
NodeId=3
hostname=192.168.0.4
datadir=/var/lib/mysql

[mysqld]
NodeId=4
hostname=192.168.0.10

[mysqld]
NodeId=5
hostname=192.168.0.11

猜你喜欢

转载自www.cnblogs.com/byxxw/p/11433571.html