mysql cluster配置测试

本文详细介绍了如何在 Red Hat Enterprise Linux Server 5.4 上搭建 MySQL 集群,包括环境配置、网络拓扑架构、软件包安装、服务器配置文件介绍、启动管理节点和数据节点、数据同步测试及集群故障测试等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、测试环境介绍

<OS Version>Red Hat Enterprise Linux Server release 5.4<DATABASE Version> 5.1.63-ndb-7.1.24-cluster-gpl-log

二、网络拓扑架构图,建议将服务器更名,不要都用localhost,更改方法:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@server2 ~]# vi /etc/sysconfig/network  
  2. NETWORKING=yes  
  3. NETWORKING_IPV6=yes  
  4. HOSTNAME=server2.localdomain  
  5. GATEWAY=192.168.1.1  
  6.   
  7. [root@server2 ~]# vi /etc/hosts  
  8. # Do not remove the following line, or various programs  
  9. # that require network functionality will fail.  
  10. 127.0.0.1               server2.localdomain localhost  
  11. ::1             localhost6.localdomain6 localhost6  
三、软件包安装

redhat5.4的光盘是带了5.0的mysqlserver的,这里我们是做集群,建议不在系统安装的时候将数据库安装上去,否则必须卸载,按照官方文档的解释,mysql-max 相关文件在5.0不存在,可以通过进入mysql,然后show storage engine,查看数据库支持的引擎。

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">server1:MySQL-Cluster-gpl-management-7.1.24-1.rhel5.i386.rpm、MySQL-Cluster-gpl-server-7.1.24-1.rhel5.i386.rpm、MySQL-Cluster-gpl-tools-7.1.23-1.rhel5.i386.rpm</span>  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">server2、server3:MySQL-Cluster-gpl-clusterj-7.1.24-1.rhel5.i386.rpm、MySQL-Cluster-gpl-extra-7.1.23-1.rhel5.i386.rpm、MySQL-Cluster-gpl-server-7.1.24-1.rhel5.i386.rpm、MySQL-Cluster-gpl-storage-7.1.23-1.rhel5.i386.rpm、MySQL-Cluster-gpl-tools-7.1.23-1.rhel5.i386.rpm、MySQL-Cluster-gpl-client-7.1.28-1.rhel5.i386.rpm</span>  

四、服务器配置文件介绍

server1:

/var/lib/mysql-cluster/config.ini  --管理节点配置文件

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [NDB_MGMD DEFAULT]  
  2. Portnumber=1186  
  3.   
  4. [NDB_MGMD]  
  5. NodeId=2  
  6. HostName=192.168.1.72  
  7. DataDir=/var/lib/mysql-cluster/  
  8. Portnumber=1186  
  9.   
  10. [TCP DEFAULT]  
  11. SendBufferMemory=4M  
  12. ReceiveBufferMemory=4M  
  13.   
  14. [NDBD DEFAULT]  
  15.   
  16. [NDBD]  
  17. NodeId=3  
  18. HostName=192.168.1.73  
  19. DataDir=/var/lib/mysql/  
  20.   
  21. [NDBD]  
  22. NodeId=1  
  23. HostName=192.168.1.71  
  24. DataDir=/var/lib/mysql/  
  25.   
  26. [MYSQLD DEFAULT]  
  27. [mysqld]  
  28. hostname=192.168.1.73  
  29. [mysqld]  
  30. hostname=192.168.1.71  
  31. [mysqld]  

/usr/sbin/ndb.mgmd --管理节点启动程序

/usr/bin/ndb_mgm  --管理节点管理程序

server2、server3:

/etc/my.cnf --mysql数据库配置文件

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [client]  
  2. #password       = your_password  
  3. port            = 3306  
  4. socket          = /var/lib/mysql/mysql.sock  
  5.   
  6. # Here follows entries for some specific programs  
  7. [mysql_cluster]  
  8. ndb-connectstring="192.168.1.72:1186"  
  9. # The MySQL server  
  10. [mysqld]  
  11. #port           = 3306  
  12. #socket         = /var/lib/mysql/mysql.sockndbcluster  
  13. ndb-connectstring="192.168.1.72:1186"  
  14. default-storage-engine=ndbcluster  

ps 做集群无需从将/usr/share/mysql/my-medium.cnf 复制到/etc/my.cnf,具体原因待分析

