MySQL cluster (mysql cluster) installation configuration scenario

Source: Internet
Author: User
Tags create directory deprecated node server

I. Description

This article references: http://www.cnblogs.com/jackluo/archive/2013/01/19/2868152.html

1. Preparing the server

Plan to build a 5-node MySQL cluster system, need to use 5 servers, but we do not have so many machines in the experiment, can only use 3, provide 5 nodes of the MySQL cluster system, the SQL node and the data node share a machine, as follows.

Host Name

Node

The corresponding IP and port

Db-mgm

Management node

10.10.6.201:1186

Db-node1

Data node

10.10.6.211:2202

Db-node1

SQL node

10.10.6.211:3306

Db-node2

Data node

10.10.6.212:2202

Db-node2

SQL node

10.10.6.212:3306

2. Preparing packages

MySQL now provides a dedicated cluster installation package, so that you do not need to download the necessary tools. Download from official website.

Http://cdn.mysql.com/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.5-linux-glibc2.5-x86_64.tar.gz

Second, install (a) data node and SQL node (each two units) 1. Add MySQL users and groups, which is required.

[[email protected] ~]# Groupadd MySQL

[[email protected] ~]# useradd-g MySQL MySQL

[Email protected] ~]#

2. To start the installation, the downloaded version is free from compilation and can be copied over.

[Email protected] ~]# http://cdn.mysql.com/Downloads/MySQL-Cluster-7.4/ Mysql-cluster-gpl-7.4.5-linux-glibc2.5-x86_64.tar.gz
[Email protected] ~]# TAR-ZXVF mysql-cluster-gpl-7.4.5-linux-glibc2.5-x86_64.tar.gz-c/usr/local/

[Email protected] ~]# ln-sv/usr/local/mysql-cluster-gpl-7.4.5-linux-glibc2.5-x86_64//usr/local/mysql

[Email protected] ~]#

3. Modify the directory permissions, which is also required, or the fourth step will be an error.

[Email protected] ~]# chown-r mysql.root/usr/local/mysql

[Email protected] ~]# chown-r mysql.root/usr/local/mysql/

[Email protected] ~]#

4. Install the initial database table

[Ro[email protected] ~]#/usr/local/mysql/scripts/mysql_install_db--user=mysql

FATAL error:could not find./bin/my_print_defaults

If you compiled from source, you need to run ' make install ' to

Copy the software into the correct location ready for operation.

If you is using a binary release, you must either is at the top

Level of the extracted archive, or pass the--BASEDIR option

Pointing to the location.

If the above error occurs, the MySQL directory is not specified and must be specified manually.

Workaround

[Email protected] ~]#/usr/local/mysql/scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/ usr/local/mysql/data/

5. Set up MySQL service to boot and boot

[Email protected] ~]# Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld

[Email protected] ~]# chmod +x/etc/rc.d/init.d/mysqld

[Email protected] ~]# chkconfig--add mysqld

[Email protected] ~]# chkconfig--list mysqld

Mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[Email protected] ~]#

[[Email protected] ~]# service mysqld start

In this step, the data node and the SQL node are installed.

(ii) Management node

Management node installation is simpler, as long as the data node and the SQL node server to copy some files out, although only one step, [[email protected] ~]# SCP 10.10.6.211:/usr/local/mysql/bin/ndb_mgm* /usr/local/bin/

[Email protected] ~]# ll/usr/local/bin/ndb*

-rwxr-xr-x 1 root root 7137184 Apr 09:45/USR/LOCAL/BIN/NDB_MGM

-rwxr-xr-x 1 root root 16336025 Apr 09:45/USR/LOCAL/BIN/NDB_MGMD

[Email protected] ~]#

Management node as long as the NDB_MGM and NDB_MGMD two files and a configuration file, so the three files are copied there, there is the management node. NDB_MGMD is the MySQL cluster Management Server, NDB_MGM is the Client management tool, and so on will use them. So far two SQL node two data nodes and a management node have been installed, but still do not work, have to be configured to connect these nodes together to work.

Three, configuration (a) Data node and SQL node (two units each)

The MySQL service will load/etc/my.cnf as its profile by default when it starts, and it is very simple to configure a MySQL server as a data node and SQL node:

Just add the following 4 lines to the end of the content and turn the MySQL server into a data node and a SQL node.

Ndbcluster \ \ Run NDB storage engine

ndb-connectstring=10.10.6.201 \ \ Specifies the management node, which declares it to be a SQL node.

[Mysql_cluster]

