mysql集群的配置

最近在 学习MYSQL集群的配置,首先要了解什么集群,为什么要使用集群,以及安装集群的软件是什么和集群中的进程有哪些。

  1.什么是集群?

集群是一组服务器提供相同的服务。

2.为什么要使用集群?

解决单点故障和数据的备份问题。

操作系统以及mysql配置文件的说明。

Linux系统:redhat6.5

安装集群软件: MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar

服务器的角色:

实验要求:5台服务器,分别ip地址192.168.1.10做管理节点,192.168.1.20/192.168.1.30做数据节点使数据能够同时备份当其中任意一台服务器宕机后,对数据库进行操作,当宕机的服务器恢复后自动同步数据,192.168.1.40/192.168.1.50做sql节点当任意一台mysql节点故障后,都可以登陆数据库。

192.168.1.10(mgmd)

192.168.1.20(ndbd)

192.168.1.30 (ndbd)

192.168.1.40 (sql)

192.168.1.50 (sql)
一。在所有服务器上安装提供集群服务的软件 mysql-cluster (.rpm  源码)

最简单是的PRM包,下面采用二进制包的方法进行安装

1.解压软件包。

[[email protected] opt]# tar -xvf MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar
2.安装软件包,tar解压出来的是rpm包,直接安装就可以。

[[email protected] opt]# rpm  -Uvh  MySQL-Cluster-*.rpm

3.查看软件包是否已安装。

[[email protected] opt]# rpm -qa | grep -i mysql

MySQL-Cluster-shared-compat-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-devel-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-embedded-gpl-7.3.3-1.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
MySQL-Cluster-test-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-server-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-client-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-shared-gpl-7.3.3-1.el6.x86_64

4.在192.168.1.10上配置管理节点。

管理节点运行的是管理进程,运行时加载自己的主配置文件,主配置文件需要自己写。

例如:配置文件为config.ini   配置文件的内容包括:

1 数据节点的公共配置[ndbd  default]
  2 指定管理节点[ndb_mgmd]
  3 指定数据节点 [ndbd]
  4 指定sql节点  [mysqld]

[[email protected] ~]# vim /etc/config.ini

[ndbd  default]
NoOfReplicas=2 (表示数据节点的份数,有几个数据节点就写几)
DataMemory=80M  (表示数据缓存的大小)
IndexMemory=18M  (表示索引缓存的大小)
[ndb_mgmd]
nodeid=1  ( 用来设置当前主机在集群中的编号)
hostname=192.168.1.10  (指定管理节点的IP地址)
datadir=/var/log/mysql-cluster (指定把运行中的信息放在/var/log/mysql-cluster,这个文件夹   必须在系统中存在,如果没有创建该文件夹。)
[ndbd]
nodeid=2  (数据节点的编号)
hostname=192.168.1.20 (数据节点的IP地址)
datadir=/var/log/mysql-cluster/data  (存储数据的位置)
[ndbd]
nodeid=3
hostname=192.168.1.30
datadir=/var/log/mysql-cluster/data
[mysqld]
nodeid=4
hostname=192.168.1.40
[mysqld]
nodeid=5
hostname=192.168.1.50

在192.168.1.10创建/var/log/mysql-cluster文件夹

[[email protected] ~]# mkdir -p /var/log/mysql-cluster/

5.在192.168.1.20/192.168.1.30上配置数据节点

在192.168.1.20和192.168.1.30上 分别创建/var/log/mysql-cluster文件夹用来存储数据的位置

[[email protected] ~]# mkdir -p /var/log/mysql-cluster/
创建主配置文件。
 [[email protected] ~]# vim /etc/my.cnf
 [mysqld]
 datadir=/var/log/mysql-cluster/data   (指定数据库目录)
 ndb-connectstring=192.168.1.10   (指定连接管理集群的服务器IP)
 ndbcluster        (表的存储引擎必须是ndbcluster)
 [mysql_cluster]   ( 指定管理集群的机器)
 ndb-connectstring=192.168.1.10(指定谁来管理集群的服务器IP)

6.在192.168.1.40/192.168.1.50上配置sql节点
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
ndbcluster
default-storage-engine=ndbcluster     (指定默认的存储引擎)
ndb-connectstring=192.168.1.10 (指定连接管理集群的服务器IP)
[mysql_cluster]
ndb-connectstring=192.168.1.10 (指定谁来管理集群的服务器IP)

