CentOS6.6 安裝與配置 MySQL Cluster 7.4.4

MySQLClustersharednothing分佈式架構,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臺服務器都檢查)


    [root@mysql1 ~]#  rpm -qa|grep mysql
    mysql-libs-5.1.71-1.el6.x86_64
    [root@myqsql1 ~]#

4、刪除
    [root@mysql1 ~]# yum -y remove mysql-libs-5.1.71-1.el6.x86_64

【開始部署數據節點、SQL節點】
5、創建用戶和組
    [root@mysql1 ~]# groupadd mysql
    [root@mysql1 ~]# useradd -r -g mysql mysql

6、解壓MySQL Cluster(步驟1 已經下載並存放在 home 目錄)
    [root@mysql1 home]tar -zxvf mysql-cluster-advanced-7.4.4-linux-glibc2.5-x86_64.tar.gz

7、把解壓出來的MySQL Cluster放在 /usr/local/mysql 目錄下,修改相關用戶權限
    [root@mysql1 home]#  mv mysql-cluster-advanced-7.4.4-linux-glibc2.5-x86_64 /usr/local/mysql
    [root@mysql1 home]# cd  /usr/local/mysql
    [root@mysql1 mysql]#  chown -R root:mysql .
    [root@mysql1 mysql]#  chown -R mysql data/

8、修改MySQL 配置文件  my.cnf
    (1) 先把 /etc/my.cnf  備份
    [root@mysql1 mysql]#  mv /etc/my.cnf /etc/my.cnf.bak
    (2) 把 supports-file 文件夾下的 my-default.cnf 重命名爲  my.cnf 在[mysqld] 字段添加如下內容:
         basedir = /usr/local/mysql
         datadir = /usr/local/mysql/data
         port = 3306
    (3) 複製到 /etc/目錄下:
        [root@mysql1 mysql]# mv support-files/my.cnf /etc/my.cnf 

9、開始創建MySQL 系統表
    [root@mysql1 mysql]# scripts/mysql_install_db basedir = /usr/local/mysql  datadir = /usr/local/mysql/data  --user=mysql

    [root@mysql1 mysql]# yum -y install libaio-dev

    系統表成功後,添加mysql root 密碼:
         (1)[root@mysql1 mysql]# bin/mysqld_safe &
         (2)mysqladmin -u root -p password 'newpassword'
    
10、配置啓動腳本
    [root@mysql1 mysql]# cp support-files/mysql.server /etc/init.d/mysql
    # 設置mysql服務爲開機自啓動
    [root@mysql1 mysql]# chkconfig --add mysqld

【以上 3-10 步部署數據節點和SQL節點,在另一臺規劃機器做同樣操作】


【部署管理節點】
管理節點只需ndb_mgm和ndb_mgmd兩個文件和一個配置文件,這兩個文件從數據節點上copy就行
ndb_mgmd是 mysql cluster管理服務器,ndb_mgm是客戶端管理工具

11、複製管理節點所需文件
     [root@mysql1 mysql]# cp bin/ndb_mgm* /usr/local/bin

12、配置MySQL服務器成數據節點和SQL節點
    [root@mysql1 mysql]# vi /etc/my.cnf
改爲如下內容:
     basedir = /usr/local/mysql
     datadir = /usr/local/mysql/data
     port = 3306
     ndbcluster
     ndb-connectstring=192.168.1.109
     default-storage-engine=ndbcluster
    # server_id = .....
    # socket = .....
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    [mysql_cluster]
     ndb-connectstring=192.168.1.109

在另一個節點也做同樣配置:
     [root@mysql1 mysql]# scp /etc/my.cnf [email protected]:/etc/
注意:兩臺服務器的配置要一致


13、配置管理節點(192.168.1.109)
    [root@mysql1 mysql]# mkdir /var/lib/mysql-cluster
    [root@mysql1 mysql]# vi /var/lib/mysql-cluster/config.ini
