请参考官方文档:http://dev.mysql.com/doc/refman/5.1/zh/ndbcluster.html
下面是官方的MySQL Cluster 的基本架构图:
搭建MySQL Cluster至少需要三个节点,一个管理节点来实现管理功能,一个SQL节点主机来实现MySQL server功能,一个ndb节点主机实现NDB Cluster的功能。
主机名 |
IP地址 |
作用 |
MySQL-SQL-Node1 |
192.168.140.128 |
SQL 节点服务器 |
MySQL-Data-Node1 |
192.168.140.129 |
Data 节点服务器 |
MySQL-MGM-Node |
192.168.140.130 |
管理节点服务器 |
注意:如果你的实验环境是根据本文的设置,为了对MySQL Cluster的配置不冲突,请整理前面的实验环境,如下:
[root@MySQL-Proxy ~]# /etc/init.d/mysql-proxy stop
[root@MySQL-Slave ~]# /etc/init.d/mysqld stop
[root@MySQL-Master ~]# /etc/init.d/mysqld stop
[root@MySQL-SQL-Node1 src]# wget
http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-Cluster-7.1/mysql-cluster-gpl-7.1.3.tar.gz
[root@MySQL-SQL-Node1 src]# chmod +x mysql-cluster-gpl-7.1.3.tar.gz
[root@MySQL-SQL-Node1 src]# scp mysql-cluster-gpl-7.1.3.tar.gz 192.168.140.129:/usr/local/src
[root@MySQL-SQL-Node1 src]# scp mysql-cluster-gpl-7.1.3.tar.gz 192.168.140.130:/usr/local/src
1> 安装MGM节点
[root@MySQL-MGM-Node ~]# cd /usr/local/src
[root@MySQL-MGM-Node src]# tar zxvf mysql-cluster-gpl-7.1.3.tar.gz
[root@MySQL-MGM-Node src]# cd mysql-cluster-gpl-7.1.3
[root@MySQL-MGM-Node mysql-cluster-gpl-7.1.3]# ./configure --prefix=/usr/local/mysqlcluster \
--with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static \
--enable-assembler --with-extra-charsets=complex \
--enable-thread-safe-client --with-big-tables --with-readline \
--with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysqlcluster/tmp/mysql.sock \
--sysconfdir=/usr/local/mysqlcluster/etc --without-debug \
--with-mysqld-user=mysql --with-plugins=max
[root@MySQL-MGM-Node mysql-cluster-gpl-7.1.3]# make && make install
2> 配置MGM节点
[root@MySQL-MGM-Node ~]# cd /usr/local/mysqlcluster/
[root@MySQL-MGM-Node mysqlcluster]# mkdir mysql-cluster
[root@MySQL-MGM-Node mysqlcluster]# vi mysql-cluster/config.ini
[NDBD DEFAULT]
NoOfReplicas= 1
DataMemory=50M
IndexMemory=10M
[NDB_MGMD]
id=1
HostName=192.168.140.130
DataDir=/usr/local/mysqlcluster/mysql-cluster
[NDBD]
id=2
HostName=192.168.140.129
DataDir=/usr/local/mysqlcluster/ndbdata
[MYSQLD]
id=3
HostName=192.168.140.128
3> 启动MGM节点
[root@MySQL-MGM-Node mysqlcluster]# libexec/ndb_mgmd -f
/usr/local/mysqlcluster/mysql-cluster/config.ini
1> 安装NDBD节点
[root@MySQL-Data-Node1 ~]# cd /usr/local/src
[root@MySQL-Data-Node1 src]# tar zxvf mysql-cluster-gpl-7.1.3.tar.gz
[root@MySQL-Data-Node1 src]# cd mysql-cluster-gpl-7.1.3
[root@MySQL-Data-Node1 mysql-cluster-gpl-7.1.3]# ./configure --prefix=/usr/local/mysqlcluster \
--with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static \
--enable-assembler --with-extra-charsets=complex \
--enable-thread-safe-client --with-big-tables --with-readline \
--with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysqlcluster/tmp/mysql.sock \
--sysconfdir=/usr/local/mysqlcluster/etc --without-debug \
--with-mysqld-user=mysql --with-plugins=max
[root@MySQL-Data-Node1 mysql-cluster-gpl-7.1.3]# make && make install
2> 配置NDBD节点
[root@MySQL-Data-Node1 ~]# cd /usr/local/mysqlcluster/
[root@MySQL-Data-Node1 mysqlcluster]# mkdir etc ndbdata
[root@MySQL-Data-Node1 mysqlcluster]# vi etc/my.cnf
[mysqld]
basedir=/usr/local/mysqlcluster/
datadir=/usr/local/mysqlcluster/var
user=mysql
port=3306
socket=/usr/local/mysql/tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.140.130
[mysql_cluster]
ndb-connectstring=192.168.140.130
3> 启动NDBD节点
[root@MySQL-Data-Node1 mysqlcluster]# libexec/ndbd --initial
注意:
第一次启动需要加--initial参数进行初始化工作,在以后的启动中,千万不要加该参数,因为ndbd程序会清除之前建立的所有用于恢复的数据文件和日志文件。
1> 安装SQL节点
[root@MySQL-SQL-Node1 ~]# cd /usr/local/src/
[root@MySQL-SQL-Node1 src]# tar zxvf mysql-cluster-gpl-7.1.3.tar.gz
[root@MySQL-SQL-Node1 src]# cd mysql-cluster-gpl-7.1.3
[root@MySQL-SQL-Node1 mysql-cluster-gpl-7.1.3]# ./configure --prefix=/usr/local/mysqlcluster \
--with-charset=utf8 --with-collation=utf8_general_ci \
--with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static \
--enable-assembler --with-extra-charsets=complex \
--enable-thread-safe-client --with-big-tables --with-readline \
--with-ssl --with-embedded-server --enable-local-infile \
--with-unix-socket-path=/usr/local/mysqlcluster/tmp/mysql.sock \
--sysconfdir=/usr/local/mysqlcluster/etc --without-debug \
--with-mysqld-user=mysql --with-plugins=max
[root@MySQL-Data-Node1 mysql-cluster-gpl-7.1.3]# make && make install
2> 配置SQL节点
[root@MySQL-SQL-Node1 ~]# cd /usr/local/mysqlcluster/
[root@MySQL-SQL-Node1 mysqlcluster]# mkdir etc
[root@MySQL-SQL-Node1 mysqlcluster]# chown -R root:mysql .
[root@MySQL-SQL-Node1 mysqlcluster]# bin/mysql_install_db --user=mysql
[root@MySQL-SQL-Node1 mysqlcluster]# vi etc/my.cnf
[mysqld]
basedir=/usr/local/mysqlcluster/
datadir=/usr/local/mysqlcluster/var
user=mysql
port=3306
socket=/usr/local/mysql/tmpcluster/mysql.sock
ndbcluster
ndb-connectstring=192.168.140.130
[mysql_cluster]
ndb-connectstring=192.168.140.130
3> 启动SQL节点
[root@MySQL-SQL-Node1 mysqlcluster]# bin/mysqld_safe --user=mysql &
在管理节点上测试:
[root@MySQL-MGM-Node ~]# cd /usr/local/mysqlcluster/
[root@MySQL-MGM-Node mysqlcluster]# bin/ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]1 node(s)
id=2@192.168.140.129 (mysql-5.1.44 ndb-7.1.3, Nodegroup: 0, Master)
[ndb_mgmd(MGM)]1 node(s)
id=1@192.168.140.130 (mysql-5.1.44 ndb-7.1.3)
[mysqld(API)]1 node(s)
id=3@192.168.140.128 (mysql-5.1.44 ndb-7.1.3)