MySQL High-availability solution cluster (cluster)

Source: Internet
Author: User

1. Experimental environment

I built the MySQL cluster environment with three servers, the SQL node and the data node are on the same server, and the management node is a separate one.

Cluster node1:192.168.1.102 Data node1:192.168.1.102

Cluster node2:192.168.1.104 Data node2:192.168.1.104

Manager node:192.168.1.19

Os:centos 6.4 64-bit

2. Install MySQL cluster on SQL node and data node

Cluster Node1:

[Email protected] home]# wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.3/ Mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64.tar.gz

[Email protected] home]# tar xvf mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64.tar.gz

[Email protected] home]# MV mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64/usr/local/mysql-cluster-gpl-7.3.6/

[Email protected] home]# cd/usr/local/

[[email protected] local]# Groupadd MySQL
[Email protected] local]# useradd-r-m-s/sbin/nologin MySQL

[Email protected] local]# chown-r root:mysql mysql-cluster-gpl-7.3.6/
[Email protected] local]# chown-r mysql:mysql mysql-cluster-gpl-7.3.6/data/

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

[Email protected] scripts]# CD. /bin/

[Email protected] bin]# cp-a. /support-files/mysql.server/etc/init.d/mysqld

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

[Email protected] bin]# chkconfig mysqld on

[Email protected] bin]# cp-a. /my.cnf/etc/my.cnf

[Email protected] bin]# VIM/ETC/MY.CNF

[Mysqld]

Basedir =/usr/local/mysql-cluster-gpl-7.3.6--The installation path of the database
DataDir =/usr/local/mysql-cluster-gpl-7.3.6/data--Data directory of the database
Port = 3306
Ndbcluster--Cluster service
ndb-connectstring=192.168.1.19--The IP address of the management node

[Mysql_cluster]
ndb-connectstring=192.168.1.19--The IP address of the management node

[[email protected] bin]#./mysqld_safe--user=mysql

[[email protected] bin]#/etc/init.d/mysqld restart
 error! MySQL server PID file could not being found!
Starting MySQL ..... ..... .................... success!
[[email protected] bin]# netstat-anp |grep mysql
tcp        0       0:::3306                     :::*                          listen       1982/mysqld        
unix  2      [ACC]     stream     listening     48481  1982/ mysqld        /tmp/mysql.sock[[email protected] bin]#/etc/init.d/ Iptables Stop

Iptables:setting chains to Policy Accept:filter [OK]
iptables:flushing firewall rules: [OK]
iptables:unloading modules: [OK]
[Email protected] bin]#

Cluster Node2:

Note: The MySQL cluster installation on Node 2 is the same as Node 1, and the configuration file is the same

3. Managing nodes

[Email protected] home]# wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.3/ Mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64.tar.gz

[Email protected] home]# tar xvf mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64.tar.gz

[Email protected] home]# MV mysql-cluster-gpl-7.3.6-linux-glibc2.5-x86_64/usr/local/mysql-cluster-gpl-7.3.6/

[Email protected] home]# cd/usr/local/

[[email protected] local]# Groupadd MySQL
[Email protected] local]# useradd-r-m-s/sbin/nologin MySQL

[Email protected] local]# chown-r root:mysql mysql-cluster-gpl-7.3.6/
[Email protected] local]# chown-r mysql:mysql mysql-cluster-gpl-7.3.6/data/

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

[Email protected] scripts]# CD. /bin/

[Email protected] bin]# cp-a. /my.cnf/etc/my.cnf

[Email protected] bin]# VIM/ETC/MY.CNF

[Mysqld]

Basedir =/usr/local/mysql-cluster-gpl-7.3.6
DataDir =/usr/local/mysql-cluster-gpl-7.3.6/data
Port = 3306

[[email protected] home]#/etc/init.d/iptables stop
iptables:flushing firewall rules: [OK]
Iptables:setting chains to Policy Accept:filter [OK]
iptables:unloading modules: [OK]

[Email protected] home]# mkdir/var/lib/mysql-cluster/

[[email protected] home]# Vim/var/lib/mysql-cluster/config.ini--note case in config file

[NDBD Default]
Noofreplicas=1

[TCP Default]
portnumber=2202

[NDB_MGMD]
Id=1
hostname=192.168.1.19
Datadir=/usr/local/mysql-cluster-gpl-7.3.6/data

[NDBD]
id=2
hostname=192.168.1.102
datadir=/usr/local/mysql-cluster-gpl-7.3.6/data/


[NDBD]
Id=3
hostname=192.168.1.104
datadir=/usr/local/mysql-cluster-gpl-7.3.6/data/

[MYSQLD]
Id=4
hostname=192.168.1.102

[MYSQLD]
Id=5
hostname=192.168.1.104

[Email protected] bin]#/NDB_MGMD--configdir=/var/lib/mysql-cluster/-f/var/lib/mysql-cluster/config.ini-- Initial--Start the Management node service
MySQL Cluster Management Server mysql-5.6.17 ndb-7.3.6

[Email protected] bin]# NETSTAT-ANP | grep NDB
TCP 0 0 0.0.0.0:1186 0.0.0.0:* LISTEN 3569/NDB_MGMD
TCP 0 0 192.168.1.105:1186 192.168.1.102:45799 established 3569/NDB_MGMD
TCP 0 0 192.168.1.105:1186 192.168.1.104:46933 established 3569/NDB_MGMD
TCP 0 0 127.0.0.1:1186 127.0.0.1:55347 established 3569/NDB_MGMD
TCP 0 0 192.168.1.105:1186 192.168.1.102:45800 established 3569/NDB_MGMD
TCP 0 0 192.168.1.105:1186 192.168.1.102:45801 established 3569/NDB_MGMD
TCP 0 0 127.0.0.1:55347 127.0.0.1:1186 established 3569/NDB_MGMD
UNIX 3 [] STREAM CONNECTED 20977 3569/NDB_MGMD
UNIX 3 [] STREAM CONNECTED 20976 3569/NDB_MGMD
[Email protected] bin]#

4. Start the cluster node and the database service

Cluster Node1:

[Email protected] bin]#/NDBD--initial

2014-10-10 09:59:20 [NDBD] INFO--Angel connected to ' 192.168.1.19:1186 '
2014-10-10 09:59:20 [NDBD] INFO--Angel allocated Nodeid:2

[Email protected] bin]#. /support-files/mysql.server start
Starting MySQL success!
[Email protected] bin]#

Cluster Node2:

[Email protected] bin]#/NDBD--initial

2014-10-10 10:01:24 [NDBD] INFO--Angel connected to ' 192.168.1.19:1186 '
2014-10-10 10:01:24 [NDBD] INFO--Angel allocated Nodeid:3

[Email protected] bin]#. /support-files/mysql.server start
Starting MySQL success!
[Email protected] bin]#

Management node View information:

[Email protected] bin]#./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 @192.168.1.102 (mysql-5.6.17 ndb-7.3.6, nodegroup:0, *)
Id=3 @192.168.1.104 (mysql-5.6.17 ndb-7.3.6, nodegroup:1)

[NDB_MGMD (MGM)] 1 node (s)
Id=1 @192.168.1.19 (mysql-5.6.17 ndb-7.3.6)

[Mysqld (API)] 2 node (s)
Id=4 @192.168.1.102 (mysql-5.6.17 ndb-7.3.6)
Id=5 @192.168.1.102 (mysql-5.6.17 ndb-7.3.6)

Ndb_mgm>

This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1561980

MySQL High-availability solution cluster (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.