节点1:192.168.50.8
节点2:192.168.50.23
管理节点:192.168.50.38
1.配置管理节点#sudo vi /etc/mysql/my.cnf
[MYSQLD]
ndbcluster
ndb-connectstring = 192.168.50.38
[MYSQL_CLUSTER]
ndb-connectstring = 192.168.50.38
编辑/etc/mysql/ndb_mgmd.cnf如果没有就复制一份
#sudo cp /usr/share/doc/mysql-server-5.0/examples/ndb_mgmd.cnf /etc/mysql
#sudo vi /etc/mysql/ndb_mgmd.cnf
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=10MB
IndexMemory=25MB
MaxNoOfTables=256
MaxNoOfOrderedIndexes=256
MaxNoOfUniqueHashIndexes=128
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
[NDB_MGMD]
Id=1
HostName=192.168.50.38
DataDir = /var/lib/mysql-cluster
[NDBD]
Id=2
HostName=192.168.50.8
DataDir= /var/lib/mysql-cluster
[NDBD]
Id=3
HostName=192.168.50.23
DataDir=/var/lib/mysql-cluster
[MYSQLD]
Id=4
HostName=192.168.50.38
[MYSQLD]
Id=5
HostName=192.168.50.8
[MYSQLD]
Id=6
HostName=192.168.50.23
[b]2.配置其他集群节点[/b]#sudo vi /etc/mysql/my.cnf
[MYSQLD]
ndbcluster
ndb-connectstring = 192.168.50.38
[MYSQL_CLUSTER]
ndb-connectstring = 192.168.50.38
3.编辑完成后1.管理节点
sudo /etc/init.d/mysql-ndb-mgm start
2.在其他集群节点
sudo /etc/init.d/mysql-ndb start
3.启动各个节点的mysql服务
验证:在管理节点运行
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.50.38:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.50.8 (Version: 5.0.75, Nodegroup: 0, Master)
id=3 @192.168.50.23 (Version: 5.0.75, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.50.38 (Version: 5.0.75)
[mysqld(API)] 3 node(s)
id=4 @192.168.50.38 (Version: 5.0.75)
id=5 @192.168.50.8 (Version: 5.0.75)
id=6 @192.168.50.23 (Version: 5.0.75)
表示配置成功
4.创建表
表的创建使用存储引擎必须是ndbcluster
eg:
create table users(
id int not null auto_increment,
username varchar(200) not null,
primary key(id)
)engine = ndbcluster default charset utf8;
要在其他节点看不到当前表所在的数据库,不需自行创建数据库后表才能同步;