下面介绍几种常见的错误:

1、Unable to connect with connect string: nodeid=0,localhost:1186  Retrying every 5 seconds. Attempts left: 2 1, failed.

可能原因:软件包安装错误(多装或者是少装都会出错);config.ini或者my.cnf配置文件有误;

2、Unable to connect with connect string: nodeid=0,192.168.1.102:1186   Retrying every 5 seconds. Attempts left: 12 11 10 9 8 7 6 5 4 3 2 1, failed.

可能原因:防火墙开启,阻止集群数据通信;selinux开启,可以通过setenforce  0 关闭;

3、启动管理节点,sql节点连接失败

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@server1 pub]# ndb_mgm  
  2. -- NDB Cluster -- Management Client --  
  3. ndb_mgm> show  
  4. Connected to Management Server at: localhost:1186  
  5. Cluster Configuration  
  6. ---------------------  
  7. [ndbd(NDB)]     2 node(s)  
  8. id=1 (not connected, accepting connect from 192.168.1.71)  
  9. id=3 (not connected, accepting connect from 192.168.1.73)  
  10.   
  11. [ndb_mgmd(MGM)] 1 node(s)  
  12. id=2    @192.168.1.72  (mysql-5.1.63 ndb-7.1.24)  
  13.   
  14. [mysqld(API)]   4 node(s)  
  15. id=50 (not connected, accepting connect from 192.168.1.73)  
  16. id=51 (not connected, accepting connect from 192.168.1.71)  
  17. id=52 (not connected, accepting connect from any host)  
  18. id=53 (not connected, accepting connect from any host)  
可能原因:数据节点的配置文件有多余的选项,例如:在[sqld]下面多了这两行:
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [mysqld]  
  2. port            = 3306  
  3. socket          = /var/lib/mysql/mysql.sock  

五、启动管理节点和数据节点

(1)准备工作:关闭防火墙:service iptables stop;关闭selinux:setenforce 0;

server1上面启动管理节点  ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial;在server2和server3上面启动数据节点  ndbd

(2)进入管理程序,查看节点连接情况:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ndb_mgm> show  
  2. Cluster Configuration  
  3. ---------------------  
  4. [ndbd(NDB)]     2 node(s)  
  5. id=1    @192.168.1.71  (mysql-5.1.63 ndb-7.1.23, Nodegroup: 0, Master)  
  6. id=3    @192.168.1.73  (mysql-5.1.63 ndb-7.1.23, Nodegroup: 0)  
  7.   
  8. [ndb_mgmd(MGM)] 1 node(s)  
  9. id=2    @192.168.1.72  (mysql-5.1.63 ndb-7.1.24)  
  10.   
  11. [mysqld(API)]   3 node(s)  
  12. id=4    @192.168.1.73  (mysql-5.1.63 ndb-7.1.24)  
  13. id=5    @192.168.1.71  (mysql-5.1.63 ndb-7.1.24)  
  14. id=6 (not connected, accepting connect from any host)  

六、测试数据同步

(1)server2上创建表

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> create table t1 (  id tinyint auto_increment primary key,  name varchar(10),  password   
  2. varchar(20),  others varchar(30) ) ;   
  3. Query OK, 0 rows affected (0.26 sec)  
  4. mysql> desc t1;  
  5. +----------+-------------+------+-----+---------+----------------+  
  6. | Field    | Type        | Null | Key | Default | Extra          |  
  7. +----------+-------------+------+-----+---------+----------------+  
  8. | id       | tinyint(4)  | NO   | PRI | NULL    | auto_increment |  
  9. | name     | varchar(10) | YES  |     | NULL    |                |  
  10. | password | varchar(20) | YES  |     | NULL    |                |  
  11. | others   | varchar(30) | YES  |     | NULL    |                |  
  12. +----------+-------------+------+-----+---------+----------------+  
  13. 4 rows in set (0.01 sec)  
(2)server3上面插入数据
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> desc t1;  
  2. +----------+-------------+------+-----+---------+----------------+  
  3. | Field    | Type        | Null | Key | Default | Extra          |  
  4. +----------+-------------+------+-----+---------+----------------+  
  5. | id       | tinyint(4)  | NO   | PRI | NULL    | auto_increment |  
  6. | name     | varchar(10) | YES  |     | NULL    |                |  
  7. | password | varchar(20) | YES  |     | NULL    |                |  
  8. | others   | varchar(30) | YES  |     | NULL    |                |  
  9. +----------+-------------+------+-----+---------+----------------+  
  10. 4 rows in set (0.03 sec)  
  11.   
  12. mysql> insert into t1 values ('','forilen','password','administrator');  
  13. Query OK, 1 row affected, 1 warning (0.01 sec)  
