※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
RedHat as4,as5 上MySQL双机集群
【1】安装gcc、g++
[root@hui ~]# mount /dev/cdrom /media/
[root@hui ~]# cd /media/RedHat/RPMS/
[root@hui RPMS]# rpm -ivh gcc-3.4.6-8.i386.rpm
glibc-devel-2.3.4-2.36.i386.rpm
glibc-headers-2.3.4-2.36.i386.rpm
glibc-kernheaders-2.4-9.1.100.EL.i386.rpm
gcc-c++-3.4.6-8.i386.rpm
libstdc++-devel-3.4.6-8.i386.rpm
【2】安装MySQL-Cluster
[root@yan share]# rpm -ivh MySQL-Cluster-gpl-server-6.3.20-0.rhel4.i386.rpm
[root@yan share]# rpm -ivh MySQL-Cluster-gpl-client-6.3.20-0.rhel4.i386.rpm
[root@yan share]# rpm -ivh MySQL-Cluster-gpl-extra-6.3.20-0.rhel4.i386.rpm
[root@yan share]# rpm -ivh MySQL-Cluster-gpl-tools-6.3.20-0.rhel4.i386.rpm
My[root@yan share]# rpm -ivh MySQL-Cluster-gpl-storage-6.3.20-0.rhel4.i386.rpm
My[root@yan share]# rpm -ivh MySQL-Cluster-gpl-management-6.3.20-0.rhel4.i386.rpm
【3】配置文件
1.节点文件配置
cd /var/lib/mysql-cluster
vi config.ini
在config.ini中添加如下内容:
NoOfReplicas=2
MaxNoOfConcurrentOperations=10000
DataMemory=80M
IndexMemory=24M
TimeBetweenWatchDogCheck=30000
DataDir=/var/lib/mysql-cluster
MaxNoOfOrderedIndexes=512
StartPartialTimeout=100
StartPartitionedTimeout=100
ArbitrationTimeout=5000
TransactionDeadlockDetectionTimeout=5000
HeartbeatIntervalDbDb=5000
StopOnError=0
[ndb_mgmd default]
DataDir=/var/lib/mysql-cluster
[ndb_mgmd]
Id=1
HostName=192.168.10.100
[ndb_mgmd]
Id=2
HostName=192.168.10.200
[ndbd]
Id=3
HostName=192.168.10.100
[ndbd]
Id=4
HostName=192.168.10.200
[mysqld]
ArbitrationRank=2
[mysqld]
ArbitrationRank=2
[tcp default]
[root@hui ~]# vi /etc/my.cnf
[mysqld]
default-storage-engine=ndbcluster
ndbcluster
ndb-connectstring=192.168.10.100,192.168.10.200
[ndbd]
connect-string=192.168.10.100,192.168.10.200
[ndb_mgm]
connect-string=192.168.10.100,192.168.10.200
[ndb_mgmd]
config-file=/var/lib/mysql-cluster/config.ini
[mysql_cluster]
ndb-connectstring=192.168.10.100,192.168.10.200
 
 
启动管理(MGM)节点:
这类节点的作用是管理MySQL簇内的其他节点,
如提供配置数据、启动并停止节点、运行备份等。由于这类节点
负责管理其他节点的配置,应在启动其他节点之前首先启动这类
节点。
[root@yan mysql-cluster]# ndb_mgmd --ndb_nodeid=1
Warning line 35: Cluster configuration warning:
  arbitrator with id 1 and db node with id 3 on same host 192.168.10.100
  arbitrator with id 2 and db node with id 4 on same host 192.168.10.200
  arbitrator with id 5 has no hostname specified
  arbitrator with id 6 has no hostname specified
  Running arbitrator on the same host as a database node may
  cause complete cluster shutdown in case of host failure.
[root@hui mysql-cluster]# ndb_mgmd --ndb_nodeid=2
启动数据节点(ndbd):
这类节点用于保存簇的数据。数据节点的数目与副本的数目相关,
是片段的倍数。例如,对于两个副本,每个副本有两个片段,那么
就有4个数据节点。
[root@yan mysql-cluster]# ndbd --connect-string="nodeid=3;host=192.168.10.100:1186"
[root@hui mysql-cluster]# ndbd --connect-string="nodeid=4;host=192.168.10.200:1186"
启动SQL节点(mysqld):
这是用来访问簇数据的节点。对于MySQL簇,客户端节点是使用NDB
簇存储引擎的传统MySQL服务器。典型情况下,SQL节点是使用命令
mysqld –ndbcluster启动的,或将ndbcluster添加到my.cnf后使用
mysqld启动。
[root@yan mysql-cluster]# mysqld_safe --ndb_nodeid=5 --user=mysql &
[root@hui mysql-cluster]# mysqld_safe --ndb_nodeid=6 --user=mysql &
在一个节点上建立数据库
[root@yan ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.30-ndb-6.3.20-cluster-gpl MySQL Cluster Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database yan;
Query OK, 1 row affected (0.23 sec)
mysql> use yan;
Database changed
mysql> create table hui(id int,name varchar(20));
Query OK, 0 rows affected (1.11 sec)
mysql>
在另一个节点上查看
[root@hui ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.30-ndb-6.3.20-cluster-gpl MySQL Cluster Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use yan;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select *from hui;
Empty set (0.01 sec)
mysql>
出现以上结果证明成功了
集群的停止
[root@yan mysql-cluster]# ndb_mgm -e shutdown
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※