ndb-connectstring=10.10.6.201 \ \ Specifies the management node, which declares it to be a data node.

Create a new MySQL configuration file

[Email protected] ~]# VI/ETC/MY.CNF

[Email protected] ~]# MORE/ETC/MY.CNF

[Client]

port=3306

Socket=/usr/local/mysql/mysql.sock

[Mysqld]

basedir=/usr/local/mysql/

Datadir=/usr/local/mysql/data

user= MySQL

Pid-file=/usr/local/mysql/mysqld.pid

Log-error=/usr/local/mysql/mysqld.err

New additions to the following four behaviors

Ndbcluster \ \ Run NDB storage engine

ndb-connectstring=10.10.6.201 \ \ Specifies the management node, which declares it to be a SQL node.

[Mysql_cluster]

ndb-connectstring=10.10.6.201 \ \ Specifies the management node, which declares its data node.

[Email protected] ~]#

Note that all two servers have to be configured this way.

(ii) Management node

The configuration of the management node is a little more complicated to create a config.ini file in the Management Server/usr/local/mysql/directory.

Online said to use Mysql-cluster, but at the start of the total when the following tips:

[Email protected] ~]# ndb_mgmd-f/usr/local/mysql-cluster/config.ini

MySQL Cluster Management Server mysql-5.6.23 ndb-7.4.5

2015-04-13 14:13:28 [Mgmtsrvr] INFO-The default Config directory '/usr/local/mysql/mysql-cluster ' does not exist. Trying to create it ...

Failed to create directory '/usr/local/mysql/mysql-cluster ', error:2

2015-04-13 14:13:28 [Mgmtsrvr] ERROR-Could not create directory '/usr/local/mysql/mysql-cluster '. Either create it manually or specify a different directory with--configdir=<path>

[Email protected] ~]#

And finally changed it to/usr/local/mysql.

[Email protected] ~]# Mkdir/usr/local/mysql

[Email protected] ~]# Vi/usr/local/mysql/config.ini

[Email protected] ~]# More/usr/local/mysql/config.ini

[NDBD DEFAULT]

Noofreplicas=1 \ \ Number of mirrors per data node

datamemory=500m \ \ Memory allocated to data in each data node

indexmemory=300m \ \ The memory allocated to the index in each data node

[TCP DEFAULT]

portnumber=2202 \ \ Default connection port for data node

[NDB_MGMD] \ \ Configuration Management node

hostname=10.10.6.201

datadir=/usr/local/mysql/\ \ Admin node data (log) directory

[NDBD]

hostname=10.10.6.211 \ \ Data Node configuration

datadir=/usr/local/mysql/data/\ \ Data Node directory

[NDBD]

hostname=10.10.6.212

datadir=/usr/local/mysql/data/

[MYSQLD] \\SQL node directory

hostname=10.10.6.211

[MYSQLD]

hostname=10.10.6.212

[Email protected] ~]#

[NDBD Default]: Indicates that each data node is configured to have no more options in the [NDBD] of each node, only one.
[NDB_MGMD]: Represents the configuration of the management node, only one.
[NDBD]: Represents the configuration of each data node, can have more than one.
[MYSQLD]: Represents the configuration of the SQL node, can have multiple, write the IP address of the different SQL nodes separately, can also write nothing, only one empty node, indicating that any one IP address can be accessed, the number of this node indicates the total number of SQL nodes that can be used to connect to the data node.

Four, start (a) Management node 1. Start the Management node

MySQL cluster requires each node to be started before it can work, and the node's boot order is the data node->sql node, the management node. Start the Management node first

[Email protected] ~]# ndb_mgmd-f/usr/local/mysql/config.ini

MySQL Cluster Management Server mysql-5.6.23 ndb-7.4.5

2015-04-13 14:14:14 [Mgmtsrvr] INFO-The default Config directory '/usr/local/mysql/mysql-cluster ' does not exist. Trying to create it ...

2015-04-13 14:14:14 [Mgmtsrvr] INFO--sucessfully created config directory

2015-04-13 14:14:14 [Mgmtsrvr] WARNING--At line 7: [TCP] portnumber is deprecated

[Email protected] ~]#

[Email protected] ~]# echo "/usr/local/bin/ndb_mgmd-f/usr/local/mysql/config.ini" >>/etc/rc.local

[Email protected] ~]#

The NDB_MGMD on the command line is the Management Server for MySQL cluster, followed by-F to indicate that the parameter that follows is the parameter configuration file that is started. If you have added a data node A few days after startup, you must add the--initial parameter when you modify the configuration file, otherwise the added node will not function in MySQL cluster.