(3)server2上面查询数据
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> select * from t1;  
  2. +----+---------+----------+---------------+  
  3. | id | name    | password | others        |  
  4. +----+---------+----------+---------------+  
  5. |  1 | forilen | password | administrator |  
  6. +----+---------+----------+---------------+  
  7. 1 row in set (0.00 sec)  
七、集群故障测试

(1)拔掉server3的网线,查看管理节点情况

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ndb_mgm> show  
  2. Cluster Configuration  
  3. ---------------------  
  4. [ndbd(NDB)]     2 node(s)  
  5. id=1 (not connected, accepting connect from 192.168.1.71)  
  6. id=3    @192.168.1.73  (mysql-5.1.63 ndb-7.1.23, Nodegroup: 0, Master)  
  7.   
  8. [ndb_mgmd(MGM)] 1 node(s)  
  9. id=2    @192.168.1.72  (mysql-5.1.63 ndb-7.1.24)  
  10.   
  11. [mysqld(API)]   3 node(s)  
  12. id=4    @192.168.1.73  (mysql-5.1.63 ndb-7.1.24)  
  13. id=5 (not connected, accepting connect from 192.168.1.71)  
  14. id=6 (not connected, accepting connect from any host)  
(2)server3已经断开,往server2中插入数据
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. +---------+------+------------------------------------------------------+  
  2. | Level   | Code | Message                                              |  
  3. +---------+------+------------------------------------------------------+  
  4. | Warning | 1366 | Incorrect integer value: '' for column 'id' at row 1 |  
  5. +---------+------+------------------------------------------------------+  
  6. 1 row in set (0.00 sec)  
  7.   
  8. mysql> select * from t1;  
  9. +----+---------+----------+---------------+  
  10. | id | name    | password | others        |  
  11. +----+---------+----------+---------------+  
  12. |  3 | xiaohu  | password | xiaohu        |  
  13. |  1 | forilen | password | administrator |  
  14. |  2 | xiaoli  | pwd      | user1         |  
  15. +----+---------+----------+---------------+  
  16. 3 rows in set (0.00 sec)  
(3)插上server3的网线,查看数据
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@server3 ~]# ndbd  
  2. 2013-12-05 11:09:09 [ndbd] INFO     -- Angel connected to '192.168.1.72:1186'  
  3. 2013-12-05 11:09:09 [ndbd] INFO     -- Angel allocated nodeid: 1  
(4)查看server1的管理节点连接情况
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ndb_mgm> show  
  2. Cluster Configuration  
  3. ---------------------  
  4. [ndbd(NDB)]     2 node(s)  
  5. id=1    @192.168.1.71  (mysql-5.1.63 ndb-7.1.23, starting, Nodegroup: 0)  
  6. id=3    @192.168.1.73  (mysql-5.1.63 ndb-7.1.23, Nodegroup: 0, Master)  
  7.   
  8. [ndb_mgmd(MGM)] 1 node(s)  
  9. id=2    @192.168.1.72  (mysql-5.1.63 ndb-7.1.24)  
  10.   
  11. [mysqld(API)]   3 node(s)  
  12. id=4    @192.168.1.73  (mysql-5.1.63 ndb-7.1.24)  
  13. id=5    @192.168.1.71  (mysql-5.1.63 ndb-7.1.24)  
  14. id=6 (not connected, accepting connect from any host)  
(5)查看server3上面数据同步情况
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> use test;  
  2. Database changed  
  3. mysql> select * from t1;  
  4. +----+---------+----------+---------------+  
  5. | id | name    | password | others        |  
  6. +----+---------+----------+---------------+  
  7. |  3 | xiaohu  | password | xiaohu        |  
  8. |  1 | forilen | password | administrator |  
  9. |  2 | xiaoli  | pwd      | user1         |  
  10. +----+---------+----------+---------------+  
  11. 3 rows in set (0.00 sec)  

数据已经同步,集群搭建完毕,具体详细参数下文分析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值