Windows下搭建Mysql集群

Mysql集群的基本架构如下:

image

基本原理参考:【转】MySQL Cluster (集群)基本原理

这里采用最小配置,用两台机器来分别部署一个management 节点,2个data node, 2个sql node.

Management Node:    192.168.0.102

Data Node A:            192.168.0.102

Data Node B:            192.168.0.104

Sql Node A:               192.168.0.102

Sql Node B:               192.168.0.104

1. 首先从Mysql官方网站上下载最新的Mysql Cluster免安装包 (http://downloads.mysql.com/archives/cluster/

注意我们下载的是ZIP Archive

2.将免安装包分别解压到两台机器的C:Mysql文件夹下

3. 在Management Node的C:MysqlBin下新建Config文件夹,用来存放cluster的配置文件。

3.1首先需要为management node创建一个默认配置文件my.ini ,内容如下:

[mysql_cluster]
# Options for management node process
config-file=C:/mysql/bin/config/config.ini

3.2 创建整个cluster的配置文件config.ini

[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2                      # Number of replicas
DataDir=C:/mysql/bin/cluster-data   # Directory for each data node's data files
                                    # Forward slashes used in directory path,
                                    # rather than backslashes. This is correct;
                                    # see Important note in text
DataMemory=80M    # Memory allocated to data storage
IndexMemory=18M   # Memory allocated to index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example Cluster setup.

[ndb_mgmd]
# Management process options:
HostName=192.168.0.102              # Hostname or IP address of management node
DataDir=C:/mysql/bin/cluster-logs   # Directory for management node log files

[ndbd]
# Options for data node "A":
                             # (one [ndbd] section per data node)
HostName=192.168.0.102           # Hostname or IP address

[ndbd]
# Options for data node "B":

HostName=192.168.0.104           # Hostname or IP address

[mysqld]
# SQL node A options:

HostName=192.168.0.102           # Hostname or IP address

[mysqld]
# SQL node B options:

HostName=192.168.0.104           # Hostname or IP address

4. 启动Management Node,命令如下:

c:mysqlin db_mgmd.exe --configdir=c:mysqlinconfig --config-file=c:mysqlinconfigconfig.ini --ndb-nodeid=1 --reload –initial

5.启动Data Node A,命令如下:

c:mysqlin dbd.exe --ndb-connectstring=192.168.0.102

6.启动Data Node B,命令如下:

c:mysqlin dbd.exe --ndb-connectstring=192.168.0.102

7.可以打开management client来查看cluster当前的状态

image

8.Data Node均启动后,接下来分别启动两个Sql Node,命令如下:

c:mysqlinmysqld.exe --ndbcluster --ndb-connectstring=192.168.0.102 --console
9. 通过management client查看cluster的当前状态

image

10.至此,cluster已经成功启动。

11.在Sql Node A上创建数据库ClusterSample

image

注:默认root密码为空

12.在Sql Node A上创建数据表Person;

image

13. 通过Sql Node A插入数据;

image

14.在Sql Node B上去查询数据

image

原文地址:https://www.cnblogs.com/Code-life/p/3800823.html