基於Docker的Mysql Cluster集羣

參考

使用Docker建立Cluster步驟

目標:一個管理節點,二個數據節點,二個mysqlserver節點node

  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下載對應版本的mysql-cluster.cnf
    在結尾新增以下配置, 目的是增長一個mysql server節點
[mysqld]
NodeId=5
hostname=192.168.0.11
  1. Create the manager node

-v 參數自行調整mysql

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參數git

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參數github

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命令,打印集羣狀態redis

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
相關文章
相關標籤/搜索