7.启动不同角色服务对应进程(有启动顺序,按照以下顺序进行启动)。
    1  启动管理进程在192.168.1.10上。
[[email protected] ~]# ndb_mgmd -f /etc/config/init        启动mysql cluster服务
MySQL Cluster Management Server mysql-5.6.14 ndb-7.3.3

[[email protected] ~]# netstat -anuptl | grep :1186       查看集群端口是否开启

tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      4341/ndb_mgmd
tcp        0      0 127.0.0.1:38177             127.0.0.1:1186              ESTABLISHED 4341/ndb_mgmd
tcp        0      0 127.0.0.1:1186              127.0.0.1:38177             ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.50:43075          ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.40:37459          ESTABLISHED 4341/ndb_mgmd

[[email protected] ~]# ndb_mgm          进入界面命令

-- NDB Cluster -- Management Client --
ndb_mgm> show                查看信息命令

Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 192.168.1.20)
id=3 (not connected, accepting connect from 192.168.1.30)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)
   2  启动192.168.1.20/192.168.1.30上的数据进程
   [[email protected] ~]# ndbd           在192.168.1.20启动数据进程的命令

2015-07-21 15:49:24 [ndbd] INFO     -- Angel connected to ‘192.168.1.10:1186‘
2015-07-21 15:49:24 [ndbd] INFO     -- Angel allocated nodeid: 2  3 
[[email protected] ~]# ndbd        在192.168.1.30启动数据进程的命令
2015-07-21 10:16:16 [ndbd] INFO     -- Angel connected to ‘192.168.1.10:1186‘
2015-07-21 10:16:16 [ndbd] INFO     -- Angel allocated nodeid: 3   service mysql start

3.启动完数据进程后在管理节点192.168.1.10上查看数据进程是否已经启动。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)

ndb_mgm> Node 2: Started (version 7.3.3)
Node 3: Started (version 7.3.3)
  4.在192.168.1.40/192.168.1.50启动mysql数据库服务。

[[email protected] ~]# service mysql start
Starting MySQL SUCCESS!

5.启动完mysql数据库服务后在管理节点192.168.1.10上查看mysql进程是否已经启动。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)

8.客户端测试
1.访问节点的单点故障。
在mysql 数据库服务上建表建库,进行查看。

登陆mysql服务器192.168.1.40/192.168.1.50

[[email protected]~]# cat /root/.mysql_secret
# The random password set for the root user at Mon Jul  6 04:54:27 2015 (local time): umdVqWxz
[[email protected] ~]# mysql -hlocalhost -uroot -pumdVqWxz

mysql>set password for [email protected]=password("123")

mysql>quit

