Installation Requirements
Installation Environment: CentOS-6.3
Installation method: Source code compiled and installed
Software Name: mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz
: http://mysql.mirror.kangaroot.net/Downloads/
Software Installation Location:/usr/local/mysql
Data storage location:/var/mysql/data
Log storage location:/var/mysql/logs
Cluster design
First of all, the design of the cluster installation allocation, I need 5 servers, the server allocation is as follows:
Management node: 192.168.15.231
SQL Node 1:192.168.15.232
SQL Node 2:192.168.15.233
Data node 1:192.168.15.234
Data node 2:192.168.15.235
The device is connected as shown in the following way:
Note: at present, the problem with this design is that the management node is a single point, 231 hangs off after the entire cluster will be paralyzed, regardless of this problem, first of all, this simple MySQL cluster first build up.
Check the installed MySQL
Check the MySQL information that is already installed in the system, and do the following:
[Email protected]/]# Rpm-qa | grep MySQL [[Email protected]/]# service MySQL status |
If you have installed a different version of MySQL, please uninstall the following:
[[email protected]/]#/etc/init.d/mysqld stop//Turn off the current MySQL service [Email protected]/]# Ps-ef | grep mysql//check if MySQL is off #如果没关闭, execute the kill-9 port number #执行删除 Rpm-e--allmatches--nodeps MySQL mysql-server Rm-rf/var/lib/mysql//Remove MySQL installation directory |
Management node Management node installation
Install the Management node (192.168.15.231)
[[email protected]/]# Groupadd MySQL [[email protected]/]# useradd mysql-g MySQL [Email protected]/]# cd/usr/local [Email protected] local]# tar-zxv-f mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz [[Email protected] local]# mv mysql-cluster-gpl-7.2.6-linux2.6-x86_64 MySQL [[email protected] local]# chown-r mysql:mysql MySQL [[Email protected] local]# CD MySQL [Email protected] mysql]# scripts/mysql_install_db--user=mysql |
Manage node Configuration
[Email protected] ~]# Mkdir/var/lib/mysql-cluster [Email protected] ~]# Cd/var/lib/mysql-cluster [Email protected] mysql-cluster]# VI +/var/lib/mysql-cluster/config.ini |
In Config.ini, add the following:
[NDBD DEFAULT] Noofreplicas=1 [TCP DEFAULT] portnumber=3306[NDB_MGMD] #设置管理节点服务器 hostname=192.168.15.231 Datadir=/var/mysql/data [NDBD] #设置存储节点服务器 (NDB node) hostname=192.168.15.234 Datadir=/var/mysql/data [NDBD] #第二个NDB节点 hostname=192.168.15.235 Datadir=/var/mysql/data [MYSQLD] #设置SQL节点服务器 hostname=192.168.15.232 [MYSQLD] #第二个SQL节点 hostname=192.168.15.233 |
Management node Startup
[Email protected] ~]#/usr/local/mysql/bin/ndb_mgmd-f/var/lib/mysql-cluster/config.ini [Email protected] ~]# Mkdir/var/mysql/logs [Email protected] ~]# NETSTAT-LNTPU |
See TCP 0 0 0.0.0.0:1186 open Instructions start normal
Open port 1186 on the Management node server
Management node Inspection
Perform the following actions:
[[email protected]/]# NDB_MGM//admin node --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.15.234) Id=3 (not connected, accepting connect from 192.168.15.235) [NDB_MGMD (MGM)] 1 node (s) Id=1 @192.168.15.231 (mysql-5.5.22 ndb-7.2.6) [Mysqld (API)] 2 node (s) Id=4 (not connected, accepting connect from 192.168.15.232) Id=5 (not connected, accepting connect from 192.168.15.233) |
Management node shutdown
[Email protected]/]#/USR/LOCAL/MYSQL/BIN/NDB_MGM-E shutdown #成功后终端打印出以下信息 Connected to Management Server at:192.168.15.236:1186 3 NDB Cluster node (s) has shutdown. Disconnecting to allow Management Server to shutdown. |
Data node Data node installation
Data node 1:192.168.15.234
Data node 2:192.168.15.235
[[email protected]/]# Groupadd MySQL [[email protected]/]# useradd mysql-g MySQL [Email protected]/]# cd/usr/local [Email protected] local]# tar-zxv-f mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz [[Email protected] local]# mv mysql-cluster-gpl-7.2.6-linux2.6-x86_64 MySQL [[email protected] local]# chown-r mysql:mysql MySQL [[Email protected] local]# CD MySQL [Email protected] mysql]# scripts/mysql_install_db--user=mysql [email protected] mysql]# CP support-files/my-medium.cnf/etc/my.cnf [email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld |
Data node Configuration
Configure the data node to perform the following actions:
[Email protected] mysql]# Mkdir/var/mysql/data [Email protected] mysql]# Mkdir/var/mysql/logs [Email protected] mysql]# VI/ETC/MY.CNF |
Append the following to the file:
[MYSQLD] Ndbcluster ndb-connectstring=192.168.15.231 [Mysql_cluster] ndb-connectstring=192.168.15.231 [NDB_MGM] connect-string=192.168.15.231 |
Data node Startup
When you start here, the Management node server firewall must have the 1186,3306 port turned on.
Note: only the –initial parameter is added when the NDBD is restarted on the first boot or after a backup/restore or configuration change!
The first boot is as follows:
[Email protected] mysql]#/USR/LOCAL/MYSQL/BIN/NDBD--initial 2013-01-30 13:43:53 [NDBD] INFO--Angel connected to ' 192.168.15.231:1186 ' 2013-01-30 13:43:53 [NDBD] INFO--Angel allocated Nodeid:2 |
Normal Start Mode:
[Email protected] mysql]#/USR/LOCAL/MYSQL/BIN/NDBD |
Data node shutdown
[[email protected]/]#/etc/rc.d/init.d/mysqld stop
Or
[[email protected] mysql]#/etc/init.d/mysql stop
Shutting down MySQL. success!
/usr/local/mysql/bin/mysqladmin-uroot shutdown
SQL node installation SQL node installation
The SQL node and the storage node (NDB node) are installed the same, performing the following actions;
SQL Node 1:192.168.15.232
SQL Node 2:192.168.15.233
[[email protected]/]# Groupadd MySQL [[email protected]/]# useradd mysql-g MySQL [Email protected]/]# cd/usr/local [Email protected] local]# tar-zxv-f mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz [[Email protected] local]# mv mysql-cluster-gpl-7.2.6-linux2.6-x86_64 MySQL [[email protected] local]# chown-r mysql:mysql MySQL [[Email protected] local]# CD MySQL [Email protected] mysql]# scripts/mysql_install_db--user=mysql [email protected] mysql]# CP support-files/my-medium.cnf/etc/my.cnf [email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld |
SQL Node Configuration
Perform the following actions:
[[email protected] mysql]# mkdir/var/mysql/data//Create a folder to store data [[email protected] mysql]# mkdir/var/mysql/logs//Create a folder for storing logs [[email protected] mysql]# VI/USR/LOCAL/MYSQL/MY.CNF//Modify configuration file |
Append the following content:
[MYSQLD] Ndbcluster ndb-connectstring=192.168.15.231 [Mysql_cluster] ndb-connectstring=192.168.15.231 [NDB_MGM] connect-string=192.168.15.231 |
SQL Node Startup
Perform the following actions:
[[Email protected] mysql]# service mysqld start Starting MySQL. success! |
SQL node shutdown
The most direct way:
[Email protected] mysql]#/usr/local/mysql/bin/mysqladmin-uroot shutdown |
[[email protected]/]#/etc/rc.d/init.d/mysqld stop
Or
[[email protected] mysql]#/etc/init.d/mysql stop
Shutting down MySQL. success!
Functional Testing
View service status on the Management node (192.168.15.231)
[Email protected] ~]#/USR/LOCAL/MYSQL/BIN/NDB_MGM --NDB Cluster--Management Client-- Ndb_mgm> Show Cluster Configuration --------------------- [NDBD (NDB)] 2 node (s) id=2 @192.168.15.234 (mysql-5.5.22 ndb-7.2.6, nodegroup:0, Master) Id=3 @192.168.15.235 (mysql-5.5.22 ndb-7.2.6, nodegroup:1) [NDB_MGMD (MGM)] 1 node (s) Id=1 @192.168.15.231 (mysql-5.5.22 ndb-7.2.6) [Mysqld (API)] 2 node (s) Id=4 @192.168.15.232 (mysql-5.5.22 ndb-7.2.6) Id=5 @192.168.15.233 (mysql-5.5.22 ndb-7.2.6) |
You can see that the data node, the management node, and the SQL node are all normal.
Note :
- When building a table, be sure to use ENGINE=NDB or Engine=ndbcluster to specify that the NDB cluster storage engine be used, or change the table's storage engine with the ALTER TABLE option.
- The NDB table must have a primary key, so you must define a primary key when you create the table, otherwise the NDB storage engine will automatically generate the implied primary key.
- The User Rights table of the SQL node is still saved with the MyISAM storage engine, so the MySQL user created in a SQL node can only access this node, and if you want to access another SQL node with the same user, you need to append the user to the corresponding SQL node. Although the MySQL Cluster7.2 version began to provide "user rights sharing".
Data Synchronization Testing
Create the relevant database on one data node and then go to another data node to see if the data is synchronized.
- Section 1 Step:
Add data on SQL Node 1 (192.168.15.232):
[[email& Nbsp;protected] mysql]# /etc/rc.d/init.d/mysqld status //Check if MySQL runs [[email protected] mysql]#/etc/rc.d/ Init.d/mysqld start //start MySQL [[email protected] mysql]#/usr/local/mysql/bin/mysql-u root-p Enter Password: mysql> show databases; mysql> CREATE DATABASE testdb2; Mysql> use TESTDB2; mysql> CREATE TABLE td_test2 (i INT) engine=ndb; //The engine of the database table must be specified here as Ndbcluster, the same as the name in the configuration file mysql> INSERT into Td_test2 () VALUES (1); Mysql> INSERT into Td_test2 () VALUES (152); mysql> SELECT * from Td_test2; |
- Section 2 Step:
Go to view data on SQL Node 2 (192.168.15.233)
mysql> use TESTDB2; Database changed Mysql> SELECT * from Td_test2; +------+ | I | +------+ | 126 | | 1 | +------+ 2 rows in Set (0.01 sec) |
The engine that looks at the table is not NDB:
>show CREATE TABLE Td_test2; |
- Section 3 Step:
Reverse test, add Data on SQL Node 2 (192.168.15.233):
mysql> CREATE DATABASE BB; mysql> use BB; Mysql> CREATE TABLE td_test3 (i INT) engine=ndb; Mysql> INSERT into Td_test3 () VALUES (98); Mysql> SELECT * from Td_test3; |
View data on SQL Node 1 (192.168.15.232):
mysql> use BB; Database changed Mysql> SELECT * from Td_test3; +------+ | I | +------+ | 98 | +------+ 1 row in Set (0.00 sec) |
Shutting down the cluster
Close the Management node first, and then close SQL nodes and data nodes.
Cluster start operation sequence
To start the cluster again, execute in the following order:
Management Node - Data Node –> SQL node Note: do not add the "–initial" parameter when starting the data node.
Errors in installation and error startup in the test
Error message:
Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (2)
Solutions 1 (port occupancy) NETSTAT-ANP |grep 3306
Kill-9 Process Number
Solutions 1 (Permissions issues) [[email protected] mysql]# chown-r mysql:mysql/var/mysql//Modify access permissions for custom folders
CentOS-6.3 Installing the MySQL Cluster