MySQLCluster是sharednothing分布式架构,ndb存储引擎把数据放置于内存中。可以做到无单点故障。由运行于不同服务器上的的多种进程构成,组件包括SQL节点,NDBD数据节点,管理程序,以及(可能的)数据访问程序表(结构)存在SQL节点中。应用程序通过SQL节点访问这些数据表;NDBD数据节点用于保存数据;集群管理通过管理工具ndb_mgmd管理。
MySQLCluster具有高可用性、高性能和可缩放性的Cluster数据管理。
MySQL集群
1、软件准备
虚拟机搭建:
环境:CentOS6.6 minimal 版本
MySQL Cluster 7.4.4:
下载:http://dev.mysql.com/downloads/cluster/
自行选择 x86-32bit 或者 x86-64bit
我这里是实验是选择 x86-64bit
2、IP 规划
mysql cluster 5个节点,部署在2台机器上:
192.168.1.109 做为 数据节点、SQL节点、管理节点
192.168.1.110 作为 数据节点、SQL节点
3、查看服务器是否安装有mysql(2台服务器都检查)
mysql-libs-5.1.71-1.el6.x86_64
[root@myqsql1 ~]#
[root@mysql1 ~]# useradd -r -g mysql mysql
[root@mysql1 mysql]# yum -y install libaio-dev
# 设置mysql服务为开机自启动
[root@mysql1 mysql]# chkconfig --add mysqld
ndb_mgmd是 mysql cluster管理服务器,ndb_mgm是客户端管理工具
加入以下内容:
[root@mysql1 bin]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.23 ndb-7.4.4
[root@mysql1 bin]#
[root@mysql1 bin]# ./ndbd --initial
2015-03-30 15:31:15 [ndbd] INFO -- Angel connected to '192.168.1.109:1186'
2015-03-30 15:31:15 [ndbd] INFO -- Angel allocated nodeid: 2
[root@mysql1 bin]#
[root@mysql2 bin]# ./ndbd --initial
2015-03-30 15:36:34 [ndbd] INFO -- Angel connected to '192.168.1.109:1186'
2015-03-30 15:36:34 [ndbd] INFO -- Angel allocated nodeid: 3
[root@myqClter2 bin]#
Starting MySQL.......................................... SUCCESS!
[root@mysql1 bin]#
[root@mysql1 bin]# ps -ef | grep mysql
ndb_mgm> show
Connected to Management Server at: 192.168.1.109:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.109 (mysql-5.6.23 ndb-7.4.4, Nodegroup: 0, *)
id=3 @192.168.1.110 (mysql-5.6.23 ndb-7.4.4, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.109 (mysql-5.6.23 ndb-7.4.4)
[mysqld(API)] 2 node(s)
id=4 @192.168.1.109 (mysql-5.6.23 ndb-7.4.4)
id=5 @192.168.1.110 (mysql-5.6.23 ndb-7.4.4)
ndb_mgm>
ndb_mgm> quit
[root@mysql1 bin]#
一是表必须用ENGINE=NDB或ENGINE=NDBCLUSTER选项创建,使用ALTER TABLE选项更改也可以,以使用NDB Cluster存储引擎在 Cluster内复制它们。
二是每个NDB表必须要有一个主键,如果没有,NDB Cluster存储引擎将自动生成隐含主键。
连到sql节点1上,创建ndb引擎数据表t1,插入数据,连到sql节点2上,查看t1表数据,再插入数据,连到sql节点1查看,没问题就OK了。
连接sql节点1,创建下表并插入数据:
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.6.23-ndb-7.4.4-cluster-commercial-advanced MySQL Cluster Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.23-ndb-7.4.4-cluster-commercial-advanced MySQL Cluster Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
Database changed
mysql> select * from t1;
+----+------+----------+--------+
| id | name | password | others |
+----+------+----------+--------+
| 1 | ndb | 123456 | 1 |
| 2 | ndb2 | 123456 | 2 |
| 4 | ndb4 | 123456 | 4 |
| 3 | ndb3 | 123456 | 3 |
+----+------+----------+--------+
4 rows in set (0.00 sec)
mysql> insert into t1 values(5, 'ndb5','123456','5');
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.23-ndb-7.4.4-cluster-commercial-advanced MySQL Cluster Server - Advanced Edition (Commercial)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test;
Database changed
mysql> select * from t1;
+----+------+----------+--------+
| id | name | password | others |
+----+------+----------+--------+
| 3 | ndb3 | 123456 | 3 |
| 5 | ndb5 | 123456 | 5 |
| 1 | ndb | 123456 | 1 |
| 2 | ndb2 | 123456 | 2 |
| 4 | ndb4 | 123456 | 4 |
+----+------+----------+--------+
5 rows in set (0.00 sec)
[root@mysql1 ~]# ndb_mgm -e shutdown
Connected to Management Server at: 192.168.55.15:1186
3 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
[root@mysql1 ~]#
[root@mysql1 ~]# service mysql stop
Shutting down MySQL..... SUCCESS!
[root@mysql1 ~]#
[root@mysql2 ~]# service mysql stop
Shutting down MySQL..... SUCCESS!
这东西用着如何就根据实际场景测吧,其相关的bug可以到http://bugs.mysql.com/search.php查看