MySQL-Cluster-7.4 for centos 6.9 64bit

MySQL-Cluster-7.5 for centos 6.9 64bit


一、安裝要求

1、安裝環境:  

系統環境:CentOS release 6.9 64bit  
軟件名稱:MySQL-Cluster-server-gpl-7.4.15-1.el6.x86_64.rpm,MySQL-Cluster-client-gpl-7.4.15-1.el6.x86_64.rpm
軟件安裝位置:/usr/bin/mysql
數據存放位置:/var/lib/mysql
日誌存放位置:/var/log/mysql


二、集羣設計
首先設計集羣的安裝分配方式,共需要5臺服務器,服務器分配如下:

    管理節點:    192.168.99.35
    數據節點1:   192.168.99.36
    數據節點2:   192.168.99.37
    sql節點1:     192.168.99.38
    sql節點2:     192.168.99.39

注意:目前這種設計存在的問題是管理節點是單點的。

三、安裝部署

1、在五臺服務器上/home創建mysql目錄,下載如下兩個軟件包,建議下載後直接scp過去
[root@centos-6 ~]# mkdir /home/mysql
[root@centos-6 ~]# cd /home/mysql/
[root@centos-6 mysql]#wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.4/MySQL-Cluster-server-gpl-7.4.15-1.el6.x86_64.rpm
[root@centos-6 mysql]#wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.4/MySQL-Cluster-client-gpl-7.4.15-1.el6.x86_64.rpm

2、清除五臺服務器上的舊版本mysql
查詢遺留了哪些mysql
rpm -qa | grep mysql
通過yum方式清除mysql
yum -y remove mysql*
查詢清除是否完成
rpm -qa | grep mysql

3、在五臺服務器上安裝MySQL-Cluster-server-gpl-7.4.15-1.el6.x86_64及MySQL-Cluster-client-gpl-7.4.15-1.el6.x86_64
yum -y install MySQL-Cluster-server-gpl-7.4.15-1.el6.x86_64.rpm MySQL-Cluster-client-gpl-7.4.15-1.el6.x86_64.rpm

備註:整個cluster安裝後的初次超級賬戶密碼存在/root/.mysql_secret這個文件當中

4、創建文件夾及進行授權

管理節點創建文件夾並授權
mkdir /var/lib/mysql-cluster  /var/run/mysqld/  
chown mysql.mysql -R /var/lib/mysql-cluster  /var/run/mysqld/

數據節點創建文件夾並授權:
mkdir /var/run/mysqld
chown mysql.mysql -R /var/lib/mysql /var/run/mysqld/    

SQL節點創建文件夾並授權
mkdir /var/run/mysqld
chown mysql.mysql -R /var/lib/mysql /var/run/mysqld/

5、配置管理節點配置文件
vim /var/lib/mysql-cluster/config.ini
[ndbd default]
NoOfReplicas=2                                   #數據寫入數量。2表示兩份
DataMemory=500M                               #配置數據存儲可使用的內存
IndexMemory=100M                              #索引給100M

#manager options:                                    #管理節點
[ndb_mgmd]
id=1
datadir=/var/lib/mysql-cluster                     #管理節點的日誌
HostName=192.168.99.35                           #管理節點的IP地址。本機IP

#data node options:                                    #數據存儲節點
[ndbd]
HostName=192.168.99.36
DataDir=/var/lib/mysql                            #mysql數據存儲路徑
id=2
[ndbd]
HostName=192.168.99.37
DataDir=/var/lib/mysql                            #mysql數據存儲路徑
id=3

#SQLnode options:                              #關於SQL節點
[mysqld]
HostName=192.168.99.38
id=4
[mysqld]
HostName=192.168.99.39
id=5

6、配置數據節點配置文件
vim  /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql                                                  #mysql數據存儲路徑
ndbcluster                                                                  #啓動ndb引擎
ndb-connectstring=192.168.99.35                                  # 管理節點IP地址
[mysqld_safe]  
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.99.35                              #管理節點IP地址