加入以下內容:
    [ndbd default]
    NoOfReplicas=2
    DataMemory=200M
    IndexMemory=20M
    [tcp default]
    portnumber=2202
    [ndb_mgmd]
    #NodeId=1
    hostname=192.168.1.109
    datadir=/var/lib/mysql-cluster/
    [ndbd]
    #NodeId=2
    hostname=192.168.1.109
    datadir=/usr/local/mysql/data/
    [ndbd]
    #NodeId=3
    hostname=192.168.1.110
    datadir=/usr/local/mysql/data/
    [mysqld]
    hostname=192.168.1.109
    [mysqld]
    hostname=192.168.1.110

14、啓動:管理節點--數據節點--SQL節點 
關閉防火牆或者添加端口 1186 允許通過
[root@mysql1 mysql]# service iptables stop (我選擇關閉)

啓動管理節點:
[root@mysql1 mysql]# cd /usr/local/bin
 [root@mysql1 bin]# yum -y install perl perl-devel (預防運行ndb_mgmd 出錯) 
[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]#

啓動sql節點
[root@mysql1 bin]# /etc/init.d/mysql start
Starting MySQL.......................................... SUCCESS! 
[root@mysql1 bin]# 
[root@mysql1 bin]# ps -ef | grep mysql
[root@mysql1 bin]# 


15、客戶端管理使用/usr/local/bin/ndb_mgm
[root@mysql1 bin]# cd /usr/local/bin
[root@mysql1 bin]# 
[root@mysql1 bin]# ndb_mgm
-- NDB Cluster -- Management Client -- 
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]# 

16、測試
使用mysql cluster中需要注意兩點:
    一是表必須用ENGINE=NDB或ENGINE=NDBCLUSTER選項創建,使用ALTER TABLE選項更改也可以,以使用NDB Cluster存儲引擎在 Cluster內複製它們。
    二是每個NDB表必須要有一個主鍵,如果沒有,NDB Cluster存儲引擎將自動生成隱含主鍵。

連到sql節點1上,創建ndb引擎數據表t1,插入數據,連到sql節點2上,查看t1表數據,再插入數據,連到sql節點1查看,沒問題就OK了。

連接sql節點1,創建下表並插入數據:
[root@mysql1 ~]# mysql -h 192.168.1.109 -p test 
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;
+------------------------+
| Database                      |
+------------------------+
| information_schema    |
| mysql                            |
| ndb_2_fs                        |
| ndbinfo                         |
| performance_schema   |
| test                                |
+--------------------------+
6 rows in set (0.00 sec)
mysql>
mysql> use test
Database changed
mysql> create table t1(id int(11) not null auto_increment primary key,name varchar(10),password varchar(20),others varchar(128));
mysql> insert into t1 values(1, 'ndb','123456','1');
mysql> insert into t1 values(2, 'ndb2','123456','2');
mysql> insert into t1 values(3, 'nd3','123456','3');
mysql> insert into t1 values(4, 'ndb4','123456','4');
mysql> select * from t1;
+----+------+----------+--------+
| id | name | password | others |
+----+------+----------+--------+
|  3 | ndb3 | 123456   | 3      |
|  1 | ndb  | 123456   | 1      |
|  2 | ndb2 | 123456   | 2      |
|  4 | ndb4 | 123456   | 4      |
+----+------+----------+--------+
4 rows in set (0.01 sec)
mysql> exit
[root@mysql1 ~]#



連到sql節點2上,查看t1表數據,再插入數據:
[root@mysql2 ~]# mysql -h 192.168.1.110 -p test 
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');
Query OK, 1 row affected (0.00 sec)
mysql> exit
Bye
[root@mysql2 ~]#


連到sql節點1查看,沒問題就OK了。
[root@mysql1 ~]# mysql -h 192.168.1.109 -p test 
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) 

mysql> exit
Bye
[root@mysql1 ~]#


17、關閉
管理節點--數據節點--SQL節點
命令ndb_mgm -e shutdown關閉管理節點和數據節點,sql節點/etc/init.d/mysqld stop關就可以了

[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!



engine=ndbcluster或者engine=ndb的表才能使用Data node所存儲。其他engine即放在SQL node本地,就像單機版一樣。
這東西用着如何就根據實際場景測吧,其相關的bug可以到http://bugs.mysql.com/search.php查看

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章