天天看點

docker mysql cluster_基于Docker的Mysql Cluster叢集

參考

使用Docker建立Cluster步驟

目标:一個管理節點,二個資料節點,二個mysqlserver節點

Create a docker network

docker network create cluster — subnet=192.168.0.0/16

修改管理節點的叢集配置檔案

從https://github.com/mysql/mysql-docker/tree/mysql-cluster下載下傳對應版本的mysql-cluster.cnf

在結尾新增如下配置, 目的是增加一個mysql server節點

[mysqld]

NodeId=5

hostname=192.168.0.11

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

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

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

在管理節點檢視叢集狀态

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