Mysql-cluster free Compilation package Download: https://dev.mysql.com/downloads/file/?id=469881
wget https://cdn.mysql.com//Downloads/MySQL-Cluster-7.5/mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz
Extract:
# tar XVF mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz
# MV XVF Mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64/soft/mysql
Authorization to Mysql-cluster Directory
#useradd-S Mysql/sbin/nologin
# Mkdir/soft/mysql/data
# Chown-r mysql:mysql/soft/mysql/*
# chmod +x/soft/mysql/bin/ndb_mem*
# cd/soft/mysql/
# ln-s/SOFT/MYSQL/BIN/NDB_MGMD/SBIN/NDB_MGMD #方便在shell直接调用ndb_mgmd命令
# ln-s/SOFT/MYSQL/BIN/NDB_MGM/SBIN/NDB_MGM #方便在shell直接调用ndb_mgm命令
Create a Config.ini file
# vim Config.ini #内容如下, be sure to pay attention to the format. Copy from Windows, remember to use UFT8 encoding.
[NDBD DEFAULT]
noofreplicas=2 #每个数据节点的镜像数量
datamemory=500m #每个数据节点中给数据分配的内存
indexmemory=300m #每个数据节点中给索引分配的内存
[NDB_MGMD] #配置管理节点, [] cannot have spaces behind, and cannot have comments
hostname=192.168.240.130
Datadir=/soft/mysql/data #管理节点数据 (log) directory
[NDBD] #数据节点配置, [] cannot have spaces behind, and cannot have comments
hostname=192.168.240.129
Datadir=/soft/mysql/data
[NDBD]
hostname=192.168.240.127
Datadir=/soft/mysql/data
[MYSQLD] #SQL节点目录, [] cannot have spaces behind, and cannot have comments
hostname=192.168.240.129
[MYSQLD]
hostname=192.168.240.128
--------------------------------------------------------------------------------------------------------------- ----
[Email protected] mysql]#/bin/ndb_mgmd-f config.ini #启动服务
MySQL Cluster Management Server mysql-5.7.18 ndb-7.5.6 #启动成功
[[email protected] mysql]#./BIN/NDB_MGM #进入管理程序, you can see that the configuration file is in effect, but because MySQL is not configured on the node, the connection is not shown here
--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.240.129)
Id=3 (not connected, accepting connect from 192.168.240.127)
[NDB_MGMD (MGM)] 1 node (s)
Id=1@192.168.240.130 (mysql-5.7.18 ndb-7.5.6)
[Mysqld (API)] 2 node (s)
Id=4 (not connected, accepting connect from 192.168.240.129)
Id=5 (not connected, accepting connect from 192.168.240.128)
--------------------------------------------------------------------------------------------------------------- ----------------
Configuration node: 192.168.240.128/192.168.240.129
[[Email protected]]# useradd-s/sbin/nologin MySQL
[[Email protected]]# mkdir/soft/mysql
[Email protected]]# tar XF mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz
[[Email protected]]# mkdir/soft/mysql/data
[Email protected]]# chown-r Mysql:mysql/soft/mysql
[[Email protected]]# cd/soft/mysql
[email protected] mysql]# Yum install-y libaio*
Vim Support-files/mysql.server #修改服务文件
Basedir=/soft/mysql
Datadir=/soft/mysql/data
[Email protected] mysql]# bin/mysqld--initialize--user=mysql--basedir=/soft/mysql--datadir=/soft/mysql/data
./bin/mysqld--initialize--user=mysql--datadir=/soft/mysql/data--note the automatically generated temporary password
[Note] A temporary password is generated for [email protected]: PBYJ>RZ95OHV
--------------------------------------------------------------------------------------------------------------- -------------------
Change Password First:
[[email protected] mysql]# bin/mysql-u root-p 'pbyj>rz95ohv'--log in to MySQL, with special symbols, to ' surround ', to step in the pits here
mysql> use MySQL; --You must change the password before you can manipulate it
ERROR 1820 (HY000): Must reset your password using ALTER USER statement before executing this statement.
mysql> alter user ' root ' @ ' localhost ' identified by ' 123456 ';
Query OK, 0 rows Affected (0.00 sec)
[[Email protected]]# vim/etc/my.cnf
[Mysqld]
Datadir=/soft/mysql/data
User=mysql
Ndbcluster
Lc_messages-dir=/soft/mysql/share/
ndb-connectstring=192.168.240.130
[Mysql_cluster]
ndb-connectstring=192.168.240.130
[[Email protected]]# bin/ndbd--initial #第一次使用要初始化数据, you can not add--initial next time, otherwise the database will be emptied
[Email protected]]# ln-s/soft/mysql/bin/sbin/mysql
[Email protected]]# ln-s/soft/mysql/support-files/mysql.server/sbin/mysqld
--------------------------------------------------------------------------------------------------------------- -------------
Back to 130 console:
Ndb_mgm> Show
Cluster Configuration
---------------------
[NDBD (NDB)] 2 node (s)
id=2@192.168.61.128 (mysql-5.7.18 ndb-7.5.6, starting, nodegroup:0)--node ndbd connected
id=3@192.168.61.129 (mysql-5.7.18 ndb-7.5.6, starting, nodegroup:0)--node ndbd connected
[NDB_MGMD (MGM)] 1 node (s)
Id=1@192.168.61.130 (mysql-5.7.18 ndb-7.5.6)
[Mysqld (API)] 2 node (s)
[Mysqld (API)] 2 node (s)
id=4@192.168.61.128 (mysql-5.7.18 ndb-7.5.6) #小心防火墙
id=5@192.168.61.129 (mysql-5.7.18 ndb-7.5.6) #小心防火墙
--------------------------------------------------------------------------------------------------------------- --------------
Test:
Build a library/build a table
Log on to MySQL on 192.168.61.128:
mysql>Create databases ABC CHARSET=GBK;
Query OK, 0 rows affected (0.72 sec)
Mysql>create table name (ID int (5) NOT NULL PRIMARY key Auto_increment,name varchar (TEN) not null) engine=ndb;
Query OK, 0 rows affected (0.72 sec)
Mysql>insert into name values (' Zhang San '), (' John Doe ');
--------------------------------------------------------------------------------------------------------------- --------------
Querying in 192.168.240.128/192.168.240.129
Mysql>select * from Tp.name;
+----+---------+
| ID | name |
+----+----------+
| 1 | Zhang San |
| 2 | John Doe |
+----+---------+
--------------------------------------------------------------------------------------------------------------- --------------
Failure of one of the analog 192.168.240.128/192.168.240.129 failures, then query
Mysql>select * from Tp.name;
+----+---------+
| ID | name |
+----+----------+
| 1 | Zhang San |
| 2 | John Doe |
+----+---------+
Mysql>insert into name values (' Changjiang '), (' Yellow River ');
Query OK, 0 rows affected (0.72 sec)
Mysql> SELECT * FROM Tp.name Group by ID;
+----+--------+
| ID | name |
+----+--------+
| 1 | Changjiang River |
| 2 | Yellow River |
| 3 | Zhang San |
| 4 | John Doe |
+----+--------+
4 rows in Set (0.01 sec)
After the test summary several points:
When the cluster hangs, two data node MySQL can not access the database;
When the cluster hangs, two MySQL still can work normally, update data also will synchronize, but cannot restart MySQL service;
2. As long as the two MySQL service is not at the same time, the data is still safe.
3. When the cluster hangs, Node A hangs up, then updates the data to Node B, and cluster and Node a resume on-line, resulting in inconsistent data for Node A and Node B.
4. When two MySQL data is inconsistent, start the cluster, then start the Data node and SQL node of the update, ensure that the cluster is successfully connected, and then start another node, and the last node will update the latest data automatically. !! Boot order is important!!!
--------------------------------------------------------------------------------------------------------------- --------------
Boot order:
Management node NDB_MEGD, data node NDBD-SQL node Specify a private mysqld for Ndbcluster parameters
Ndb_mgmd-f Config.ini, NDBD, mysqld start
Close order:
The SQL node specifies the Ndbcluster parameter of the dedicated MYSQLD, management node Ndb_mem
Mysqld stop--ndb_mgm-e shutdown---finish
Report:
1. mysqld--initialize-insecure automatically generate root user without password, mysqld--initialize automatically generate root user with random password
2. Use the MySQL account settings, you need to append the following information in/etc/security/limits.conf, otherwise you will be prompted Limite limit error:
MySQL hard nofile 65535
3.[error] Can ' t find error-message file '/usr/local/mysql/share/zh-cn/errmsg.sys '. Check error-message file location and ' lc-messages-dir ' configuration directive.
Add lines in MY.CNF:
Lc_messages-dir=/soft/mysql/share/
4. When you start MySQL, you may be prompted: ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/tmp/mysql.sock ' (111)
Ln-s/soft/mysql/mysql.sock/tmp/mysql.sock #要用绝对路径
Mysql-cluster installation Configuration