MySQL Cluster basic deployment tutorial, mysqlcluster
Mysql Cluster Overview
The most significant advantage of MySql Cluster is high availability, high real-time performance, high redundancy, and high scalability.
It allows you to deploy the Cluster of the "in memory" database in a non-shared system. without a shared architecture, the system can use cheap hardware. in addition, since each component has its own memory and disk, there is no single point of failure.
It consists of a group of computers with various processes running on each computer, including mysql servers, NDB cluster data nodes, management service initiation, and specialized data access programs.
All these nodes constitute a complete mysql cluster system. the data is stored in the storage engine of "NDB storage server", and the table (structure) is saved in "mysql Server. the application accesses these data tables through the "mysql Server", and the cluster management server manages the "NDB storage server" through the management tool (ndb_mgmd ".
Basic Concepts
"NDB" is a "in-memory" storage engine with high availability and good data consistency. the following describes the process of a mysql cluster node. A single computer can have any number of nodes.
Management Nodes (MGM): these nodes manage other nodes in the mysql cluster, such as configuration files and cluster logs, start and stop nodes, and run backups. each node in the cluster retrieves configuration data from the Management Server and requests the location of the management server. when a new event occurs in the data node, the node transmits the information about the event to the management server, and then writes the information to the cluster log. Because these nodes are responsible for managing the configurations of other nodes, you should first start these nodes before starting other nodes. The MGM node is started with the command "ndb_mgmd ".
Data nodes (NDB): these nodes are used to save cluster data. the number of data nodes is related to the number of copies, which is a multiple of fragments. suppose there are two copies, each of which has two fragments, then there are four data nodes. however, there is no need to set multiple copies. the data node is started with the "ndbd" command.
SQL node: This is the node used to access cluster data. for MYSQL cluster, the client node is a traditional Mysql server that uses the NDB cluster Storage engine. generally, SQL nodes Add "ndbcluster" to "my. use "mysqld" to start cnf
In addition, there can be any number of cluster client processes or programs. They are divided into two types: Standard mysql client and management client.
Standard mysql client: Access mysql cluster from existing mysql applications written in php, perl, c, c ++, java, python, ruby, etc.
Management clients: these clients are connected to management servers and provide commands such as starting and stopping nodes, starting and stopping message tracing, displaying node versions and statuses, and starting and stopping backups.
The following is the mysql cluster architecture:
Because Mysql Cluster uses TCP/IP connection and data transmission between nodes is not encrypted, it uses a separate subnet.
Next we will deploy
For convenience, I put the management nodes, data nodes, and SQL nodes on one machine.
Management Node 1 10.1.6.205
Data Node 1 10.1.6.203
Data Node 2 10.1.6.205
SQL Node 1 10.1.6.203
SQL Node 2 10.1.6.205
1. Install (7.2.6 is installed here)
Download the mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz Binary Package (including ndb and mysql)
Root@10.1.6.205 :~ # Tar-C/usr/local-xzvf mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gzroot@10.1.6.205:/usr/local # ln-s/usr/local/mysql-cluster-gpl-7.2.8-linux2.6-i686/usr/local/mysqlroot@10.1.6.205: /usr/local # cd mysqlroot@10.1.6.205:/usr/local/mysql # scripts/mysql_install_db -- user = mysqlroot@10.1.6.205:/usr/local/mysql # chown-R mysql: mysql/usr/local/mysql similarly 10.1.6.203
2. Configure SQL nodes and NDB nodes
root@10.1.6.205:/usr/local/mysql# vim /etc/my.cnf [mysqld]basedir=/usr/local/mysql/datadir=/usr/local/mysql/data/user=mysqlport=3306socket=/tmp/mysql.sock ndbclustermax_connect_errors=10000ndb-connectstring=10.1.6.205connect_timeout = 300 [mysql_cluster]ndb-connectstring=10.1.6.205
Similarly, 10.1.6.203
3. Configuration Management Node
Root@10.1.6.205:/usr/local/mysql # vim/opt/cluster/config. ini [ndbd default] NoOfReplicas = 2 DataMemory = 80 M # allocate the memory used by data storage. Each ndb occupies IndexMemory = 18 M # allocate the memory used by index storage. Each ndb occupies [tcp default] portnumber = 2205 # ndb listening port # Set Management node [ndb_mgmd] NodeId = 1 hostname = 10.1.6.205datadir =/opt/cluster # directory for storing logs on MGM # Set storage node NDB1 [ndbd] NodeId = 2 hostname = 10.1.6.203datadir =/usr/local/mysql/data # Set the storage node NDB2 [ndbd] NodeId = 3 hostname = 10.1.6.205datadir =/usr/local/mysql/data # set SQL Node 1 [mysqld] NodeId = 4 hostname = 10.1.6.203 # Set SQL Node 2 [mysqld] NodeId = 5 hostname = 10.1.6.205 [mysqld] # Run any ip connection [mysqld]
4. Start mysql cluster
1) Start the management node server first. 2) Start the NDB storage node server. 3) Start the SQL node server.
1) execute the process of starting the MGM Node
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndb_mgmd -f /opt/cluster/config.iniMySQL Cluster Management Server mysql-5.5.22 ndb-7.2.6
The parameter-f or -- config-file must be used to tell the location of the config. ini file in the ndb_mgm configuration file.
2) on two storage node servers, if the NDB process is started for the first time, you must first execute the following command:
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd --initial2013-08-28 23:40:36 [ndbd] INFO -- Angel connected to '10.1.6.205:1186'2013-08-28 23:40:36 [ndbd] INFO -- Angel allocated nodeid: 2
Note: The-initial parameter is used only when NDB is started for the first time, or when the backup/recovery or configuration file changes and NDB is restarted. this parameter causes the node to delete any files created by an earlier NDB instance for restoration, including log files for restoration.
If it is not the first time, use the following command
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndbd
3) Start the SQL node Server
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqld_safe /etc/my.cnf &
5. view the status of each node
root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showCluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @10.1.6.203 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)id=3 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s)id=1 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6) [mysqld(API)] 4 node(s)id=4 @10.1.6.203 (mysql-5.5.22 ndb-7.2.6)id=5 @10.1.6.205 (mysql-5.5.22 ndb-7.2.6)id=6 (not connected, accepting connect from any host)id=7 (not connected, accepting connect from any host) ndb_mgm>
6. Test
Note: Compared with Mysql that does not use the Cluster, the data operation method in the mysql cluster is not much different.
1) The table must be created using the engine = NDB or engine = NDBCLUSTER option.
2) Each NDB table must have a primary key. If the user does not define the primary key when creating the table, the NDB Cluster Storage engine will automatically generate an implicit primary key.
This implicit key also occupies space, just like any other table index. because there is not enough memory to accommodate these automatically created keys, it is easy to see problems.
Create a table on 203 SQL Node 1
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysql -uroot -pmysql> use test;mysql> create table dave (num int(10)) engine=ndb;mysql> show create table dave\G;*************************** 1. row *************************** Table: daveCreate Table: CREATE TABLE `dave` ( `num` int(10) DEFAULT NULL) ENGINE=ndbcluster DEFAULT CHARSET=latin11 row in set (0.00 sec) mysql> insert into dave -> values -> (100);Query OK, 1 row affected (0.01 sec)mysql> select * from dave;+------+| num |+------+| 100 |+------+
View the table on 205 SQL Node 2
root@10.1.6.205:/usr/local/mysql# /usr/local/mysql/bin/mysql -uroot -pmysql> use testmysql> select * from dave;+------+| num |+------+| 100 |+------+
Test OK
Follow the table
mysql> select * from ndbinfo.memoryusage;+---------+--------------+--------+------------+----------+-------------+| node_id | memory_type | used | used_pages | total | total_pages |+---------+--------------+--------+------------+----------+-------------+| 2 | Data memory | 851968 | 26 | 83886080 | 2560 || 2 | Index memory | 212992 | 26 | 19136512 | 2336 || 3 | Data memory | 851968 | 26 | 83886080 | 2560 || 3 | Index memory | 212992 | 26 | 19136512 | 2336 |
Note: When the usage is full, the access will fail. In this case, you need to adjust the DataMemory and IndexMemory parameters. All configuration files must be adjusted and restarted to take effect.
7. Disable cluster
root@10.1.6.205:/usr/local/mysql/bin# /usr/local/mysql/bin/ndb_mgm -e shutdownConnected to Management Server at: 10.1.6.205:11863 NDB Cluster node(s) have shutdown.Disconnecting to allow management server to shutdown.
Disable the SQL node mysqld service.
root@10.1.6.203:/usr/local/mysql/bin# /usr/local/mysql/bin/mysqladmin -uroot -p shutdownEnter password: 130829 02:19:57 mysqld_safe mysqld from pid file /usr/local/mysql/data//debian.pid ended[1]+ Done /usr/local/mysql/bin/mysqld_safe /etc/my.cnf
The above is the initial deployment of the mysql cluster, and then the haproxy + keepalive dual-host high availability will be written.
Articles you may be interested in:
- How to configure a MySQL Cluster in Windows Server 2003
- Use cluster to expand your Node server to a multi-thread Server
- How to Create a disk table in MySQL Cluster
- How to configure a MySQL Cluster on a win2003 Server