Build MySQL Cluster

Source: Internet
Author: User
Tags chmod node server

Virtual machine build MySQL Cluster

Reference Document: Http://www.cnblogs.com/jackluo/archive/2013/01/19/2868152.html

Http://www.cnblogs.com/StanBlogs/archive/2011/06/14/2080986.html

Three servers are required. A Management node server. The other two act as data nodes and SQL nodes.

The Ubuntu64-bit operating system is selected here. The MySQL cluster correspondence must also be 64-bit. Go to the official site to download mysql-cluster-gpl-7.4.4-linux-glibc2.5-x86_64.

(Note: When the virtual machine operation, under the VMware, can only operate one SQL node, and then the virtual machine has the cloning function, the entire copy, so that the other SQL node is basically done, only need to change the next IP. In a virtual machine experiment, it is best to complete the snapshot or clone.

I'm here, Management node IP is 192.168.1.232

Another two machines, both acting as data nodes and also SQL nodes. IP is 192.168.1.210; 192.168.1.219

After installing the Ubuntu operating system, change the Ip,dns configuration.

Switch user sudo passwd root and create a root user password.

After Su root, enter the root password.

The following operations are performed using the root user.

IP configuration for each machine:

Vim/etc/network/interfaces

The contents of the change are as follows: (the words in parentheses are removed)

Auto Eth0

Iface eth0 inet Static (there is no DHCP dynamic, take static IP)

Address 192.168.1.219 (IP address)

Gateway 192.168.1.1 (Gateways address)

Netmask 255.255.255.0 (Subnet mask)

Dns-nameservers 192.168.1.1 (DNS resolution)

To restart the network settings:

sudo/etc/init.d/networking restart

I. Operations on data nodes and SQL nodes

1. Create groups, users

Groupadd MySQL

useradd-g MySQL MySQL

2. Download MySQL cluster64. Upload this file to a directory. Upload directly to/usr/local (if you upload a server using a file, you need to assign permissions such as chmod 777/usr/local)

Decompression: TAR-XVF mysql.tar.gz

Renamed: MV mysql-cluster-gpl-7.4.4-linux-glibc2.5-x86_64 MySQL

3. Modify MySQL directory permissions

CD MySQL

Chown-r Root.

Chown-r MySQL Data

Chgrp-r MySQL.

4. Install MySQL initial library

Under the MySQL directory:

scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql

5. Set MySQL to start

The MySQL service can be powered on. Not a whole line.

6. The MySQL configuration file is set here, which defaults to the performance parameters of the MySQL configuration.

Vim/etc/my.cnf

[Client]

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

[Mysqld]

Ndbcluster

Datadir=/usr/local/mysql/data

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

ndb-connectstring=192.168.1.232 #这个是管理节点的ip

Old_passwords=1

[Mysql_cluster]

ndb-connectstring=192.168.1.232 #这里配置的是管理节点服务器地址

7. You do not have to start the MySQL service at this time.

The above operations need to be done on multiple data nodes and SQL node machines (if the virtual machine, cloning is good, and then change the IP).

Two. Operations on the Management node

The management node does not need to install the MySQL service. Only need to mysql-cluster the two files after decompression, respectively is

On the SQL node server:/USR/LOCAL/MYSQL/BIN/NDB_MGMD and/USR/LOCAL/MYSQL/BIN/NDB_MGM

NDB_MGMD is the service of the Management node

NDB_MGM is the client view for the management node

1. Copy the two files on the SQL node to the/usr/local/bin directory of the Management node. (I use FileZilla to pass through)

2. On the management node, make sure that the two files are executable.

Cd/usr/local/bin

chmod +x ndb_mgm*

3. Create a MySQL folder under/usr/local to ensure that the data node can generate a log file when the service is opened

Mkdir/usr/local/mysql

4. Create a configuration file for a management node

Mkdir/var/lib/mysql-cluster

Cd/var/lib/mysql-cluster

Vim Config.ini

[NDBD DEFAULT]

noofreplicas=2

[TCP DEFAULT]

portnumber=22202

[NDB_MGMD]

hostname=192.168.1.232 #管理节点

datadir=/var/lib/mysql-cluster/

[NDBD]

hostname=192.168.1.210 #数据节点

datadir=/usr/local/mysql/data/

[NDBD]

hostname=192.168.1.219 #数据节点

datadir=/usr/local/mysql/data/

[MYSQLD]

# Here the SQL node is configured, preferably left blank.

[MYSQLD]

Third, start MySQL cluster

Note The boot order: the first is the management node, then the data node, and finally the SQL node.

1. Ndb_mgmd-f/var/lib/mysql-cluster/config.ini--initial

The first time you start, add the--initial parameter, or when you change the Config.ini node, add

(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. )

Use NDB_MGM to listen to the client at this time

2. Data node

/usr/local/mysql/bin/ndbd

The first time you start, you need to add the--initial parameter for the initialization of the NDB node. You cannot add this parameter during a later boot process, otherwise the NDBD program clears all data files and log files that were previously established for recovery.

/USR/LOCAL/MYSQL/BIN/NDBD--initial

(If error: Log file cannot be generated, create this directory manually)

At this point, on the management node, NDB_MGM, when using the show command, you can see that the data node is connected (this is required for multiple data nodes)

3. SQL node

/usr/local/mysql/bin/mysqld_safe--user=mysql &

If an error says that a certain socket is not connected to MySQL, try creating the system database again, as follows:

Under the MySQL directory

scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql

Start again

/usr/local/mysql/bin/mysqld_safe--user=mysql &

View the Management node. The SQL node should also be connected at this point.

Iv. Testing

1 , General testing:

On node 4 above:

In order for the table to replicate normally in cluster, creating a table must use the Ndbcluster engine (engine=ndb Or Engine=ndbcluster) method as follows:

Mysql>use Test

Mysql>create table Teacher (t_id int) engine=ndb; (here the engine should be NDB, not InnoDB)

If it is an already existing table, modify the table's engine with ALTER table.

Mysql>alter table Student Engine=ndb;

Insert a piece of data:

Mysql>insert into teacher values (133);

Then on Node 5:

Mysql>select * from teacher;

Two node data consistency, congratulations, test success!

Simulation NDB node Crash :

This basic Reference document:

http://www.cnblogs.com/StanBlogs/archive/2011/06/14/2080986.html

Build MySQL Cluster

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.