程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> MySQL-Cluster_Red Hat & Oracle Enterprise Linux 5 (x86, 64-bit)_02

MySQL-Cluster_Red Hat & Oracle Enterprise Linux 5 (x86, 64-bit)_02

編輯:關於MYSQL數據庫

在數據節點1上關閉

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)] 2 node(s)

id=2 (not connected, accepting connect from 192.168.0.153)

id=3         @192.168.0.154  (MySQL-5.1.47 ndb-7.1.5, Nodegroup: 0, Master)

[ndb_mgmd(MGM)]       1 node(s)

id=1         @192.168.0.150  (MySQL-5.1.47 ndb-7.1.5)

[MySQLd(API)]        2 node(s)

id=4         @192.168.0.151  (MySQL-5.1.47 ndb-7.1.5)

id=5         @192.168.0.152  (MySQL-5.1.47 ndb-7.1.5)

在任意SQL節點上查詢:

SQL節點1:

MySQL> select * from redhat;

+------+

| id   |

+------+

|    1 |

|    3 |

|    2 |

+------+

3 rows in set (0.00 sec)

SQL節點2上:

MySQL> select * from redhat;

+------+

| id   |

+------+

|    1 |

|    3 |

|    2 |

+------+

3 rows in set (0.01 sec)

6.Cluster 的關閉

6.1在Shell下執行如下命令:

[root@s01 ~]# ndb_mgm -e shutdown

Connected to Management Server at: localhost:1186

2 NDB Cluster node(s) have shutdown.

Disconnecting to allow management server to shutdown.

6.2用ndb_mgm 工具下關閉:

ndb_mgm> shutdown

Node 2: Cluster shutdown initiated

Node 3: Cluster shutdown initiated

Node 3: Node shutdown completed.

Node 2: Node shutdown completed.

2 NDB Cluster node(s) have shutdown.

Disconnecting to allow management server to shutdown.

注:集群關閉後,SQL節點的MySQL服務並沒有停止。

維護Cluster

1.備份

ndb_mgm> start backup;

Waiting for completed, this may take several minutes

Node 2: Backup 1 started from node 1

Node 2: Backup 1 started from node 1 completed

 StartGCP: 535 StopGCP: 538

 #Records: 2053 #LogRecords: 0

 Data: 50312 bytes Log: 0 bytes

在備份日志中,需要注意的是“Backup 1”,它表示該備份的唯一ID,如果做第二次備份,備份ID會變成“Backup 2”。“Backup 1 started from node 1 completed”,表示備份完成。

在數據庫節點上(192.168.0.153)

[root@s04 BACKUP-1]# pwd

/MySQL/BACKUP/BACKUP-1

[root@s04 BACKUP-1]# ll

total 40

-rw-r--r-- 1 root root 25808 Sep 18 22:23 BACKUP-1-0.2.Data

-rw-r--r-- 1 root root  7988 Sep 18 22:23 BACKUP-1.2.ctl

-rw-r--r-- 1 root root    52 Sep 18 22:23 BACKUP-1.2.log

在數據節點上(192.168.0.154):

[root@s05 BACKUP-1]# pwd

/MySQL/BACKUP/BACKUP-1

[root@s05 BACKUP-1]# ll

total 40

-rw-r--r-- 1 root root 24880 Sep 18 22:23 BACKUP-1-0.3.Data

-rw-r--r-- 1 root root  7988 Sep 18 22:23 BACKUP-1.3.ctl

-rw-r--r-- 1 root root    52 Sep 18 22:23 BACKUP-1.3.log

以上兩個數據節點上的數據文件名不一樣,一個包含“.2”,另一個包含“.3”,這個數據表明了此備份哪個數據節點上的數據(192.168.0.153為數據節點2,192.168.0.154為數據節點3)。

  對於大數據量的備份,MySQL Cluster 還提供了幾個備份的參數可供調整,這些參數需要寫在config.ini的[NDBD DEFAULT]或者[NDBD]組中,對各參數的具體說明如下。

@ BackupDataBufferSize:將數據寫入磁盤之前用於對數據進行緩沖處理的內存量。

