环境:Vmware workstation6.5操作系统:Centos 5.2 (2台)第一台:主机名:mysql1 IP: 192.168.1.30第二台主机名:mysql2 IP: 192.168.1.32软件下载安装下载软件地址:http://dev.mysql.com/downloads/select.php?id=14 选择操作系统是RedHat Enterprise 版本如下:MySQL-Cluster-gpl-client-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-debuginfo-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-devel-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-embedded-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-extra-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-management-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-server-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-shared-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-storage-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-test-7.0.8a-0.rhel5.i386.rpmMySQL-Cluster-gpl-tools-7.0.8a-0.rhel5.i386.rpm将软件包上传到服务器Rpm –ivh *.rpm具体配置 在两台机器上做(同样的配置文件)1、创建配置文件目录:( mysql1 mysql2)#mkdir /var/lib/mysql-cluster –p在/var/lib/mysql-cluster 下创建集群配置文件config.ini编辑,添加如下内容:[NDBD DEFAULT]NoOfReplicas=2DataMemory=128MIndexMemory=64MMaxNoOfConcurrentOperations=2000000[MYSQLD DEFAULT][NDB_MGMD DEFAULT]DataDir= /var/lib/mysql-cluster[TCP DEFAULT]# Section for the cluster management node[NDB_MGMD]# IP address of the management node (this system)ID=1HostName= 192.168.1.30[NDB_MGMD]# IP address of the management node (this system)ID=2HostName= 192.168.1.32# Section for the storage nodes[NDBD]ID=3# IP address of the first storage nodeHostName=192.168.1.30[NDBD]ID=4# IP address of the second storage nodeHostName=192.168.1.32# one [MYSQLD] per storage node[MYSQLD][MYSQLD][MYSQLD][MYSQLD][MYSQLD][MYSQLD][MYSQLD]2、创建API文件( mysql1 mysql2)编辑/etc/my.cnf 添加如下内容:[mysqld]default-storage-engine=ndbclusterlog=queryLoglog-slow-queries=slowquerylogmax_connections = 1000#NDBCLUSTERndbclusterndb-connectstring = 192.168.1.30,192.168.1.32[ndb_mgm]connect-string = 192.168.1.30,192.168.1.32[ndbd]connect-string = 192.168.1.30,192.168.1.32[mysql_cluster]ndb-connectstring= 192.168.1.30,192.168.1.32[ndb_mgmd]config-file=/var/lib/mysql-cluster/config.ini集群的启动:启动管理节点在mysql1 上 启动管理节点# ndb_mgmd –ndb_nodeid=1在mysql2上启动管理节点# ndb_mgmd –ndb_nodeid=2第一次会有警告:Cluster configuration warning:arbitrator with id 1 and db node with id 3 on same host 192.168.1.30arbitrator with id 2 and db node with id 4 on same host 192.168.1.32Running arbitrator on the same host as a database node maycause complete cluster shutdown in case of host failure.是说:节点1和3,2和4的arbitrator一样,可能引起整个集群失败 这个无所谓,继续启动NDB 在mysql1 上运行:# ndbd –nodeid=3 –initial在mysql2上运行:# ndbd –nodeid=4 –iniitial注意:在第一次启动ndb或者修改了config.ini 文件才加上-initiail 参数查看状态:在任意一台机器上查看:[root@mysql1 ~]# ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 192.168.1.30:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=5 @192.168.1.30 (mysql-5.1.37 ndb-7.0.8, Nodegroup: 0, Master)id=6 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8, Nodegroup: 0)[ndb_mgmd(MGM)] 2 node(s)id=1 @192.168.1.30 (mysql-5.1.37 ndb-7.0.8)id=2 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8)[mysqld(API)] 9 node(s)id=7 (not connected, accepting connect from any host)id=8 (not connected, accepting connect from any host)id=9 (not connected, accepting connect from any host)id=10 (not connected, accepting connect from any host)id=11 (not connected, accepting connect from any host)id=12 (not connected, accepting connect from any host)id=13 (not connected, accepting connect from any host)id=14 (not connected, accepting connect from any host)id=15 (not connected, accepting connect from any host)看到上面的信息就正常了启动API在mysql1中:#mysqld_safe –ndb_nodeid=5 –user=mysql &在mysql2 中:#mysqld_safe –ndb_nodeid=6 –user=mysql &再次查看:[root@mysql1 ~]# ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 192.168.1.30:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=5 @192.168.1.30 (mysql-5.1.37 ndb-7.0.8, Nodegroup: 0, Master)id=6 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8, Nodegroup: 0)[ndb_mgmd(MGM)] 2 node(s)id=1 @192.168.1.30 (mysql-5.1.37 ndb-7.0.8)id=2 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8)[mysqld(API)] 9 node(s)id=7 @192.168.1.30 (mysql-5.1.37 ndb-7.0.8)id=8 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8)id=9 (not connected, accepting connect from any host)id=10 (not connected, accepting connect from any host)id=11 (not connected, accepting connect from any host)id=12 (not connected, accepting connect from any host)id=13 (not connected, accepting connect from any host)id=14 (not connected, accepting connect from any host)id=15 (not connected, accepting connect from any host)显示两个API节点 正常集群测试在mysql1中创建库# /usr/local/mysql/bin/mysql -u root -pmysql >create database love;mysql > use love;mysql > create table love (i INT) mysql > insert into love () VALUES (1);在mysql2上查询:mysql > select * from love;mysql> show tables;+----------------+| Tables_in_love |+----------------+| love | +----------------+1 row in set (0.03 sec)mysql> select * from love;+------+| i |+------+| 1 | +------+1 row in set (0.08 sec)已经同步:下面我将mysql1 停掉网卡:看一下状态:[root@mysql2 ~]# ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 192.168.1.32:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=5 (not connected, accepting connect from 192.168.1.30)id=6 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8, Nodegroup: 0, Master)[ndb_mgmd(MGM)] 2 node(s)id=1 (not connected, accepting connect from 192.168.1.30)id=2 @192.168.1.32 (mysql-5.1.37 ndb-7.0.8)[mysqld(API)] 9 node(s)id=7 (not connected, accepting connect from any host)id=8 (not connected, accepting connect from any host)id=9 (not connected, accepting connect from any host)id=10 (not connected, accepting connect from any host)id=11 (not connected, accepting connect from any host)id=12 (not connected, accepting connect from any host)id=13 (not connected, accepting connect from any host)id=14 (not connected, accepting connect from any host)id=15 (not connected, accepting connect from any host)mysql2 对外提供服务成为主服务器看能否查询:mysql> select * from love;ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTERmysql> select * from love;ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTER暂时不能查询,出现错误:稍等片刻再次查询,没有错误,这段时间是故障转移,时间不是很长具体时间没计算在mysql2 上创建 表:mysql > create table love1 (i INT) mysql > insert into love1 () VALUES (1);接下来将mysql1的网卡启动在mysql1上查询数据:[root@mysql1 ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.1.37-ndb-7.0.8a-cluster-gpl-log MySQL Cluster Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use love;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables ;+----------------+| Tables_in_love |+----------------+| love | | love1 | +----------------+2 rows in set (0.01 sec)mysql> select * from love1;+------+| i |+------+| 1 | +------+1 row in set (0.00 sec)可以看到在mysql2上创建的表love2正常运行但是mysql1成为主服务器,这个怎么改变过来,还不清楚The end !
本文转自andylhz 51CTO博客,原文链接:http://blog.51cto.com/andylhz2009/213666,如需转载请自行联系原作者