7、配置sql節點配置文件
vim /etc/my.cnf    
[mysqld]
ndbcluster                                                             #啓動ndb引擎
ndb-connectstring=192.168.99.35                              # 管理節點IP地址
[mysqld_safe]   
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]  
ndb-connectstring=192.168.99.35                               #管理節點IP地址

說明:數據節點和SQL結點配置文件區別 ,就多一行
數據結點有:datadir=/var/lib/mysql                   #mysql數據存儲路徑。


四、啓動mysql集羣
初次啓動命令以及用戶密碼更改調整:(請嚴格按照次序啓動)
先啓動:管理結點服務->數據結點服務->sql結點服務
關閉:關閉管理結點服務,關閉管理結點服務後,nbdb數據結點服務會自動關閉->手動把sql結點服務關了。
執行初次啓動前請先確認 將兩臺機器的防火牆關閉(service iptables stop 或者 設定 防火牆端口可通,兩個端口即通訊端口1186、數據端口3306 )

1、在99.35上啓動管理節點
ndb_mgmd -f/var/lib/mysql-cluster/config.ini        # mysql cluster 後臺運行進程
[root@centos-6 mysql-cluster]# ndb_mgmd -f/var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.36 ndb-7.4.15
2017-06-05 20:18:55 [MgmtSrvr] INFO     -- The default config directory '/usr/mysql-cluster' does not exist. Trying to create it...
2017-06-05 20:18:55 [MgmtSrvr] INFO     -- Sucessfully created config directory
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 8: [MGM] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 16: [DB] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 20: [DB] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 25: [API] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 28: [API] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 8: [MGM] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 16: [DB] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 20: [DB] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 25: [API] id is deprecated, use NodeId instead
2017-06-05 20:18:55 [MgmtSrvr] WARNING  -- at line 28: [API] id is deprecated, use NodeId instead
查看啓動是否成功
[root@centos-6 mysql-cluster]# netstat  -antup | grep 1186
tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      5075/ndb_mgmd       
tcp        0      0 127.0.0.1:47322             127.0.0.1:1186              ESTABLISHED 5075/ndb_mgmd       
tcp        0      0 127.0.0.1:1186              127.0.0.1:47322             ESTABLISHED 5075/ndb_mgmd       


2、在99.36及99.37上啓動數據節點,第一次啓動記得帶上初始化參數initial
[root@Centos-6-99 mysql]# ndbd --initial
2017-06-05 20:21:28 [ndbd] INFO     -- Angel connected to '192.168.99.35:1186'
2017-06-05 20:21:28 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@Centos-6-99 mysql]#

[root@Centos-6-99 mysql]# ndbd --initial
2017-06-05 20:21:47 [ndbd] INFO     -- Angel connected to '192.168.99.35:1186'
2017-06-05 20:21:47 [ndbd] INFO     -- Angel allocated nodeid: 3
[root@Centos-6-99 mysql]#

3、在99.38及99.39上啓動sql節點
[root@localhost mysql]# 170605 20:23:23 mysqld_safe Logging to '/var/log/mysqld.log'.
170605 20:23:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@localhost mysql]# 170605 20:23:32 mysqld_safe Logging to '/var/log/mysqld.log'.
170605 20:23:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

4、在99.35上登錄管理節點查看集羣狀態
[root@centos-6 mysql-cluster]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2    @192.168.99.36  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0, *)
id=3    @192.168.99.37  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4    @192.168.99.38  (mysql-5.6.36 ndb-7.4.15)
id=5    @192.168.99.39  (mysql-5.6.36 ndb-7.4.15)

ndb_mgm>

5、在99.38及99.39sql節點添加mysql用戶
[root@localhost mysql]# cat /root/.mysql_secret
# The random password set for the root user at Mon Jun  5 19:55:57 2017 (local time): MsIBXVtxWT4He5JF

[root@localhost mysql]# mysql -u root -pMsIBXVtxWT4He5JF
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36-ndb-7.4.15-cluster-gpl

