Simple use of Mysql-Cluster-7.5 to build a database cluster, cluster to build

Source: Internet
Author: User

Simple use of Mysql-Cluster-7.5 to build a database cluster, cluster to build

Reading directory

  • Preface
  • Several Concepts in mysql cluster
  • Architecture diagram and description
  • Download mysql cluster
  • Before installing mysql cluster
  • Install the Configuration Management Node
  • Install configuration data and mysql nodes
  • Test
  • Start and close
  • Summary

 

|Preface

 

When your business reaches a certain equivalent, you must have a certain number of databases to load your database requests. I have explained in my previous blog how to achieve load balancing, but another problem is data synchronization, because the premise of Server Load balancer is that the databases on each server are synchronized. When the business volume is small, we will use the master-slave replication method to synchronize server data, one master, multiple slaves, or dual master, but although the read/write splitting is performed, however, there are still a large number of restrictions on reading methods, so the problem of solving data synchronization is the significance of the Database Cluster. I will use the mysql-cluster provided on the mysql official website to implement the cluster. (Install the latest version of the document before it is published, and step on all the pitfalls on the Internet ;)

 

|Several Concepts in mysql cluster

For simplicity, mysql-cluster is mc.

1. mc already contains mysql. The latest mc7.5 I downloaded contains mysql version 5.7. Therefore, you do not need to install the database using the msyql installation package. Note that the version of mysql5.7 is significantly different from the previous version in the command and configuration for installation. Therefore, there are many versions earlier than mc7.5 on the Internet, including different mysql versions, therefore, the installation method is different.

2. manage nodes. mc Management Nodes manage, configure, and monitor the entire cluster.

3. Data nodes use memory to store data. The data stored in the data node is automatically copied and stored to other data nodes.

4. mysql nodes, also known as database nodes, are used as databases in the same way as mysql we usually use. Accessed by data nodes.

 

| Architecture diagram and description

The configuration in my experiment is that because the virtual machine occupies a large amount of memory and only three servers are used, it is best to separate the data node from the mysql node in actual situations. In practice, the Server Load balancer service still needs to be backed up, because in case the Server Load balancer server goes down, all data nodes will not be accessible, so you need to back up the Server Load balancer if necessary, manage nodes and Server Load balancer instances separately. The experiment only implements the entire database cluster. For Server Load balancer, see the previous blog configuration.

 

| Download mysql cluster

Https://cdn.mysql.com//Downloads/MySQL-Cluster-7.5/mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

The download path is mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz.

Note that the 64-bit version is correct.

 

| Before installing mysql cluster

Before installation, if you have installed mysql, You need to delete various mysql files. Before deletion, stop the mysql service. Do not forget to delete my. cnf configuration files. Make sure that the deletion is clean. Otherwise, it may conflict with the subsequent installation. In this case, disable the firewall. In practice, the Firewall opens the corresponding port. Ensure that the server can access each other before and ping the server. A fixed IP address. Ensure that no other program occupies the required port. For example, 3306. These are all confirmed before installation. You need to be familiar with basic linux commands and install the basic mysql version, because I will briefly describe some operations in the subsequent sequence, without too much explanation.

 

| Install the Configuration Management Node

Upload the downloaded package to the server/usr/local.

Extract

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

Retrieve the required file

# Cd mysql-cluster-gpl-7.5.4-linux-glibc2.5-x86_64

# Cp bin/ndb_mgm */usr/local/bin

# Cd/usr/local/bin

# Chmod + x ndb_mgm *

Create a configuration file and initialize the management Node

# Mkdir/var/lib/mysql-cluster

# Mkdir/usr/local/mysql

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

