2. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
3. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
7. Connectors
C, JDBC, ODBC, .NET, PHP …etc
Per-Thread buffer
- sort_buffer_size
- read_buffer_size
- join_buffer_size
- tmp_table_size
Privileges Cache
MySQL Server
Thread Cache
Holds pre-allocated threads for quick re-use
Query Cache
Holds query results as preformatted network packets
Parser
MyISAM Key Cache
Holds MyISAM
index data in
memory for reuse
InnoDB Buffer Cache
Holds InnoDB data and
index pages within
memory for reuse
Table Cache File
descriptor (MyISAM)
Session Level,即每個
線程都會分配一次
Global Level,即開機時只
會分配一次,全域共用
Memory Usage
8. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
10. MySQL HA Overview
Master Slave
AP
R/W R
Active Stand by
AP
R/W
Failover
Master Master
AP
R/W
Master
R/W
R/W
MySQL
HA
讀寫
分流
主備
架構
多主
架構
MySQL
Cluster
AP
R/W
Data Node
SQL Node
Data Node
SQL Node
R/W
15. 多主
架構
群組
複製
多源
複製
Master Master
AP
R/W
Master
R/W
R/W
DB_1 /
Master
DB_2 /
Master
AP
R/W
DB_3 /
Master
R/
W
R/W
Slave
Replication
Read
類似方案:
• MySQL Group Replication
• Galera Cluster For MySQL
• Percona Xtradb Cluster
+Servers ≠+Speed
Have to waiting for
other servers commit
均為獨立資料庫
最後統一複製到
單一資料庫中
16. M
M M
S1 S2 S3 S4 S...
HA M
M M
S1 S2 S3 S4 S...
HA
MySQL connector
Applications
MySQL Router
MySQL connector
Applications
MySQL Router
MySQL
Shell
MySQL
InnoDB
Cluster
19. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDBCluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
24. NDB Terminology
» Node: A component of NDB Cluster
» Local Checkpoint(LCP)
⋄ Specific to a single node
⋄ Saving all of a node's data to disk
⋄ Usually occurs every fewminutes
» Global Checkpoint(GCP)
⋄ Occurs every fewseconds
⋄ When transactions for all nodes are synchronized
⋄ The REDOlog is flushed to disk
» Fragment
⋄ Contains a portion of a database table
⋄ Also called a partition
» Replica: Fragment's replicas in order to provide redundancy
User Manual: https://dev.mysql.com/doc/ndbapi/en/overview-terminology.html
25. NDB Terminology
SQL Node SQL Node SQL Node
NDB
NDB
NDB
NDB
1.Write to SQL Node
2.Insert into Data Node
3.SYNC5.GCP
6. Redo Log
4.ACK
Flush
7.GCP
8. Fragment
Write
Default Replica is 2
Sync 2 Data Nodes
26. »Management node
⋄To manage the other nodes
⋄Providing configuration data
⋄Performing starting and stopping nodes
⋄Running backups
⋄Arbitrator
NDB
Management
Server
ndb_mgmd
NDB
Management
Client
ndb_mgm
MySQL Cluster Components
27. »Management node Client
⋄Connect to the management server
⋄Provide commands:
⋄Start and stop nodes
⋄Showing node versions and status
⋄Starting and stopping backups
NDB
Management
Server
ndb_mgmd
NDB
Management
Client
ndb_mgm
MySQL Cluster Components
28. »Data node
⋄Stores cluster data
⋄Located on a separate computer
⋄Stored completely in memory
⋄There are as many data nodes as there are
replicas, times the number of fragments
MySQL Cluster Components
29. »SQL node
⋄Accesses the cluster data
⋄A traditional MySQL server
⋄Uses the NDBCLUSTER storage engine
⋄Just a specialized type of API node
⋄Standard MySQL Client
⋄ndb_restore
⋄NDB API:C++API, ClusterJ API...etc
MySQL Cluster Components
NDB API
NoSQL
Interface
30. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
32. Types of installation
» MySQL Cluster Auto-Installer
» Traditionway
» MySQL Cluster Manager(MCM)
33. Supported Platforms
Operating System Architecture 7.5 7.4
Red Hat / Oracle Linux 7 x86_64 V V
Red Hat / Oracle Linux 6 x86_32, x86_64 V V
Red Hat / Oracle Linux 5 x86_32, x86_64 V X
Ubuntu 16.04 LTS x86_32, x86_64 V X
Ubuntu 14.04 LTS x86_32, x86_64 V X
SUSE Enterprise Linux 12 x86_64 V V
SUSE Enterprise Linux 11 (11.4+) x86_64 X V
Debian GNU/Linux 8 x86_32, x86_64 V X
Microsoft Windows 2012 Server (incl R2) x86_64 V X
Microsoft Windows 2008 Server (incl R2) x86_64 X V
57. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDBCluster
» NDB Cluster programs
» Management of NDB Cluster
» NDB Cluster replication
62. »Node Group
⋄Consists of one or more nodes, and stores
partitions, or sets of replicas
⋄Number of Redundancy:
[# of node groups] =[# of data nodes] / NoOfReplicas
»Replica
⋄copy of a cluster partition
Defining Data Node
Node Group 0
Node Group 1
4 Data Nodes:
NoOfReplicas=1
4 node groups
NoOfReplicas=2
2 node groups
NoOfReplicas=4
1 node group
67. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDBCluster programs
» Management of NDB Cluster
» NDB Cluster replication
73. For Table used
» ndb_delete_all - Delete All Rows from an NDB Table
» ndb_desc - Describe NDB Tables
» ndb_drop_index - Drop Index from an NDB Table
» ndb_drop_table - Drop an NDB Table
» ndb_index_stat - NDB Index Statistics Utility
» ndb_move_data - NDB Data Copy Utility
» ndb_select_all - Print Rows from an NDB Table
» ndb_select_count - Print RowCounts for NDB Tables
» ndb_show_tables - Display List of NDB Tables
74. ndb_error_reporter
/opt/ndb-7.5.7/bin/ndb_error_reporter ./config.ini
2017-12-05 23:49:51 [ndb_config] WARNING -- at line 337: Cluster
configuration warning:
arbitrator with id 1 and db node with id 7 on same host 192.168.101.75
Running arbitrator on the same host as a database node may
cause complete cluster shutdown in case of host failure.
root@192.168.101.75's password:
ndb_1_cluster.log 100% 419KB 5.5MB/s 00:00
ndb_1_out.err 100% 0 0.0KB/s 00:00
ndb_1_out.log 100% 421KB 14.2MB/s 00:00
2017-12-05 23:57:44 [ndb_config] WARNING -- at line 337: Cluster
configuration warning:
.....
Copying configuration file...
/opt/mcm-1.4.4/clusters/mycluster/1/cfg/config.ini
Please attach ndb_error_report_20171205235655.tar.bz2 to your error report
75. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDBCluster
» NDB Cluster replication
77. SQL Node SQL Node SQL Node SQL Node
NDB
NDB
NDB
NDB
NDB
Management
Server
ndb_mgmd
NDB
Management
Client
Ndb_mgm
Start in order
78. Start types
» Initial start
⋄ The cluster starts with a clean file system on all data nodes
» System restart
⋄ This occurs when the cluster has been shut down
» Node restart
⋄ This is the online restart of a cluster node
» Initial node restart
⋄ The node is reinitialized and started with a clean file system
80. Start phases
» Setup and initialization (phase -1)
1. Obtain a node ID
2. Fetch configuration data
3. Allocate ports to be used for inter-node communications
4. Allocate memory according to settings obtained from the
configuration file
81. Start phases
» Phase 0
⋄ The NDBFS and NDBCNTR blocks start
⋄ Data node file systems are cleared(With --ininialize)
» Phase 1
⋄ All remaining NDB kernel blocks are started
⋄ Connections are set up
⋄ Inter-block communications are established
⋄ Heartbeats are started
⋄ API node connections are also checked(Node restart)
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
82. Hang in Phase 1
» Usually network problems
⋄ Having multiple network interfaces
⋄ Blocking of TCP/IP ports needed
83. Start phases
» Phase 2
⋄ Checks the states of all existing nodes
⋄ The master node is chosen
⋄ The cluster schema file is initialized
» Phase 3
⋄ For initial starts, the log files must be initialized
⋄ Obtains the states of the data nodes
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
84. Start phases
» Phase 4
⋄ For initialize or initialize restart
• The redo log files are created
• The number of these files is equal to NoOfFragmentLogFiles
⋄ For a system restart:
• Read schema or schemas
• Read data from the local checkpoint
• Apply all redo information until the latest restorable global
checkpoint has been reached
⋄ For a node restart, find the tail of the redo log
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
85. Common Errors
» Reconfigure NoOfFragmentLogFiles without --initial-start
» Local checkpoint(LCP) files are broken
» Global checkpoint(GCP) files are broken
» Redo log files are broken
More Details:
https://dev.mysql.com/doc/ndb-internals/en/ndb-internals-start-phases-
system-restart-phase-4.html
86. Start phases
» Phase 5
⋄ For an initial start or system restart
• Local checkpoint(LCP) is executed
• Global checkpoint(GCP) is executed
⋄ Checks of memory usage
⋄ Any required node takeovers are performed
» Phase 6
⋄ Node groups are defined and set up
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
87. Start phases
» Phase 7
⋄ The arbitrator node is selected and begins to function
⋄ The next backup IDis set
⋄ Nodes reaching this start phase are marked as Started
⋄ It is nowpossible SQL nodes to connect to the cluster
» Phase 8
⋄ If this is a system restart, all indexes are rebuilt
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
88. Start phases
» Phase 9
⋄ The node internal startup variables are reset
» Phase 100
⋄ During a node restart or initial node restart, SQL nodes could
connect to the node and begin to receive events
» Phase 101
⋄ The SUMA handover phase
⋄ GCP is negotiated and used as a point of reference for changing
the source of event
User Manual: https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-start-phases.html
89. Data node log files
nodeid
ndb_node_id_out.log
ndb_node_id.pid
data-nodeid.dat undo-nodeid.dat
ndb_nodeid_fs
1 2
LCP
DBDICT D8
D1
D9
D10 D11DBDI
Define as datadir
in config.ini
Define as FileSystemPath in config.ini
Data dictionary,
GCI, Redo Log
94. Agenda
» Basics concepts of MySQL
» About MySQL HA
» MySQL NDB Cluster overview
» Installation
» Configuration of NDB Cluster
» NDB Cluster programs
» Management of NDB Cluster
» NDBCluster replication
98. # In Master Server
shell> mysql -u<user> -p<pwd>
mysql> create user 'repl'@'172.16.0.%';
Query OK, 0 rows affected (0.01 sec)
mysql> set password for 'repl'@'172.16.0.%'=password('repl');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'172.16.0.%';
Query OK, 0 rows affected (0.00 sec)
99. # In Slave Server
shell> mysql -u<user> -p<pwd>
mysql> use mysql;
mysql> CREATE TABLE `mysql`.`ndb_apply_status` (
`server_id` int(10) unsigned NOT NULL,
`epoch` bigint(20) unsigned NOT NULL,
`log_name` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin
NOT NULL,
`start_pos` bigint(20) unsigned NOT NULL,
`end_pos` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`server_id`) USING HASH
) ENGINE=innodb;
100. # In Slave Server
shell> mysql -u<user> -p<pwd>
mysql> change master to master_host='192.168.0.4',
master_port=3306, master_log_file='mysql-bin.000001',
master_log_pos=120, master_user='repl', master_password='repl';
mysql> start slave;
mysql> show slave statusG
*************************** 1. row ***************************
...(以上資料略過)...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...(以下資料略過)...
*檢查上面2個參數是否為Yes,若是則代表設定成功