最近测试了一下mysql cluster,使用的系统是centos 5.8 64位,由于只是为了测试功能,所以为了不那么麻烦就是用rpm包安装,cluster使用的7.2.8版本,管理节点和数据节点只需要安装server就可以了,sql节点是需要安装client就可以了。
安装完成后开始配置,配置的过程就是添加几个配置文件。
管理节点,在默认的路径/var/lib/mysql下重建一个config.ini文件,内容如下:
[ndbd default]
noOfReplicas=2
DataMemory=80M
IndexMemory=18M
[tcp default]
[ndb_mgmd]
hostname=192.168.163.110
datadir=/var/lib/mysql
[ndbd]
hostname=192.168.163.140
datadir=/var/lib/mysql/data
[ndbd]
hostname=192.168.163.170
datadir=/var/lib/mysql/data
[mysqld]
hostname=192.168.163.160
[mysqld]
hostname=192.168.163.110
数据节点的配置文件是my.cnf,在/etc目录下
添[mysqld]
ndbcluster
ndb-connectstring = 192.168.163.110
[ndb_cluster]
ndb-connectstring = 192.168.163.110
sql节点的配置文件也是my.cnf,也是在/etc目录下
[mysqld]
#basedir = /var/lib/mysql/data
#datadir = /var/lib/mysql/data
user = mysql
port = 3306
#socket = /tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.163.110
[mysql_cluster]
ndb-connectstring=192.168.163.110
配置文件添加完成后,剩下的就是启动mysql cluster各个节点了。
首先启动mysql 管理节点,ndb_mgmd –f /var/lib/mysql/config.ini
[root@vmhost02 local]# ndb_mgmd -f /var/lib/mysql/config.ini
MySQL Cluster Management Server mysql-5.5.27 ndb-7.2.8
[root@vmhost02 local]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.163.110:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.163.140)
id=3 (not connected, accepting connect from 192.168.163.170)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.163.110 (mysql-5.5.27 ndb-7.2.8)
[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from 192.168.163.160)
id=5 (not connected, accepting connect from 192.168.163.110)
管理节点启动完成,然后启动数据节点
[root@vmhost05 ~]# ndbd --ndb-connectstring=192.168.163.110:1186
2012-10-18 15:52:17 [ndbd] INFO -- Angel connected to '192.168.163.110:1186'
2012-10-18 15:52:17 [ndbd] INFO -- Angel allocated nodeid: 2
[root@vmhost05 ~]# ps -ef|grep ndb
root 20571 1 0 15:52 ? 00:00:00 ndbd --ndb-connectstring=192.168.163.110:1186
root 20572 20571 23 15:52 ? 00:00:01 ndbd --ndb-connectstring=192.168.163.110:1186
root 20607 4420 0 15:52 pts/0 00:00:00 grep ndb
[root@vmhost ~]# ndbd --ndb-connectstring=192.168.163.110:1186
2012-10-18 15:52:44 [ndbd] INFO -- Angel connected to '192.168.163.110:1186'
2012-10-18 15:52:44 [ndbd] INFO -- Angel allocated nodeid: 3
[root@vmhost ~]# ps -ef|grep ndb
root 22005 1 0 15:52 ? 00:00:00 ndbd --ndb-connectstring=192.168.163.110:1186
root 22006 22005 22 15:52 ? 00:00:01 ndbd --ndb-connectstring=192.168.163.110:1186
root 22051 4787 0 15:52 pts/0 00:00:00 grep ndb
两个数据节点启动都完成了,然后就是启动sql节点了,sql节点的启动和mysql没有太大的区别servies mysql start或者/etc/init.d/mysql start,也可以使用mysqld_safe.
至此整个mysql cluster就启动完成了。
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.163.140 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0, Master)
id=3 @192.168.163.170 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.163.110 (mysql-5.5.27 ndb-7.2.8)
[mysqld(API)] 3 node(s)
id=4 (not connected, accepting connect from 192.168.163.160)
测试mysql工作情况,创建一个数据库jiqun,在jiqun库里面创建一张表tb1,随便插入几条数据,然后关闭192.168.163.140数据节点的ndb程序,查询tb1数据,然后插入数据到tb1表,启动140数据节点的ndb服务,再查询结果。