Simple use of mysql-cluster-7.5 to build a DB cluster

Source: Internet
Author: User

Read Catalogue

    • Objective
    • Several conceptual explanations in MySQL cluster
    • Architecture Diagram and Description
    • Download MySQL Cluster
    • Before installing MySQL Cluster
    • Install the Configuration Management node
    • Installing configuration data and MySQL nodes
    • Test
    • Start and close
    • Summarize

|Objective

When your business arrives at a certain amount of the equivalent, you certainly need a certain number of databases to load balance your database requests, I have explained in the previous blog, how to achieve load balancing, but there is also a problem is data synchronization, because the premise of load balancing is that each server database is data synchronization. When the volume of business is small, we will use the master-slave replication method to achieve server data synchronization, a master and many from or dual-master, but although the read-write separation, but for the reading method is still relatively large, so the problem of solving data synchronization is the significance of the database cluster. I use the mysql-cluster provided by the MySQL website to implement the cluster. (to the article before the release of the latest version of the installation tutorial, the network trampled the pits have stepped over;)

| Several conceptual explanations in MySQL cluster

For the sake of simplicity, I hereafter referred to as Mysql-cluster for MC.

1, MC already contains MySQL, I download the latest mc7.5, official note contains is the MySQL version is 5.7. Therefore, you do not need to install the database using another MSYQL installation package. Also note that the mysql5.7 version in the installation of the command and configuration above and before the version is very different, so there are a lot of mc7.5 before the version, contains a different version of MySQL, so the installation method is different.

2, Management node, MC Management node is responsible for the management, configuration, monitoring the entire cluster.

3, the Data node, the use of memory storage data, the data stored in the data node will be automatically copied and stored to other data nodes.

4, MySQL node, also known as the database node, and we usually use the same MySQL, as a database use. Accessed by the data node.

|Architecture Diagram and Description

The configuration in my experiment is that because the virtual machine consumes a large amount of memory and uses only 3 servers, it is best to separate the data node from the MySQL node in the actual situation. In practice, the load balancing service also needs to be backed up, because in the event that the Load Balancer server goes down and all data nodes are inaccessible, you need to manage the node and load balancer separately for the Load Balancer server backup, conditionally. The experiment only realizes the whole database cluster, load Balancing please refer to 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 version I downloaded is mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

Note that the 64-bit version, do not download the wrong

|Before installing MySQL Cluster

Before installing, if you have previously installed MySQL, then you need to delete the corresponding various MySQL files, please stop the MySQL service before deleting. And do not forget to delete the my.cnf these configuration files. Make sure to delete cleanly. Otherwise it may be in conflict with the subsequent installation. If it is an experiment, turn off the firewall, actually, the firewall opens the corresponding port. Ensure that the server can access each other before, can ping through. Secure a fixed IP address. Ensure that no other programs occupy the ports that need to be used. such as 3306. These are confirmed and then installed. Requires Linux Basic command proficiency, need to be proficient in the installation of MySQL basic version of operations, because some of the post-order operations I will simply describe, do not do 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

Take the required files out

# 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 new configuration file and initialize the management node

# Mkdir/var/lib/mysql-cluster

# Mkdir/usr/local/mysql

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

(enter "i" is the edit, press the upper left corner of the keyboard "ESC" Exit Edit, enter ": Wq" for saving. )

Here is the configuration file, according to my modified changes can be, the other can not move.

[NDBD Default]
noofreplicas=2
datamemory=40960m
indexmemory=512m


[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

Initializing the management node with a configuration file

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

The MySQL Cluster Management Server mysql-5.7.16 appears ndb-7.5.4

And then you can use NDBD to go in and manage.

# NDBD

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

So far, the management node is configured, then the configuration data and SQL node

|Installing configuration data and MySQL nodes

All of the following operations require the same action on all cluster nodes

New 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

# 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

Renaming

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

Initialize the database (note here that if you install the version unlike mine, the database initializes the commands differently, many of the previous versions will use: scripts/mysql_install_db--user=mysql to initialize, This has been deprecated in the new version of MySQL, so you need to use the following command to install, if you need to install another version please refer to the corresponding version of the MySQL official installation command. )

# cd/usr/local/mysql/bin/

#./mysqld--initialize

The temporary password is generated: I'm generating the "O,Z2EL6STDH", this password to remember, to be used later.

Modify Permissions

# CD:

First return to the previous 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 "i" is the edit, press the upper left corner of the keyboard "ESC" Exit Edit, enter ": Wq" for saving. )

[Mysqld]
Ndbcluster
ndb-connectstring=10.0.125.87

[Mysql_cluster]
ndb-connectstring=10.0.125.87

Where IP is the IP of the management node

Start MySQL on the server above the cluster node (success will be success)

#/etc/init.d/mysql.server Start

Start ndbd#/etc/init.d/ndbd--initial If the above does not use the absolute path of this : #/usr/local/mysql/bin/ndbd--initial If the following occurs, it succeeds.

2017-03-06 14:04:07 [NDBD] INFO--Angel connected to ' 10.0.125.86:1186 '
2017-03-06 14:04:07 [NDBD] INFO--Angel allocated nodeid:21

Finally, when all the node configuration is complete, go back to the management node, use the above mentioned show to view, similar display below, prove that the connection is complete

#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

Modify MySQL password unified, modify MySQL access, so that external IP can remotely access MySQL

#cd/usr/local/mysql/

# Bin/mysql--user=root–p

Enter the temporary password that you saved earlier.

Then change the password

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

Allow clients to connect remotely

Mysql>Grant all privileges on * * to [e-mail protected] '% ' identified by ' root ';

Then create a database on one of the above, see if the other one is synchronized, then create the table, then add the delete and so on.

The only thing to note is that when you create a table, you must select the engine for the table ndbcluster, otherwise the table will not be synchronized

The following is the test

|Start and close

Start the MySQL cluster. The boot order is: management node → data node →sql node.

Start the command above all, delete--initial can

Shutdown only need to close the management node, the subsequent data node will be closed at the same time, MySQL is the same as the original

Management node shutdown command: NDB_MGM-E shutdown

Describe Command
Stopping the management node /USR/LOCAL/BIN/NDB_MGM-E shutdown
Start the Management node /usr/local/bin/ndb_mgmd-f/var/lib/mysql-cluster/config.ini
Initialize the management node to start /usr/local/bin/ndb_mgmd-f/var/lib/mysql-cluster/config.ini--initial
Start Data node /usr/local/mysql/bin/ndbd
Initialize MySQL ./mysqld--initialize
Start the SQL node /etc/init.d/mysql.server start

This article has been reproduced from other people, personally tested and made adjustments to some places:http://www.cnblogs.com/linkstar/p/6510713.html

Simple use of mysql-cluster-7.5 to build a DB cluster

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.