Docker上部署MySQLCluster(基于mysql/mysql-cluster镜像)

What is MySQL Cluster? Mysql集群的概念?

MySQL Cluster is built on the NDB storage engine and provides a highly scalable, real-time, ACID-compliant transactional database, combining 99.999% availability with the low TCO of open source. Designed around a distributed, multi-master architecture with no single point of failure, MySQL Cluster scales horizontally on commodity hardware to serve read and write intensive workloads, accessed via SQL and NoSQL interfaces.

MySQL Cluster构建于NDB存储引擎之上,提供高度可伸缩、实时、符合ACID的事务数据库,结合了99.999%的可用性和开放源码的低TCO。MySQL Cluster是围绕分布式、多主、服务架构设计的,所以没有单点故障,它在商品硬件上横向扩展,以提供通过SQL和NoSQL接口访问的读写密集型工作负载。

For more information about MySQL Cluster, please visit https://www.mysql.com/products/cluster/

更多MySQL集群资料,请访问:https://www.mysql.com/products/cluster/

MySQL Cluster Docker Images Mysql集群Docker镜像

These are optimized MySQL Cluster Docker images, created and maintained by the MySQL team at Oracle. The available versions are:

这些是优化的MySQL集群DOCKER镜像,由Oracle公司的MySQL团队创建和维护。可用的版本是:

MySQL Cluster 7.5 (tag: 7.5)
MySQL Cluster 7.6, the latest GA version (tag: 7.6 or latest)

Images are updated when new MySQL Cluster maintenance releases and development milestones are published. Please note that all MySQL Cluster Docker images are to be considered experiemental and should not be used in production.

当新的MySQL集群版本发布时,镜像被更新。请注意,所有MySQL集群镜像是用于测试或实验性,不推荐在生产中使用。

How to Use the MySQL Cluster Images

Start a MySQL Cluster Using Default Configuration

Note that the ordering of container startup is very strict, and will likely need to be started from scratch if any step fails
First we create an internal Docker network that the containers will use to communicate

注意,容器启动的顺序非常严格,如果任何步骤失败,都可能需要从头开始。
首先,我们创建一个内部的DOCKER网络,容器将用来进行通信。

docker network create cluster --subnet=192.168.0.0/16

Then we start the management node

然后确定管理节点

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

The two data nodes

然后启动数据节点

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

And finally the MySQL server node

最后启动Server节点

docker run -d --net=cluster --name=mysql1 --ip=192.168.0.10 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql/mysql-cluster mysqld

The server will be initialized with a randomized password that will need to be changed, so fetch it from the log, then log in and change the password.

服务器将用一个需要更改的随机密码初始化,因此从日志中取出它,然后登录并更改密码。


If you get an error saying «ERROR 2002 (HY000): Can't connect to local MySQL server through socket» then the server has not finished initializing yet.

如果您得到一个错误提示_ERROR 2002(HY000):无法通过套接字连接到本地MySQL服务器_那么服务器还没有完成初始化。

 

#打印自动生成的密码,可能刚开始有一段时间,没打印出来,等会再输入docker logs mysql1 2>&1 查找
docker logs mysql1 2>&1 | grep PASSWORD
#复制自动生成的密码,登录管理员账号
docker exec -it mysql1 mysql -uroot -p
#修改root的密码,此处的‘MyNewPass’请改为自己的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
#刷新权限
flush privileges; 

 

Finally start a container with an interactive management client to verify that the cluster is up

最后启动一个带有交互式管理客户端的容器,以验证集群是否已启动。

 

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

Run the SHOW command to print cluster status. You should see the following

运行如下命令以打印群集状态,您应该看到以下内容:

Starting ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.0.2:1186
Cluster 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)

Customizing MySQL Cluster

The default MySQL Cluster image includes two config files which are also available in the github repository at https://github.com/mysql/mysql-docker/tree/mysql-cluster

定制MySQL集群

默认的MySQL集群图像包含两个配置文件,这些文件也可在如下地址中的GITHUB存储库中使用

https://github.com/mysql/mysql-docker/tree/mysql-cluster

  • /etc/my.cnf
  • /etc/mysql-cluster.cnf
  • To change the cluster, for instance by adding more nodes or change the network setup, these files must be updated. For more information on how to do so, please refer to the MySQL Cluster documentation at to https://dev.mysql.com/doc/index-cluster.html
    To map up custom config files when starting the container, add the -v flag to load an external file. Example:
    docker run -d --net=cluster --name=management1 --ip=192.168.0.2 -v <path-to-your-file>/mysql-cluster.cnf:/etc/mysql-cluster.cnf mysql/mysql-cluster ndb_mgmd
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值