Copyright (c) 2000, 2017, 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;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set password for 'root'@'localhost'=password('123456');
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@localhost mysql]# mysql -u root -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36-ndb-7.4.15-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2017, 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> grant all privileges on *.* to cluster@"%" identified by "123456";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>

6、外部鏈接99.38sql節點進行創建數據庫及數據表測試
mysql -ucluster -p123456 -h113.106.99.38
mysql> create database db;
mysql> use db;
mysql> create table test(id int) engine=ndb;
mysql> insert into test values(10);
mysql> insert into test values(11);
mysql> select * from test;
+------+
| id   |
+------+
|   11 |
|   10 |
+------+
2 rows in set (0.00 sec)
mysql>

7、外部鏈接登錄99.39進行查看及插入數據測試
mysql -ucluster -p123456 -h113.106.99.39
mysql> show databases;
mysql> use db;
mysql> insert into test values(12);
Query OK, 1 row affected (0.01 sec)
mysql> insert into test values(13);
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+------+
| id   |
+------+
|   10 |
|   12 |
|   13 |
|   11 |
+------+
4 rows in set (0.01 sec)
mysql>

五、關閉mysql集羣
關閉mysql集羣順序: 關閉管理節點服務-》 關閉管理節點時,數據結點服務自動關閉 –》 需要手動關閉SQL結點服務

1、關閉管理節點
ndb_mgm
ndb_mgm> shutdown
Node 2: Cluster shutdown initiated
Node 3: Cluster shutdown initiated
Node 2: Node shutdown completed.
Node 3: Node shutdown completed.
3 NDB Cluster node(s) have shutdown.
Disconnecting to allow management server to shutdown.
查看管理節點是否已關閉
[root@centos-6 mysql-cluster]# ps -axu | grep  ndbd   
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      5127  0.0  0.0 103328   876 pts/0    S+   20:44   0:00 grep ndbd
[root@centos-6 mysql-cluster]#

查看數據節點是否關閉
[root@Centos-6-99 mysql]# ps -axu | grep  ndbd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      2243  0.0  0.0 103328   872 pts/0    S+   21:09   0:00 grep ndbd
[root@Centos-6-99 mysql]#

2、手動關閉sql節點
[root@localhost mysql]# mysqladmin -uroot -p123456 shutdown
Warning: Using a password on the command line interface can be insecure.
170605 20:45:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+  Done                    mysqld_safe --defaults-file=/etc/my.cnf

或方法二採用暴力kill方式關閉
ps -axu |grep mysql
kill -9
kill -9
ps -axu |grep mysql

六、再次啓動mysql集羣進行故障切換測試
1、啓動管理節點
[root@centos-6 mysql-cluster]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2 (not connected, accepting connect from 192.168.99.36)
id=3 (not connected, accepting connect from 192.168.99.37)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4 (not connected, accepting connect from 192.168.99.38)
id=5 (not connected, accepting connect from 192.168.99.39)

2、啓動數據節點

[root@Centos-6-99 mysql]# ndbd
2017-06-05 20:47:25 [ndbd] INFO     -- Angel connected to '192.168.99.35:1186'
2017-06-05 20:47:25 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@Centos-6-99 mysql]#

[root@Centos-6-99 mysql]# ndbd
2017-06-05 20:47:28 [ndbd] INFO     -- Angel connected to '192.168.99.35:1186'
2017-06-05 20:47:28 [ndbd] INFO     -- Angel allocated nodeid: 3
[root@Centos-6-99 mysql]#

注意:非初始化啓動記得不要加initial參數

3、啓動sql節點
[root@localhost mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
[1] 2014
[root@localhost mysql]# 170605 20:49:49 mysqld_safe Logging to '/var/log/mysqld.log'.
170605 20:49:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost mysql]#


[root@localhost mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
[1] 1740
[root@localhost mysql]# 170605 20:49:57 mysqld_safe Logging to '/var/log/mysqld.log'.
170605 20:49:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost mysql]#

4、通過外部服務器分別登錄兩臺sql節點進行查詢
[coolner@localhost ~]$ mysql -ucluster -p123456 -h113.106.99.38
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test;
+------+
| id   |
+------+
|   12 |
|   13 |
|   11 |
|   10 |
+------+
4 rows in set (0.00 sec)
mysql>