[[email protected] ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server                                                (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved                                               .

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input stateme                                               nt.

查看存储引擎默认是不是dbcluster

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | DEFAULT | Clustered, fault-tolerant tables                               | YES          | NO   | NO         |

关闭192.168.1.50上的 mysql服务

[[email protected] ~]# service mysql stop
查看192.168.1.10上的信息

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5 (not connected, accepting connect from 192.168.1.50)

用192.168.1.40查看是否可以登陆数据库,如果可以登陆说明解决单点故障。

[[email protected] ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

2.数据节点单点故障。(关闭1个数据服务,在表中进行插入,查看等一些操作,当另外一个恢复服务后,看能不能进行同步数据,如果可以说明就解决单点故障)
验证数据节点单点故障的步骤:

1.关闭192.168.1.20的数据节点的服务。

[[email protected] ~]# pkill -9 ndbd

2. 查看管理节点的192.168.1.20的状态。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 192.168.1.20)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)

3.在sql节点上查看数据库的信息,当192.168.1.20宕机后查看的信息是192.168.1.30的信息。

在数据库上对表进行select ,insert into 等信息后,当192.168.1.30恢复后能不能同步数据,如果可以说明可以解决单点故障。

时间: 2024-07-28 21:11:42

mysql集群的配置的相关文章

mysql cluster (mysql 集群)安装配置方案(转)

一.准备 1.准备服务器 计划建立有5个节点的MySQL CLuster体系,需要用到5台服务器,但是我们做实验时没有这么多机器,可以只用2台,我就是一台本机,一台虚拟机搭建了有5个节点的MySQL CLuster体系,将一个SQL节点一个数据节点一个SQL节点放在了一台服务器上(192.168.1.252),将另一个SQL节点和一个数据节点放在了另外一台服务器上(192.168.1.52). 节点配置说明 节点 对应的IP和端口 管理节点(1个) 192.168.1.252 SQL节点 (2个

mysql cluster (mysql 集群)安装配置方案

一.说明 本文参考:http://www.cnblogs.com/jackluo/archive/2013/01/19/2868152.html 1.准备服务器 计划建立有5个节点的MySQL CLuster体系,需要用到5台服务器,但是我们做实验时没有这么多机器,可以只用3台,提供5个节点的MySQL CLuster体系,将SQL节点和数据节点共用一台机器,具体如下. 主机名 节点 对应的IP和端口 DB-mgm 管理节点 10.10.6.201:1186 DB-node1 数据节点 10.1

Linux环境MySQL集群配置

一.介绍 ======== 这篇文档旨在介绍如何安装配置基于2台服务器的MySQL集群.并且实现任意一台服务器出现问题或宕机时MySQL依然能够继续运行. 注意! 虽 然这是基于2台服务器的MySQL集群,但也必须有额外的第三台服务器作为管理节点,但这台服务器可以在集群启动完成后关闭.同时需要注意的是并不推荐在 集群启动完成后关闭作为管理节点的服务器.尽管理论上可以建立基于只有2台服务器的MySQL集群,但是这样的架构,一旦一台服务器宕机之后集群就无法继 续正常工作了,这样也就失去了集群的意义了

MySQL集群搭建(所有节点在同一台机子上)

转自:http://www.2cto.com/database/201408/328954.html 加了一些遇到的错误及其解决方法: ------------------------------------------------华丽的分割线-------------------------------------------------------- mysql用来开发中小型项目还是挺好用的,从节约成本的方面来考虑的确是个不错的选择,但是开发并发了比较大的项目显然还是有些吃力的,前几 年解决

MYSQL集群的搭建

按照此配置完全可以配置成功!! 一.介绍========测试环境:Server1:ndbd 192.168.1.225Server2:ndbd 192.168.1.226Server3:mysqld --ndb-cluster 192.168.1.224 (ndbd_mgm ndbd_mgmd也在本机)Server4:LVS 192.168.1.111 (调度主服务器,利用此服务器进行MYSQL的负载均衡,否则MYSQL CLUSTER只做到了数据同步的作用,好像在机制内部MYSQL NDB的各

MySql 集群配置

MYSQL CLUSTER方案介绍 本文的大致框架来自罗志威.黄川的报告, 在它的基础上进行简化和修改一些bug并且添加了主从复制的章节,最后做出该文档 MySQL Cluster 是MySQL适合于分布式计算环境的高实用.高冗余版本.它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器.现在mysql cluster 被独立出来, 作为一个专门的产品进行运营, mysql-server-5.6+ 就不在存在对mysql cluster的支持,需要独立

MySQL集群架构以及本人配置过程中出现的问题及解决办法

首先说下MySQL的优缺点 优点 解决单点故障 自动实现数据冗余 缺点就是维护起来太麻烦. 集群的条件就是所有的机器上都要安装MySQL的集群软件,我安装的是MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm的rpm包,不是源码包安装.如果系统里面安装了mysql-server等数据库服务软件的要自行写在掉即可. MySQL集群中有三种角色,下面是三种角色以及其的作用 角色 数据节点:ndbd节点 存储在表里的数据(表中的记录) SQL节点:不存储数据,供用户访问和

MySQL集群安装与配置

MySQL集群安装与配置 文章目录 [隐藏] 一.mysql集群安装 二.节点配置 三.首次启动节点 四.测试服务是否正常 五.安全关闭和重启 MySQL Cluster 是 MySQL 适合于分布式计算环境的高实用.高冗余版本.它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器.MySQL Cluster 能够使用多种故障切换和负载平衡选项配置NDB存储引擎,但在 Cluster 级别上的存储引擎上做这个最简单.下面我们简单介绍MySQL Clus

集群技术(二) MySQL集群简介与配置详解

when?why? 用MySQL集群? 减少数据中心结点压力和大数据量处理(读写分离),采用把MySQL分布,一个或多个application对应一个MySQL数据库.把几个MySQL数据库公用的数据做出共享数据,例如购物车,用户对象等等,存在数据结点里面.其他不共享的数据还维持在各自分布的MySQL数据库本身中.  集群MySQL中名称概念   MySQL群集需要有一组计算机,每台计算机的角色可能是不一样的.MySQL群集中有三种节点:管理节点.数据节点和SQL节点.群集中的某计算机可能是某一