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查看