@ BackupLogBufferSize:將日志記錄寫入磁盤之前用於對其進行緩沖處理的內存量。

@BackupMemory:在數據庫節點中為備份分配的總內存。它應是分配給備份數據緩沖的內存和分配給備份日子緩沖的內存之和。

@BackupWriteSize:每次寫入磁盤的塊大小,適用於備份數據緩沖和備份日志緩沖。

2.恢復:

ndb_mgm> start backup;

Waiting for completed, this may take several minutes

Node 2: Backup 3 started from node 1

Node 2: Backup 3 started from node 1 completed

 StartGCP: 5552 StopGCP: 5555

 #Records: 2060 #LogRecords: 0

 Data: 50904 bytes Log: 0 bytes

SQL節點1上:

MySQL> select * from redhat;

+------+

| id   |

+------+

|    3 |

|    2 |

|    1 |

|    4 |

+------+

4 rows in set (0.00 sec)

MySQL> truncate table redhat;

Query OK, 0 rows affected (0.52 sec)

MySQL> select * from redhat;

Empty set (0.01 sec)

SQL節點2上:

MySQL> select * from redhat;

Empty set (0.00 sec

在數據節點1上:

[root@data1 BACKUP]# ndb_restore -b3 -n 2 -c host=192.168.0.150:1186 -r /MySQL/BACKUP/BACKUP-3/

Backup Id = 3

Nodeid = 2

backup path = /MySQL/BACKUP/BACKUP-3/

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3.2.ctl'

Backup version in files: ndb-6.3.11 ndb version: MySQL-5.1.47 ndb-7.1.5

Stop GCP of Backup: 0

Connected to ndb!!

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3-0.2.Data'

_____________________________________________________

Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/ndb_apply_status(6) fragment 0

_____________________________________________________

Processing data in table: jIEshi/def/redhat(7) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/NDB$BLOB_4_3(5) fragment 0

_____________________________________________________

Processing data in table: sys/def/SYSTAB_0(2) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/ndb_schema(4) fragment 0

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3.2.log'

Restored 2 tuples and 0 log entrIEs

NDBT_ProgramExit: 0 – OK

在數據節點2上:

[root@data2 ~]# ndb_restore -b3 -n 3 -c host=192.168.0.150:1186 -r /MySQL/BACKUP/BACKUP-3/

Backup Id = 3

Nodeid = 3

backup path = /MySQL/BACKUP/BACKUP-3/

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3.3.ctl'

Backup version in files: ndb-6.3.11 ndb version: MySQL-5.1.47 ndb-7.1.5

Stop GCP of Backup: 0

Connected to ndb!!

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3-0.3.Data'

_____________________________________________________

Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/ndb_apply_status(6) fragment 1

_____________________________________________________

Processing data in table: jIEshi/def/redhat(7) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/NDB$BLOB_4_3(5) fragment 1

_____________________________________________________

Processing data in table: sys/def/SYSTAB_0(2) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/ndb_schema(4) fragment 1

Opening file '/MySQL/BACKUP/BACKUP-3/BACKUP-3.3.log'

Restored 2 tuples and 0 log entrIEs

NDBT_ProgramExit: 0 – OK

在SQL節點1上:

MySQL> select * from redhat;

+------+

| id   |

+------+

|    3 |

|    2 |

|    1 |

|    4 |

+------+

4 rows in set (0.00 sec)

在SQL節點2上:

MySQL> select * from redhat;

+------+

| id   |

+------+

|    3 |

|    2 |

|    1 |

|    4 |

+------+

4 rows in set (0.00 sec)

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

ndb_mgm> start backup

Waiting for completed, this may take several minutes

Node 2: Backup 4 started from node 1

Node 2: Backup 4 started from node 1 completed

 StartGCP: 6040 StopGCP: 6043

 #Records: 2060 #LogRecords: 0

 Data: 50896 bytes Log: 0 bytes

在SQL節點1上:

MySQL> drop table redhat;

Query OK, 0 rows affected (0.31 sec)

Empty set (0.00 sec)

MySQL> show tables;

Empty set (0.00 sec)

在SQL節點2上:

MySQL> show tables;

Empty set (0.02 sec)

在數據節點1上:

[root@data1 BACKUP]# ndb_restore -b4 -n 2 -c host=192.168.0.150:1186 -m  -r /MySQL/BACKUP/BACKUP-4/

Backup Id = 4

Nodeid = 2

backup path = /MySQL/BACKUP/BACKUP-4/

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4.2.ctl'

Backup version in files: ndb-6.3.11 ndb version: MySQL-5.1.47 ndb-7.1.5

Stop GCP of Backup: 0

Connected to ndb!!

Successfully restored table `jIEshi/def/redhat`

Successfully restored table event REPL$jIEshi/redhat

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4-0.2.Data'

_____________________________________________________

Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/ndb_apply_status(6) fragment 0

_____________________________________________________

Processing data in table: jIEshi/def/redhat(7) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/NDB$BLOB_4_3(5) fragment 0

_____________________________________________________

Processing data in table: sys/def/SYSTAB_0(2) fragment 0

_____________________________________________________

Processing data in table: MySQL/def/ndb_schema(4) fragment 0

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4.2.log'

Restored 2 tuples and 0 log entrIEs

NDBT_ProgramExit: 0 – OK

在數據節點2上:

[root@data2 ~]# ndb_restore -b4 -n 3 -c host=192.168.0.150:1186 -r /MySQL/BACKUP/BACKUP-4/

Backup Id = 4

Nodeid = 3

backup path = /MySQL/BACKUP/BACKUP-4/

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4.3.ctl'

Backup version in files: ndb-6.3.11 ndb version: MySQL-5.1.47 ndb-7.1.5

Stop GCP of Backup: 0

Connected to ndb!!

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4-0.3.Data'

_____________________________________________________

Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/ndb_apply_status(6) fragment 1

_____________________________________________________

Processing data in table: jIEshi/def/redhat(7) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/NDB$BLOB_4_3(5) fragment 1

_____________________________________________________

Processing data in table: sys/def/SYSTAB_0(2) fragment 1

_____________________________________________________

Processing data in table: MySQL/def/ndb_schema(4) fragment 1

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4.3.log'

Restored 2 tuples and 0 log entrIEs

NDBT_ProgramExit: 0 – OK

在SQL節點1上:

MySQL> show tables;

+------------------+

| Tables_in_jIEshi |

+------------------+

| redhat           |

+------------------+

1 row in set (0.00 sec)

MySQL> select * from redhat;

+------+

| id   |

+------+

|    3 |

|    2 |

|    1 |

|    4 |

+------+

4 rows in set (0.00 sec)

在SQL節點2上:

MySQL> show tables;

+------------------+

| Tables_in_jIEshi |

+------------------+

| redhat           |

+------------------+

1 row in set (0.05 sec)

MySQL> select * from redhat;

+------+

| id   |

+------+

|    3 |

|    2 |

|    1 |

|    4 |

+------+

4 rows in set (0.01 sec)

參數

說明

-b

備份id

-n

節點id

-m

恢復表定義

-r

恢復路徑

-c

Cluster 管理器連接串

如果要恢復表結構:因為是第一個節點恢復,所以需要添加參數-m 來恢復表定義,這樣在其他節點恢復的時候就不需要再加此參數,否則會報如下錯誤:

[root@data2 ~]# ndb_restore -b4 -n 3 -c host=192.168.0.150:1186  -m -r /MySQL/BACKUP/BACKUP-4/

Backup Id = 4

Nodeid = 3

backup path = /MySQL/BACKUP/BACKUP-4/

Opening file '/MySQL/BACKUP/BACKUP-4/BACKUP-4.3.ctl'

Backup version in files: ndb-6.3.11 ndb version: MySQL-5.1.47 ndb-7.1.5

Stop GCP of Backup: 0

Connected to ndb!!

Create table `jIEshi/def/redhat` failed: 721: Schema object with given name already exists

Restore: Failed to restore table: `jIEshi/def/redhat` ... Exiting

NDBT_ProgramExit: 1 – Failed

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved