1、安装管理节点:192.168.100.1
(1)把mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz解压到/usr/local/myql下
(2)在mysql目录下创建文件夹:mkdir /usr/local/myql/mysql-cluster
(3)在mysql目录下创建文件夹:mkdir /usr/local/myql/cluster-conf
(4)编辑config.ini文件:vi /usr/local/mysql/cluster-conf/config.ini内容如下:
[ndbd default]
NoOfReplicas=2
DataMemory=200M
IndexMemory=100M
[ndb_mgmd]
id=1
hostname=192.168.100.1
DataDir=/usr/local/mysql/mysql-cluster
[ndbd]
id=2
HostName=192.168.100.4
DataDir=/usr/local/mysql/ndbdata
[ndbd]
id=5
HostName=192.168.100.5
DataDir=/usr/local/mysql/ndbdata
[mysqld]
id=6
HostName=192.168.100.2
[mysqld]
id=7
HostName=192.168.100.3
2、安装SQL节点 192.168.100.4 & 192.168.100.5
(1)把mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz解压到/usr/local/myql下
(2)添加mysql用户
groupadd mysql
useradd -g mysql mysql
(3)添加权限
chown -R mysql:mysql /usr/local/mysql
(4)拷贝配置文件
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
(5)初始化数据库
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql
(6)拷贝守护进程所需文件
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
(7)配置守护进程
chkconfig –add mysqld
chkconfig –level 35 mysqld on
(8)更改配置文件vi /etc/my.cnf内容如下:
[mysqld]
port = 3306
socket = /tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.100.1 #管理节点的IP
3、安装数据节点
(1)把mysql-cluster-gpl-7.2.8-linux2.6-x86_64.tar.gz解压到/usr/local/mysql 下
(2)在mysql目录下创建文件:mkdir /usr/local/mysql/ndbdata
(3)编辑my.cnf: vi /etc/my.cnf在文件末尾添加如下内容:
[mysql_cluster]
ndb-connectstring=192.168.100.1 #管理节点IP
4、配置环境变量:
#config mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
5、启动集群
启动顺序:管理服务器->存储节点->SQL节点
(1)启动管理节点
rm mysql/mysql-cluster/ndb_1_config.bin.1 #如果config.ini有改动则要加上
ndb_mgmd -f /usr/local/mysql/cluster-conf/config.ini
(2)启动存储节点
ndbd --initial #(第一次启动必须添加选项)
ndbd #不是第一次启动需要执行的命令
(3)启动SQL节点
/etc/rc.d/init.d/mysqld start 或service mysqld start
6、关闭集群
(1)关闭SQL节点
/etc/rc.d/init.d/mysqld stop 或service mysqld stop
(2)关闭管理节点
ndb_mgm〉shutdown
7、验证配置的正确性
在管理节点执行:ndb_mgm -> show
8、创建表
创建表需要以 ndbcluster作为存储引擎
CREATE TABLE `test`.`test` (
`id` VARCHAR(45) NOT NULL,
`name` VARCHAR(9),
PRIMARY KEY (`id`)
) ENGINE = ndbcluster;
参考:http://www.cnblogs.com/bigshuai/archive/2012/02/29/2373865.html