(Enter"IClick "Esc" in the upper left corner of the keyboard to exit editing. Enter ": wq" to save .)

The following is the configuration file, which can be modified according to my changes.

[Ndbd default]
NoOfReplicas = 2
DataMemory = 40960 M
IndexMemory = 512 M


[Ndb_mgmd]
Nodeid = 1
HostName = 10.0.125.87
DataDir =/var/lib/mysql-cluster

[Ndb_mgmd]
Nodeid = 2
HostName = 10.0.125.84
DataDir =/var/lib/mysql-cluster

[Ndbd]
Nodeid = 21
HostName = 10.0.125.86
DataDir =/var/lib/mysql-cluster

[Ndbd]
Nodeid = 22
HostName = 10.0.125.85
DataDir =/var/lib/mysql-cluster

[Mysqld]
Nodeid = 31
HostName = 10.0.125.86
[Mysqld]
Nodeid = 32
HostName = 10.0.125.85

Use configuration files to initialize Management Nodes

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

MySQL Cluster Management Server mysql-5.7.16 ndb-7.5.4 appears

Then you can use ndbd for management.

# Ndbd

Ndb_mgm> show (use the show command to view the management status. After the data node is configured, use this command to view and manage it)

 

By now, the management node is configured, and the data and SQL node are configured.

| Install configuration data and mysql nodes

All of the following operations must be performed on all cluster nodes.

New User Group mysql and user msyql

# Groupadd mysql

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

Create a folder and grant permissions

# Mkdir/var/lib/mysql-cluster

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

Upload the downloaded package to the server/usr/local.

Extract

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

Rename

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

Initialize the database (note that, if the version you install is different from mine, the database initialization command will be used in many previous versions: scripts/mysql_install_db -- user = mysql for initialization. mysql has been deprecated in the new version. Therefore, you need to use the following command to install it, if you need to install another version, refer to the installation command of the corresponding version on the mysql official website .)

# Cd/usr/local/mysql/bin/

#./Mysqld -- initialize

A temporary password is generated:O, Z2el6stDh", Remember the password, which will be used later.

 

Modify permissions

# Cd ..

First Return to the upper-level

# Chown-R root.

# Chown-R mysql data

# Chgrp-R mysql.

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

# Chmod + x/etc/rc. d/init. d/mysql. server

# Chkconfig -- add mysql. server

Configure data nodes

# Vi/etc/my. cnf

(Enter"IClick "Esc" in the upper left corner of the keyboard to exit editing. Enter ": wq" to save .)

[Mysqld]
Ndbcluster
Ndb-connectstring = 10.0.125.87

[Mysql_cluster]
Ndb-connectstring = 10.0.125.87

The IP address is the IP address of the Management node.

Start the service above the cluster node to start mysql (success will be successful)

#/Etc/init. d/mysql. server start

 

Start ndbd#/Etc/init. d/ndbd -- initialIf you cannot use the absolute path: #/Usr/local/mysql/bin/ndbd -- initialIf the following occurs, the operation is successful.

14:04:07 [ndbd] INFO -- Angel connected to '10. 0.125.86: 1186'
14:04:07 [ndbd] INFO -- Angel allocated nodeid: 21

 

Finally, when all the nodes are configured, return to the management node and use the show shown above to view the following similar display, proving that the connection has been completed.

# Cd/usr/local/bin/

# Ndb_mgm

Ndb_mgm> show
Cluster Configuration
---------------------
[Ndbd (NDB)] 2 node (s)
Id = 21 @ 10.0.125.86 (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0 ,*)

Id = 22 @ 10.0.125.85 (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0)

[Ndb_mgmd (MGM)] 1 node (s)
Id = 1 @ 10.0.125.87 (mysql-5.7.18 ndb-7.5.6)

[Mysqld (API)] 2 node (s)
Id = 31 @ 10.0.125.86 (mysql-5.7.18 ndb-7.5.6)

Id = 32@10.0.128.85 (mysql-5.7.18 ndb-7.5.6)

  |Test

Change the mysql password to ensure that the mysql access permission is modified so that the external ip address can remotely access mysql.

# Cd/usr/local/mysql/

#Bin/mysql -- user = root-p

Enter the previously saved temporary password.

Then change the password

Mysql>Set password = password ('root ');

Allow remote client connection

Mysql>Grant all privileges on *. * to root @ '%' identified by 'root ';

 

Create a database on one instance, check whether the other instance is synchronized, create a table, and add or delete a table.

Note that when creating a table, the engine of the table must be selected as ndbcluster; otherwise, the table will not be synchronized.

Below is the test

|Start and close

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

Run the command above. Delete -- initial.

When you close the management node, you only need to close the management node. The data nodes after it will be closed at the same time, and mysql will be the same as the original one.

Management node shutdown command: ndb_mgm-e shutdown

Description Command
Stop a management Node /Usr/local/bin/ndb_mgm-e shutdown
Start a management Node /Usr/local/bin/ndb_mgmd-f/var/lib/mysql-cluster/config. ini
Initialize management node startup /Usr/local/bin/ndb_mgmd-f/var/lib/mysql-cluster/config. ini -- initial
Start a Data Node /Usr/local/mysql/bin/ndbd
Initialize mysql ./Mysqld -- initialize
Start an SQL Node /Etc/init. d/mysql. server start

This article has been reproduced from others, tested and adjusted in some places:Http://www.cnblogs.com/linkstar/p/6510713.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.