./ndb_mgmd-f/var/lib/mysql-cluster/config.ini--initial

A warning may be reported at startup, such as warning-at line 7: [TCP] portnumber is deprecated, this is not a tube. can work properly.

2. See if there is a successful start

[Email protected] ~]# ls/usr/local/mysql/

Config.ini mysql-cluster ndb_1_cluster.log Ndb_1_out.log ndb_1.pid

[Email protected] ~]#

[Email protected] ~]# NETSTAT-TLNP | grep 1186

TCP 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 3075/NDB_MGMD

[Email protected] ~]# NDB_MGM

--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 10.10.6.211)

Id=3 (not connected, accepting connect from 10.10.6.212)

[NDB_MGMD (MGM)] 1 node (s)

Id=1 @10.10.6.201 (mysql-5.6.23 ndb-7.4.5)

[Mysqld (API)] 2 node (s)

Id=4 (not connected, accepting connect from 10.10.6.211)

Id=5 (not connected, accepting connect from 10.10.6.212)

Ndb_mgm> exit

[Email protected] ~]#

(ii) Data node (two units)

When you start the data node for the first time after installation, add the--initial parameter, and do not add it unless it is restarted after a backup, recovery, or configuration change.

[Email protected] ~]#/USR/LOCAL/MYSQL/BIN/NDBD--initial

2015-04-13 14:49:59 [NDBD] INFO--Angel connected to ' 10.10.6.201:1186 '

2015-04-13 14:49:59 [NDBD] INFO--Angel allocated Nodeid:2

[Email protected] ~]# NETSTAT-TLNP |grep 2202

TCP 0 0 10.10.6.211:2202 0.0.0.0:* LISTEN 14780/ndbd

[Email protected] ~]#

[Email protected] ~]# ECHO/USR/LOCAL/MYSQL/BIN/NDBD >>/etc/rc.local

[Email protected] ~]#

(c) SQL node (two units)

[[Email protected] ~]# service mysqld start

Starting MySQL success!

[Email protected] ~]#

(iv) Client management

At this point into the client or management node, you can do various operations on the MySQL cluster, there will be NDB_MGM > prompt appears, first to see the connection of each node, enter show at ndb_mgm> prompt:

[Email protected] ~]# NDB_MGM

--NDB Cluster--Management Client--

Ndb_mgm> Show

Connected to Management Server at:localhost:1186

Cluster Configuration

---------------------

[NDBD (NDB)] 2 node (s)

id=2 @10.10.6.211 (mysql-5.6.23 ndb-7.4.5, nodegroup:0, *)

Id=3 @10.10.6.212 (mysql-5.6.23 ndb-7.4.5, nodegroup:1)

[NDB_MGMD (MGM)] 1 node (s)

Id=1 @10.10.6.201 (mysql-5.6.23 ndb-7.4.5)

[Mysqld (API)] 2 node (s)

Id=4 @10.10.6.211 (mysql-5.6.23 ndb-7.4.5)

Id=5 @10.10.6.212 (mysql-5.6.23 ndb-7.4.5)

Ndb_mgm> exit

You can see that the individual nodes are connected, and the MySQL cluster configuration is complete.

(v) Closure

MySQL cluster is also very simple to close, just enter the shutdown at the ndb_mgm> prompt, this will show the closing information of each node, and then enter exit to exit NDB_MGM Management, back to the shell. Although MySQL cluster is turned off, the SQL node's MySQL service does not stop. Then we can do all kinds of experiments.

V. Test (i) Create a new test database in a SQL node, jedy_db

[Email protected] mysql]#/usr/local/mysql/bin/mysql

mysql> CREATE DATABASE jedy_db;

Query OK, 1 row affected (0.10 sec)

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| jedy_db |

| MySQL |

| Ndb_2_fs |

| Ndbinfo |

| Performance_schema |

| Test |

+--------------------+

7 rows in Set (0.05 sec)

Mysql> \q

Bye

[Email protected] mysql]#

(ii) View in another SQL node

[Email protected] mysql]#/usr/local/mysql/bin/mysql

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| Information_schema |

| jedy_db |

| MySQL |

| Ndb_3_fs |

| Ndbinfo |

| Performance_schema |

| Test |

+--------------------+

7 rows in Set (0.06 sec)

Mysql> \q

Bye

[Email protected] mysql]#

All configurations Complete

MySQL cluster (mysql cluster) installation configuration scheme

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.