手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL Cluster7.4.12分布式集群搭建

[日期:2016-08-25] 来源:Linux社区  作者:alfer [字体: ]

集群规划:

节点 IP ADDRESS
Management Server (ndb_mgmd) 192.168.6.203
data nodes (ndbd)

192.168.6.204

192.168.6.205

SQL node (MySQLd)

192.168.6.204

192.168.6.205

Mysql Cluster版本:

MySQL Cluster NDB 7.4.12 (5.6.31-ndb-7.4.12),

下载地址: http://dev.mysql.com/downloads/cluster/

集群部署:

1、环境清理及安装:

如果已经存在mysql相关的安装或者依赖包,则先清理mysql的相关安装和依赖

检查mysql是否存在mysql相关依赖包:

1
rpm -qa | grep mysql*

如存在:mysql-libs-5.1.66-2.el6_3.x86_64

则卸载mysql并删除依赖:

1
2
3
yum -y remove mysql
rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64
......

2、集群安装:

管理节点: 

192.168.6.203 

1
rpm -ivh MySQL-Cluster-server-gpl-7.4.12-1.el6.x86_64.rpm

数据节点 和 mysql server: 

192.168.6.204

192.168.6.205

1
2
rpm -ivh MySQL-Cluster-server-gpl-7.4.12-1.el6.x86_64.rpm
rpm -ivh MySQL-Cluster-client-gpl-7.4.12-1.el6.x86_64.rpm

配置文件:

管理节点配置文件:

在192.168.6.203上创建  /var/lib/mysql-cluster/config.ini ,内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[NDB_MGMD DEFAULT] 
Portnumber=1186 
    
[NDB_MGMD] 
NodeId=10 
HostName=192.168.6.203 
DataDir=/var/lib/mysql-cluster/ 
Portnumber=1186 
    
[TCP DEFAULT] 
SendBufferMemory=4M 
ReceiveBufferMemory=4M 
    
[NDBD DEFAULT] 
NoOfReplicas=2    # Number of replicas
DataMemory=800M    # How much memory to allocate for data storage
IndexMemory=100M   # How much memory to allocate for index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example Cluster setup.
    
[NDBD] 
NodeId=20 
HostName=192.168.6.204 
DataDir=/var/lib/mysql/ 
    
[NDBD]
NodeId=21
HostName=192.168.6.205
DataDir=/var/lib/mysql/
  
[MYSQLD DEFAULT] 
[mysqld] 
hostname=192.168.6.204
[mysqld] 
hostname=192.168.6.205

数据节点和mysqld节点:

在192.168.6.20[4,5]上分别创建/etc/my.cnf

1
2
3
4
5
6
7
8
[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine
ndb-connectstring="192.168.6.203:1186"
  
[mysql_cluster]
# # Options for MySQL Cluster processes:
ndb-connectstring="192.168.6.203:1186"  # location of management server

3、启动集群:

准备工作:集群每台机器 关闭防火墙;设置selinux的SELINUX=disabled;

先启动管理节点:

192.168.6.203上启动管理节点:

1
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial

再启动数据节点:

192.168.6.20[4,5]上启动数据节点:

1
ndbd

最后192.168.6.20[4,5]启动mysqld服务:

1
mysqld_safe --user=mysql &

通过管理节点,查看节点连接状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
shell>  ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.6.203:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=20  @192.168.6.204  (mysql-5.6.31 ndb-7.4.12, Nodegroup: 0, *)
id=21  @192.168.6.205  (mysql-5.6.31 ndb-7.4.12, Nodegroup: 0)
  
[ndb_mgmd(MGM)] 1 node(s)
id=10  @192.168.6.203  (mysql-5.6.31 ndb-7.4.12)
  
[mysqld(API)]  2 node(s)
id=22  @192.168.6.204  (mysql-5.6.31 ndb-7.4.12)
id=23  @192.168.6.205  (mysql-5.6.31 ndb-7.4.12)
  
ndb_mgm>

看到上面的状况,则说明集群启动成功。

进入mysqld,查看mysql是否已经支持分布式存储引擎ndbcluster

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
shell> mysql -uroot -p
mysql> set password=password('xxxxxx'# 第一次登陆需要修改root 用户的登录密码
mysql> show engines\g;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | YES     | Clustered, fault-tolerant tables                               | YES          | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| ndbinfo            | YES     | MySQL Cluster system information storage engine                | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
11 rows in set (0.00 sec)

4、测试数据同步:

在192.168.6.204上创建一张t2表:

1
2
3
4
5
6
7
8
9
10
11
12
mysql> use test;
Database changed
mysql> create table t2(id intname varchar(20)) engine=ndbcluster;
Query OK, 0 rows affected (0.10 sec)
mysql> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null Key Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
name  varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
rows in set (0.00 sec)

在192.168.6.205上向表t2插入一条数据:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null Key Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
name  varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
rows in set (0.00 sec)
mysql> insert into t2 values(1,'lisan');
Query OK, 1 row affected (0.00 sec)
  
mysql> select from t2;
+------+-------+
| id   | name  |
+------+-------+
|    1 | lisan |
+------+-------+
1 row in set (0.00 sec)

在204上查看t2表:

1
2
3
4
5
6
7
mysql> select from t2;
+------+-------+
| id   | name  |
+------+-------+
|    1 | lisan |
+------+-------+
1 row in set (0.00 sec)

看到上面结果,则说明分布式mysql数据同步成功。

安装过程中遇到的问题:

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 关闭;

Ubuntu下MySQL Cluster安装和配置  http://www.linuxidc.com/Linux/2016-04/130100.htm

MySQL集群之MySQL Cluster  http://www.linuxidc.com/Linux/2016-04/130099.htm

MySQL Cluster 备份与恢复 http://www.linuxidc.com/Linux/2013-06/85295.htm

MySQL Cluster安装配置 http://www.linuxidc.com/Linux/2013-07/87705.htm

MySQL Cluster 3台机器搭建集群环境 DOC http://www.linuxidc.com/Linux/2013-01/78249.htm

MySQL Cluster7.2在线增加数据节点存在重大弊端 http://www.linuxidc.com/Linux/2012-08/67605.htm

MySQL Cluster 的详细介绍请点这里
MySQL Cluster 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-08/134593.htm

linux
相关资讯       MySQL Cluster  MySQL Cluster集群 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款