转载来源:https://mysqlrelease.com/2017/05/docker-images-for-mysql-cluster/

We’re constantly working to improve packaging and distribution of MySQL products. We have official Docker images for MySQL Server and we use Docker images to provide easy to use previews of upcoming and experimental setups and features in our products. Today we’re dockerizing another major product by releasing preview Docker images for MySQL Cluster. In this blog post, we’ll see just how easy it is to have your own dockerized cluster up and running in less than five minutes.

Just a brief but important note on the status of these images first: While the MySQL Cluster version in these images is a fully tested and supported GA version, the Docker image setup is still experimental and should not at this time be utilized for production purposes.

The Docker image for MySQL Cluster comes with a default configuration that will give you a cluster consisting of two data nodes, one management node and one server node. We’ll use this default configuration in our first example and then proceed to show how you can easily override these defaults to customize your setup.

Now, let us start the stopwatch and get going.

Running with the default config

This setup will consist of one management node at IP 192.168.0.2, two data nodes at 192.168.0.3 and 192.168.0.4 respectively, and a MySQL server node at 192.168.0.10.

Since we will run our containers on a separate network, we go ahead and create that as follows:

docker network create cluster \--driver=bridge \--subnet=192.168.0.0/16 \--ip-range=192.168.0.0/24 \--gateway=192.168.1.1 \

We’re now ready to launch our containers. As you will see from the commands below, the first argument after the image name specifies the process to be started in the container (ndb_mgmd, ndbd or mysqld) and thus the type or role of the container. Any subsequent arguments will be forwarded directly to the respective process.

Launching our management node:

docker run -d --net=cluster --name=management1 --ip=192.168.0.2 mysql/mysql-cluster ndb_mgmd

Launching our first data node:

docker run -d -p 3310:3306 --net=cluster --name=ndb1 --ip=192.168.0.3 mysql/mysql-cluster ndbd

Launching our second data node:

docker run -d -p 3311:3306 --net=cluster --name=ndb2 --ip=192.168.0.4 mysql/mysql-cluster ndbd

Launching our third data node:

docker run -d -p 3312:3306 --net=cluster --name=ndb3 --ip=192.168.0.5 mysql/mysql-cluster ndbd

Launching our MySQL node:

docker run -d -p 3313:3306 --net=cluster --name=mysql1 --ip=192.168.0.10 mysql/mysql-cluster mysqld

By default, the MySQL node generates a one-time password for the MySQL admin user root@localhost which can be retrieved with

docker logs mysql1 2>&1 | grep password

For security reasons, you must reset this password upon the first connection to the MySQL server. Proceed as follows:

docker exec -it mysql1 mysql -uroot -p

On the resulting mysql client command line, input

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

… where MyNewPass is the new root password.

You now have a running MySQL Cluster setup. To verify that and in general to monitor and administer your cluster, you can spin up an interactive management client by running

docker run -it --net=cluster mysql/mysql-cluster

Type SHOW and you should see this:

ndb_mgm> SHOWConnected to Management Server at: 192.168.0.2:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2    @192.168.0.3  (mysql-5.7.18 ndb-7.6.2, Nodegroup: 0, *)id=3    @192.168.0.4  (mysql-5.7.18 ndb-7.6.2, Nodegroup: 0)[ndb_mgmd(MGM)] 1 node(s)id=1    @192.168.0.2  (mysql-5.7.18 ndb-7.6.2)[mysqld(API)]   1 node(s)id=4    @192.168.0.10  (mysql-5.7.18 ndb-7.6.2)

Using a custom config

The walkthrough above utilizes a default set of minimal config files embedded in the image, which gets you going with a simple and lean cluster for sandboxing and prototyping. We’ll now go on to show how you can run with a custom MySQL Cluster config.

The approach we’ll use is to create the config files on the host computer, then proceed to mount them into the Docker containers afterwards. In effect we’re going to be replacing the default config files that are present in the image with custom ones mounted from outside the container. For the sake of a simple example, we will describe the setup of a cluster with data and index memory increased from the rather anaemic default config used above.

Remember to clean out any running containers and networks from the previous example before you proceed.

On the Docker host machine, create <your-path>/mysql-cluster.cnf and paste the following into it:

[ndbd default]
NoOfReplicas=2
DataMemory=1536M
IndexMemory=192M[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

We also need a my.cnf file for the MySQL server in this cluster. Create <your-path>/my.cnf and paste the following into it.

[mysqld]
ndbcluster
ndb-connectstring=192.168.0.2[mysql_cluster]
ndb-connectstring=192.168.0.2

Create the Docker private network we’ll need:

docker network create cluster --subnet=192.168.0.0/16

We’re now ready to launch our containers.

Launching our management node:

docker run -d --net=cluster --name=management1 --ip=192.168.0.2 -v <your-path>/mysql-cluster.cnf:/etc/mysql-cluster.cnf mysql/mysql-cluster ndb_mgmd

Launching our first data node:

docker run -d --net=cluster --name=ndb1 --ip=192.168.0.3 -v <your-path>/my.cnf:/etc/my.cnf mysql/mysql-cluster ndbd

Launching our second data node:

docker run -d --net=cluster --name=ndb2 --ip=192.168.0.4 -v <your-path>/my.cnf:/etc/my.cnf mysql/mysql-cluster ndbd

Launching our MySQL node:

docker run -d --net=cluster --name=mysql1 --ip=192.168.0.10 -v <your-path>/my.cnf:/etc/my.cnf mysql/mysql-cluster mysqld

Now you can go on to retrieve and reset the MySQL admin user password and check that you have an actual running cluster by using the procedure described in the first example in this post.

Conclusion

The Docker image for MySQL Cluster aims to provide and easy and frictionless way to get up and running for sandbox development and rapid prototyping. Please do remember that this is a preview, and shouldn’t be used in production at this stage. We very much welcome feedback on this image. Please give us your comments below and we’ll factor your input into our ongoing work to take these images forward to production readiness.

Docker Images for MySQL Cluster相关推荐

  1. Docker系列之MySQL安装教程

    Docker系列之MySQL安装教程 有了前面的基础教程Docker系列之常用命令操作手册之后,本博客记录一篇mysql的安装教程 mysql镜像查询命令 docker search mysql 几个 ...

  2. 小白都能懂的 玩转docker系列之 Mysql同步数据

    先搜索一个镜像 [root@xiaoxiao ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL ...

  3. 【大数据】M1 mac win docker安装kafka+mysql+canal

    文章目录 kafka docker-compose创建kafka 容器启动以后,访问容器,并且发送消息测试 问题 Exception in thread "main" kafka. ...

  4. Docker下部署mysql

    一.拉取 Docker Hub 官方提供的MySQL镜像 docker pull mysql:5.7 二.创建数据.日志存放路径 mkdir -p ~/mysql/{data,logs} 三.运行容器 ...

  5. Mysql Cluster 集群 windows版本

    VM1:192.168.220.102 管理节点(MGM) VM2:192.168.220.103 数据节点(NDBD1),SQL节点(SQL1) VM3:192.168.220.104 数据节点(N ...

  6. 【推荐】MySQL Cluster报错及解决方法(不断更新中)

    排查问题技巧: MySQL Cluster 自带了一个错误代码的查看的小程序.通过这个小东西我们可以方便的定位问题的原因. 这个程序就是 perror 在MYSQL安装目录的bin下面. 如报错:ER ...

  7. MySQL Cluster安装

    管理节点:192.168.10.243 Data节点1:192.168.10.244 Data节点2:192.168.10.245 SQL节点1:192.168.30.244 SQL节点2:192.1 ...

  8. MySQL Cluster 日常维护

    在前面几篇文章已经详细介绍了MySQL Cluster的搭建,配置讲解.而且相信大家都掌握了基本用法.现在我们来看看Cluster的日常维护.熟悉日常维护,将有助于工作中更好的管理和使用Cluster ...

  9. linux开启docker mysql_Linux服务器利用Docker快速搭建MySQL数据库

    首先你要有一台Linux服务器 利用Xshell远程软件连接后就可以开始安装docker容器了. 1.第一步在Linux服务器上安装docker 2.第二步利用Docker拉取mysql镜像 Cent ...

最新文章

  1. python全套视频教程下载-老男孩python全套视频教程百度云资源下载
  2. 云炬Android开发笔记 10主界面-首页UI与数据解析器开发(RecyclerView)
  3. java实现红包要多少钱_Java实现发红包功能
  4. CXF小窥:知道服务器端wsdl地址,如何本地测试服务接口
  5. SQL中where 1 = 1的用处
  6. 读书和不读书有什么区别呢?
  7. android 3d布局轮播,android 图片/视频混合轮播控件banner
  8. Java基础笔记(十五)——封装(续)static关键字
  9. 量子计算机编程教程,量子信息与量子计算简明教程 PDF扫描版[12MB]
  10. java hexbin_bin文件转换为hex文件操作步骤解析 - 全文
  11. 基于深度学习时间序列分类研究综述[论文阅读]
  12. 大数据自助分析平台系列文章(深入讲解由零开始设计一个大数据自助分析平台)
  13. L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到一个处理错误
  14. Excel用户打死想不到:表格能做APP,WPS用户:金山系出品就是牛
  15. 几种kafka多线程消费方式
  16. 阿里物联网云平台搭建(一)
  17. 【算法】高精度(加减乘除)包含高精度*高精度高精度/高精度
  18. Java并发原理解析!docker命令
  19. Vysor 安装教程
  20. 金蝶EAS客户端批量执行sql代码

热门文章

  1. GetWindowThreadProcessId
  2. Node.js web应用模块之forever
  3. iOS编写最简单的界面切换应用
  4. moodle架构分析---表现层的设计(二)
  5. 斗地主AI算法——第十章の被动出牌(4)
  6. 每日一题(C语言基础篇)3
  7. 【AI视野·今日NLP 自然语言处理论文速览 第二十五期】Fri, 1 Oct 2021
  8. s2 理论 第二套题
  9. 看脸 高效学英语 下
  10. 定时备份mysql数据库压缩文件