標籤:資料
Mysql-cluster是具有故障節點恢複正常後的資料自動回復功能的。
實驗環境中包含兩個data節點:分別位於46,47兩台伺服器上
ndb_mgm> show
Connected to Management Server at: localhost:1186
[ndbd(NDB)] 2 node(s)
id=2 @10.186.20.46 (mysql-5.6.25 ndb-7.4.7, Nodegroup: 0)
id=3 @10.186.20.47 (mysql-5.6.25 ndb-7.4.7, Nodegroup: 0, *)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.186.20.45 (mysql-5.6.25 ndb-7.4.7)
[mysqld(API)] 2 node(s)
id=4 @10.186.20.46 (mysql-5.6.25 ndb-7.4.7)
id=5 @10.186.20.47 (mysql-5.6.25 ndb-7.4.7)
ndb_mgm>
此處所說的資料自動修複是指的,在其中一個節點崩潰後,另外一個節點對外提供服務,在崩潰期間所有的資料變動(ndb表),可以在崩潰節點恢複並且假如叢集後,自動同步資料。
實驗過程如下:
1,檢驗當前資料(test.a表為ndb表)
46:
mysql> select * from a;
+——+
| id |
+——+
| 1 |
| 2 |
+——+
2 rows in set (0.00 sec)
47:
mysql> select * from a;
+——+
| id |
+——+
| 1 |
| 2 |
+——+
2 rows in set (0.01 sec)
2,停掉47上的sql,data節點
[[email protected] mysql3307]# ps -ef|grep mysqld
root 2216 2011 0 12:18 pts/0 00:00:00 /bin/sh ./bin/mysqld_safe –defaults-file=./my.cnf
mysql 2385 2216 1 12:18 pts/0 00:01:54 /opt/mysql_s/bin/mysqld –defaults-file=./my.cnf –basedir=/opt/mysql_s/ –datadir=/opt/mysql_s/data –plugin-dir=/opt/mysql_s//lib/plugin –user=mysql –log-error=/opt/mysql_s/data/10-186-20-47.err –pid-file=/opt/mysql_s/data/10-186-20-47.pid –socket=/tmp/mysql3302.sock –port=3302
root 4979 4641 0 12:37 pts/1 00:00:00 /bin/sh ./bin/mysqld_safe –defaults-file=./my.cnf
mysql 5157 4979 0 12:37 pts/1 00:00:12 /usr/local/mysql3307/bin/mysqld –defaults-file=./my.cnf –basedir=/usr/local/mysql3307 –datadir=/usr/local/mysql3307/data –plugin-dir=/usr/local/mysql3307/lib/plugin –user=mysql –log-error=/usr/local/mysql3307/data/10-186-20-47.err –pid-file=/usr/local/mysql3307/data/10-186-20-47.pid –socket=/tmp/mysql3307.sock –port=3307
root 14253 4641 0 14:44 pts/1 00:00:00 grep mysqld
[[email protected] mysql3307]# kill 2385
[[email protected] mysql3307]#
[[email protected] mysql3307]# ps -ef|grep ndb
root 7810 1 0 13:13 ? 00:00:03 ndbd –ndb-connectstring=10.186.20.45:1186
root 7811 7810 1 13:13 ? 00:01:28 ndbd –ndb-connectstring=10.186.20.45:1186
root 14312 4641 0 14:44 pts/1 00:00:00 grep ndb
[[email protected] mysql3307]# kill 7811 7810
[ro[email protected] mysql3307]#
通過管理節點show命令查看是否處於停用狀態
ndb_mgm> show
[ndbd(NDB)] 2 node(s)
id=2 @10.186.20.46 (mysql-5.6.25 ndb-7.4.7, Nodegroup: 0, *)
id=3 (not connected, accepting connect from 10.186.20.47)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.186.20.45 (mysql-5.6.25 ndb-7.4.7)
[mysqld(API)] 2 node(s)
id=4 @10.186.20.46 (mysql-5.6.25 ndb-7.4.7)
id=5 (not connected, accepting connect from 10.186.20.47)
ndb_mgm>
3,在46節點上做插入,刪除操作。
mysql> insert into a select 3;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> delete from a where id=1;
Query OK, 1 row affected (0.02 sec)
mysql>
4,開啟47上的sql,data節點
[[email protected] mysql_s]# ./bin/mysqld_safe –defaults-file=./my.cnf &
[2] 14408
[[email protected] mysql_s]# 150825 14:46:26 mysqld_safe Logging to ‘/opt/mysql_s/data/10-186-20-47.err’.
150825 14:46:26 mysqld_safe Starting mysqld daemon with databases from /opt/mysql_s/data
[[email protected] mysql_s]#
[[email protected] mysql_s]#
[[email protected] mysql_s]# ndb
ndbd ndbmtd
[[email protected] mysql_s]# ndbd –ndb-connectstring=10.186.20.45:1186
2015-08-25 14:46:54 [ndbd] INFO – Angel connected to ‘10.186.20.45:1186’
2015-08-25 14:46:54 [ndbd] INFO – Angel allocated nodeid: 3
[[email protected] mysql_s]#
5,檢驗47上資料是否同步
mysql> select * from a;
+——+
| id |
+——+
| 2 |
| 3 |
+——+
2 rows in set (0.00 sec)
資料已經自動修複。
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
mysql-cluster資料自動修複(節點崩潰期間寫入其他節點資料)