Mysql-Cluster-7.5 builds database cluster

Mysql-Cluster is a cluster tool and cannot achieve load balancing, which is different from oracle's rac. However, mysql-cluster can achieve synchronization between multiple databases. Although master-slave replication can also achieve data synchronization, master-master replication can also achieve simultaneous read and write requirements between two databases, but for systems with a relatively large amount of access, pass It is more appropriate to configure cluster + load balancing.

Today, I came to find a document to test and install mysql-cluster:

Environment Description:

mysql version: 5.7.21

mysql-cluster version: 7.5.6 

The entire framework should include: management nodes, data nodes, and mysql nodes, with their respective functions:

Management node, the mysql-cluster management node is responsible for managing, configuring, and monitoring the entire cluster.

Data nodes use memory to store data, and the data saved in data nodes will be automatically copied and stored to other data nodes.

The mysql node, also called the database node, is the same as the mysql we usually use and is used as a database. Accessed by data nodes.

The IPv4 of each node is as follows:

Management node: 172.17.61.131

Data nodes and mysql nodes: 172.17.61.132, 172.17.61.133


1. Preparation before installation:

Download the mysql-cluster tool:

http://mirrors.sohu.com/mysql/MySQL-Cluster-7.5/

I downloaded mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

Since MySQL has been installed on these machines before, it is necessary to stop the MySQL service first, delete the relevant MySQL data files and original files, and ensure that port 3306 is not occupied, and the IPs of the three machines can communicate with each other.


2. Install the configuration management node

Upload the downloaded package to the server /usr/local

decompress

# tar xvf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

Take out the required documents

# cd mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64

# cp bin/ndb_mgm* /usr/local/bin

# cd /usr/local/bin

# chmod +x ndb_mgm*

Create a new configuration file and initialize the management node

# mkdir /var/lib/mysql-cluster

# ln -s /usr/local/mysql /home/mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64

# vi /var/lib/mysql-cluster/config.ini

[ndbd default]
NoOfReplicas=2
DataMemory=80M #This parameter cannot be too large, otherwise the node will be forced to shut down due to insufficient memory space
IndexMemory=18M

[ndb_mgmd]
HostName=172.17.61.131
DataDir=/var/lib/mysql-cluster

[ndbd]
HostName=172.17.61.132
DataDir=/var/lib/mysql-cluster

[ndbd]
HostName=172.17.61.133
DataDir=/var/lib/mysql-cluster

[mysqld]
[mysqld]

Initialize a management node with a configuration file

# /usr/local/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial

MySQL Cluster Management Server mysql-5.7.21 ndb-7.5.6 appears

Then you can use ndbd to manage it (if the ndbd command does not work, use the ndb_mgm command in the /usr/local/bin directory)

# ndbd

ndb_mgm>show (use the show command to view the management situation, when the data node is configured, we will use this command to view and manage)

So far, the management node configuration is complete, and then configure the data and sql nodes


3. Install and configure data and mysql nodes

The following operations need to be performed on all nodes

Add user group mysql and user msyql

# groupadd mysql

# useradd -g mysql -s /bin/false mysql

Create a new folder and give permissions

# mkdir /var/lib/mysql-cluster

# mkdir /u01/mysql

# chown root:mysql /var/lib/mysql-cluster

#chown mysql:mysql /u01/mysql

Upload the downloaded package to the server /usr/local

decompress

# tar xvf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

Create links for easy access

# ln -s /usr/local/mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64 /usr/local/mysql

Initialize the database

/usr/loca/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/u01/mysql  

/usr/loca/mysql/bin/mysql_ssl_rsa_setup --datadir=/u01/mysql  

Configure autostart

# cp support-files/mysql.server /etc/rc.d/init.d/mysql

Modify the datadir and basedir of etc/rc.d/init.d/mysql

# chmod +x /etc/rc.d/init.d/mysql

# chkconfig --add mysql

Configure data nodes

# vi /etc/my.cnf

Add the following parts:

 
 

[mysqld]

ndbcluster

ndb-connectstring=172.17.61.131 [mysql_cluster] ndb-connectstring=172.17.61.131

Start the database:

service mysql start

初次登入需要修改密码,这个和普通安装mysql一样

启动ndbd

/etc/init.d/ndbd --initial

如果上述不行使用绝对路径的这个:# /usr/local/mysql/bin/ndbd --initial如果出现下述现象就成功了

2018-05-09 14:14:24 [ndbd] INFO     -- Angel connected to '172.17.61.131:1186'
2018-05-09 14:14:24 [ndbd] INFO     -- Angel allocated nodeid: 2


4.最后当所有的节点配置完成,回到管理节点,使用上述说过的show查看,如下的类似显示,证明已经连接完成
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @172.17.61.132  (mysql-5.7.18 ndb-7.5.6, Nodegroup: 0, *)
id=3    @172.17.61.133  (mysql-5.7.18 ndb-7.5.6, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.17.61.131  (mysql-5.7.18 ndb-7.5.6)

[mysqld(API)]   2 node(s)
id=4    @172.17.61.132  (mysql-5.7.18 ndb-7.5.6)
id=5    @172.17.61.133  (mysql-5.7.18 ndb-7.5.6)

5.测试是否能够同步数据 :

创建表时必须使用ndbcluster引擎,否则无法同步数据

node1:

mysql> use l5m
Database changed
mysql> create table student(age int) engine=ndbcluster;
Query OK, 0 rows affected (0.51 sec)

mysql> insert into student values(11);
Query OK, 1 row affected (0.07 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

node2:

mysql>  select * from student;
+------+
| age  |
+------+
|   11 |
+------+
1 row in set (0.00 sec)

6. Startup and Shutdown Sequence

Start the mysql cluster. The startup sequence is: management node → data node → SQL node.

The startup commands are all there, just delete --initial

When closing, only the management node needs to be closed, and the subsequent data nodes will be closed at the same time, and mysql is the same as the original.

Management node shutdown command: ndb_mgm -e shutdown

(After the execution is completed, the management node will be closed, and the data node will also be closed, but the SQL node will not, that is, the database service needs to be manually stopped on each server to ensure data synchronization)


refer to:

http://www.cnblogs.com/linkstar/p/6510713.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326688201&siteId=291194637