1. 下载mysql cluster的可执行文件压缩包, 写这个帖子的时候已经出到了7.1.x,无奈这个版本无论如何我也没配置成功,无奈转会6.x
wget http://www.mysql.com/get/Downloads/MySQL-Cluster-6.3/mysql-cluster-gpl-6.3.39-linux-i686-glibc23.tar.gz/from/http://mysql.he.net/
2. 安装
tar zxvf mysql-cluster-gpl.6.3.39-linux-i686-glibc23.tar.gz
mv ./mysql-cluster-gpl-6.3.39-linux-i686-glibc23 /usr/local/
cd /usr/local
ln -s mysql-cluster-gpl-6.3.39-linux-i686-glibc23 mysql
groupadd mysql
useradd -g mysql mysql
cd mysql
scripts/mysql_install_db –user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
cp bin/ndb* /usr/local/bin/
3.编辑配置文件
mkdir /var/lib/mysql-cluster
chown mysql.mysql /var/lib/mysql-cluster
编辑/lib/mysql-cluster/config.ini
[NDBD DEFAULT] NoOfReplicas=3DataMemory=768M
IndexMemory=128M
MaxNoOfAttributes=4000
MaxNoOfOrderedIndexes=125
MaxNoOftables=150
TimeBetweenWatchDogCheck= 90000 [MYSQLD DEFAULT] [NDB_MGMD DEFAULT] [TCP DEFAULT] # Managment Server
[NDB_MGMD] # the IP of THIS SERVER
NodeId=1
HostName=10.10.0.243
LogDestination=FILE:filename=cluster.log,maxsize=1000000,maxfiles=6 [NDB_MGMD] NodeId=2
# the IP of SECOND MGMD
HostName=10.10.0.247
LogDestination=FILE:filename=cluster.log,maxsize=1000000,maxfiles=6
# Storage Engines
[NDBD] NodeId=3# the IP of the FIRST SERVER (STORAGE NODE)
HostName=10.10.0.244
DataDir=/var/lib/mysql-cluster [NDBD] NodeId=4
# the IP of the SECOND SERVER (STORAGE NODE)
HostName=10.10.0.245
DataDir=/var/lib/mysql-cluster [NDBD] NodeId=5
# the IP of the THIRD SERVER (STORAGE NODE)
HostName=10.10.0.246
DataDir=/var/lib/mysql-cluster
# 3 MySQL Clients
# I personally leave this blank to allow rapid changes of the mysql clients;
# you can enter the hostnames of the above two servers here. I suggest you dont.
[MYSQLD]
[MYSQLD]
[MYSQLD]
#e4d of file
尝试启动
/usr/local/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
4. 安装数据节点
与第一个节点相同, 我们需要下载Mysql cluster包并且安装, 不同点在于我们不需要配置config.ini,而是需要配置/etc/my.cnf
#Options for mysqld process:
[MYSQLD]
ndbcluster
ndb-connectstring=10.10.0.243 #这里写上MGMD的地址
key_buffer = 512M
max_allowed_packet = 16M
sort_buffer_size = 512K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
thread_cache_size=1024
myisam_sort_buffer_size = 8M
memlock
sysdate_is_now
max-connections=2000
thread-cache-size=64
query-cache-type = 0
query-cache-size = 0
table-open_cache=1024
table-cache=512
lower-case-table-names=0
#Options for ndbd process:
[MYSQL_CLUSTER]
ndb-connectstring=10.10.0.243
#end of file
启动ndb(第一次启动时需要加上–initial参数)
/usr/local/mysql/bin/ndbd
5. 安装启动mysqld(api)节点
同其他节点一样,首先下载安装mysql,完毕后使用
cp /usr/local/mysql/support-files/mysql.server /etc/init.d
chmod +x /etc/init.d/mysql.server
/etc/rc.d/init.d/mysql.server start
6. 检查运行情况,回到mgmd节点,使用
/usr/local/bin/ndb_mgm
连接到控制台, 使用
show
查看各个节点工作情况
Connected to Management Server at: 10.10.0.243:1186
Cluster Configuration
———————
[ndbd(NDB)] 3 node(s)
id=3 @10.10.0.244 (mysql-5.1.51 ndb-6.3.39, Nodegroup: 0, Master)
id=4 @10.10.0.245 (mysql-5.1.51 ndb-6.3.39, Nodegroup: 0)
id=5 @10.10.0.246 (mysql-5.1.51 ndb-6.3.39, Nodegroup: 0)
id=1 @10.10.0.243 (mysql-5.1.51 ndb-6.3.39)
id=2 (not connected, accepting connect from 10.10.0.247) [mysqld(API)] 3 node(s)
id=6 @10.10.0.243 (mysql-5.1.51 ndb-6.3.39)
id=7 @10.10.0.244 (mysql-5.1.51 ndb-6.3.39)
id=8 @10.10.0.245 (mysql-5.1.51 ndb-6.3.39)
这时候我们就可以使用任意的一个API节点连接查询数据库了,需要注意的是仅仅对于结构为NDBCLUSTER的表才会进入集群系统,否则只会停留在相应的节点上
下面我们要安装配置MySql Proxy实现负载均衡
