alirajabi / MySQL-Cluster

Dockerfile that creates a MySQL Cluster image.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Introduction

This Docker container provides a MySQL Cluster installation.

The project sources can be found on GitHub. The Docker image build is hosted at Docker Hub.

#Build

git clone https://github.com/g17/MySQL-Cluster.git
cd MySQL-Cluster
docker build -t h3nrik/mysql-cluster .

#Prerequisites

In order to set up the MySQL Cluster you should have prepared a proper network setup similar to the following. It includes one management node, two data nodes and two SQL nodes.

  • Management Node: host name mgm01 (192.168.0.1).
  • SQL Nodes: host name mysqld01 (192.168.0.100) and mysqld02 (192.168.0.101).
  • Data Nodes: host name ndbd01 (192.168.0.10) and ndbd02 (192.168.0.11).

#Installation

Prepare a configuration file for the management node similar to the following one (but do not change the datadir definitions!):

[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
datadir=/usr/local/mysql/data

[NDB_MGMD DEFAULT]
datadir=/var/lib/mysql-cluster

[NDB_MGMD]
NodeId=1
hostname=192.168.0.1

[NDBD]
NodeId=10
hostname=192.168.0.10

[NDBD]
NodeId=11
hostname=192.168.0.11

[MYSQLD]
NodeId=100
hostname=192.168.0.100

[MYSQLD]
NodeId=101
hostname=192.168.0.101

#Usage

  1. Start the management node on host 192.168.0.1:

     docker run -d --name ndb_mgmd01 --net=host -p 192.168.0.1:1186:1186 -v /path/to/your/config.ini:/etc/mysql-cluster.ini:ro h3nrik/mysql-cluster ndb_mgmd
    
  2. Connect with the management console to the management node to issue the SHOW command that displays your cluster configuration and state:

     docker run -it --rm --name ndb_mgm h3nrik/mysql-cluster ndb_mgm 192.168.0.1
    
  3. Run the data nodes on host 192.168.0.10 and 192.168.0.11:

     docker run -d --name ndbd01 --net=host h3nrik/mysql-cluster ndbd 192.168.0.1
     docker run -d --name ndbd02 --net=host h3nrik/mysql-cluster ndbd 192.168.0.1
    
  4. Run the SQL nodes on host 192.168.0.100 and 192.168.0.101:

     docker run -d --name mysqld01 --net=host -p 192.168.0.100:3306:3306 h3nrik/mysql-cluster mysqld 192.168.0.1
     docker run -d --name mysqld02 --net=host -p 192.168.0.101:3306:3306 h3nrik/mysql-cluster mysqld 192.168.0.1
    
  5. Now you can connect to any of the SQL nodes with your client.

#Update Nodes

You can easily update the data/SQL nodes e.g. for up-scaling the cluster:

  1. Modify the config.ini file mounted into the management node.
  2. Stop the management node.
  3. Start it again. It will do a reload of that configuration file automatically.
  4. Start the new SQL/data nodes on the hosts configured in the config.ini file.

#Further Ideas

In addition to this setup a MySQL proxy could be used to access the SQL nodes.

About

Dockerfile that creates a MySQL Cluster image.


Languages

Language:Shell 100.0%