[coolner@localhost ~]$ mysql -ucluster -p123456 -h113.106.99.39
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id   |
+------+
|   12 |
|   13 |
|   11 |
|   10 |
+------+
4 rows in set (0.00 sec)

mysql>

5、模擬數據節點99.36故障,在管理節點查詢集羣狀態並在兩臺sql節點進行查詢
[root@Centos-6-99 mysql]# ps -aux | grep ndbd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      2141  0.0  0.0  27292  2640 ?        Ss   20:47   0:00 ndbd
root      2142  1.0 27.5 3155544 1082592 ?     Sl   20:47   0:04 ndbd
root      2187  0.0  0.0 103328   876 pts/0    S+   20:54   0:00 grep ndbd
[root@Centos-6-99 mysql]# kill -9 2141
[root@Centos-6-99 mysql]# kill -9 2142

在管理節點查看可以看到99.36這臺數據節點斷開了鏈接
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2 (not connected, accepting connect from 192.168.99.36)
id=3    @192.168.99.37  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0, *)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4    @192.168.99.38  (mysql-5.6.36 ndb-7.4.15)
id=5    @192.168.99.39  (mysql-5.6.36 ndb-7.4.15)

ndb_mgm>

sql節點查詢顯示正常
[coolner@localhost ~]$ mysql -ucluster -p123456 -h113.106.99.38
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id   |
+------+
|   12 |
|   13 |
|   11 |
|   10 |
+------+
4 rows in set (0.00 sec)

[coolner@localhost ~]$ mysql -ucluster -p123456 -h113.106.99.39
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id   |
+------+
|   12 |
|   13 |
|   11 |
|   10 |
+------+
4 rows in set (0.00 sec)

mysql>

6、重新啓動數據節點99.36,並在管理節點查看狀態
[root@Centos-6-99 mysql]# ndbd
2017-06-05 20:58:05 [ndbd] INFO     -- Angel connected to '192.168.99.35:1186'
2017-06-05 20:58:05 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@Centos-6-99 mysql]#

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2    @192.168.99.36  (mysql-5.6.36 ndb-7.4.15, starting, Nodegroup: 0)    #顯示在初始化狀態
id=3    @192.168.99.37  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0, *)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4    @192.168.99.38  (mysql-5.6.36 ndb-7.4.15)
id=5    @192.168.99.39  (mysql-5.6.36 ndb-7.4.15)

已完成初始化的狀態
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2    @192.168.99.36  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0)
id=3    @192.168.99.37  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0, *)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4    @192.168.99.38  (mysql-5.6.36 ndb-7.4.15)
id=5    @192.168.99.39  (mysql-5.6.36 ndb-7.4.15)

ndb_mgm>

7、模擬sql節點99.38故障,在管理節點查詢集羣狀態並在99.39sql節點進行查詢
在99.38關閉sql節點
[root@localhost mysql]# mysqladmin -uroot -p123456 shutdown
Warning: Using a password on the command line interface can be insecure.
170605 21:01:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+  Done                    mysqld_safe --defaults-file=/etc/my.cnf
[root@localhost mysql]#

在管理節點查看集羣狀態,顯示99.38sql節點斷開鏈接
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2    @192.168.99.36  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0)
id=3    @192.168.99.37  (mysql-5.6.36 ndb-7.4.15, Nodegroup: 0, *)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.99.35  (mysql-5.6.36 ndb-7.4.15)

[mysqld(API)]    2 node(s)
id=4 (not connected, accepting connect from 192.168.99.38)
id=5    @192.168.99.39  (mysql-5.6.36 ndb-7.4.15)

ndb_mgm>

遠程登錄99.39節點查詢

[coolner@localhost ~]$ mysql -ucluster -p123456 -h192.168.99.39
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id   |
+------+
|   10 |
|   12 |
|   13 |
|   11 |
+------+
4 rows in set (0.00 sec)

mysql>


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