阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

MySQL Cluster7.4.12分布式集群搭建

127次阅读
没有评论

共计 6696 个字符,预计需要花费 17 分钟才能阅读完成。

集群规划:

节点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

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计6696字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中