说起mysql的集群估计很多人会首先想起mysql自带的replication或者mysql-mmm。mysql-mmm其实也是基于mysql自带的replication的,不过封装的更好用一些,但是配置起来还是比较麻烦,而且对于动态增减master节点可以说是无能为力的。

  偶然的情况下了解到有一个基于mysql的集群galera,除了只支持InnoDB以外,基本就没什么缺点了。大家看看官方是怎么说的:

Features

MySQL/Galera is synchronous multi-master cluster for MySQL/InnoDB database, having features like:

    Synchronous replication
Active-active multi-master topology
Read and write to any cluster node
Automatic membership control, failed nodes drop from the cluster
Automatic node joining
True parallel replication, on row level
Direct client connections, native MySQL look & feel Benefits These features yield un-seen benefits for a DBMS clustering solution: No slave lag
No lost transactions
Both read and write scalability
Smaller client latencies

  废话少说,马上开始动手测试,测试用的OS是64位的CentOS 6。首先,添加MariaDB的软件仓库,创建文件“/etc/yum.repos.d/MariaDB.repo”,内容

# MariaDB 5.5 CentOS repository list - created 2013-11-05 06:30 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

  然后,安装MariaDB-Galera集成版

# yum -y install MariaDB-Galera-server.x86_64 MariaDB-client.x86_64 galera.x86_64

 # cp /usr/share/mysql/wsrep.cnf /etc/my.cnf.d/

  Galera默认试用4567端口同步数据,需要修改防火墙,这里为了方便直接把防火墙给关闭了

# /etc/init.d/iptables stop

  MariaDB-Galera貌似没有给你提供配套的selinux配置,为了方便,直接把selinux给禁止了

# setenforce 0

  既然是集群,当然不能只有一台机器

机器a 192.168.56.103
机器b 192.168.56.104
机器c 192.168.56.105

  修改机器a的“/etc/my.cnf.d/wsrep.cnf”,改动内容

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
# Group communication system handle
wsrep_cluster_address="gcomm://"
# Address which donor should send State Snapshot to.
# Should be the address of THIS node. DON'T SET IT TO DONOR ADDRESS!!!
# (SST method dependent. Defaults to the first IP of the first interface)
wsrep_sst_receive_address=192.168.56.103

  因为机器a是第一个节点,wsrep_cluster_address直接填"gcomm://"就可以了。如果是要加入到某个集群,那就填集群里面随便一个节点的ip就可以,例如"gcomm://192.168.56.103:4567"。wsrep_sst_receive_address是本机用来接收同步数据的ip,默认是机器网络配置里面找到的第一个ip,如果机器有多个ip的话最好指定一下,例如“192.168.56.103”。启动mysql数据库服务

# /etc/init.d/mysql start

  现在要把机器b加入到集群,同样修改配置文件“/etc/my.cnf.d/wsrep.cnf”,改动内容

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
# Group communication system handle
wsrep_cluster_address="gcomm://192.168.56.103:4567"
# Address which donor should send State Snapshot to.
# Should be the address of THIS node. DON'T SET IT TO DONOR ADDRESS!!!
# (SST method dependent. Defaults to the first IP of the first interface)
wsrep_sst_receive_address=192.168.56.104

  启动机器b的mysql服务。

  到这里集群就搭建完毕了,现在开始正式测试集群。首先,链接机器a的mysql服务,创建一个数据库和一张表,表里面有一个让mysql-mmm比较麻烦和头疼的AUTO_INCREMENT字段,顺便添加乐一个用来访问这个数据库的用户

[root@centos6 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.33a-MariaDB MariaDB Server, wsrep_23.7.6.rXXXX Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database asdf;
Query OK, 1 row affected (0.03 sec) MariaDB [(none)]> grant all on asdf.* to 'aauu'@'localhost' identified by '';
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> use asdf;
Database changed
MariaDB [asdf]> create table aatt (aa int primary key auto_increment);
Query OK, 0 rows affected (0.14 sec) MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.01 sec) MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.00 sec) MariaDB [asdf]> select * from aatt;
+----+
| aa |
+----+
| 2 |
| 4 |
+----+
2 rows in set (0.00 sec)

  auto_increment的步进自动变成2了,是不是很智能?现在我们去到机器b,用新建的用户名登录mysql服务,执行类似的操作

[root@centos6 ~]# mysql -u aauu -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.33a-MariaDB MariaDB Server, wsrep_23.7.6.rXXXX Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use asdf;
Database changed
MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.01 sec) MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.04 sec) MariaDB [asdf]> select * from aatt;
+----+
| aa |
+----+
| 2 |
| 4 |
| 5 |
| 7 |
+----+
4 rows in set (0.00 sec)

  看到没有?刚才插入的数据都在这个就没什么值得说的,厉害的是机器a上新建的用户在这里可以用!现在我们来动态把机器c加入到集群里面去

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
# # Group communication system handle
wsrep_cluster_address="gcomm://192.168.56.104:4567"
# # Address which donor should send State Snapshot to.
# # Should be the address of THIS node. DON'T SET IT TO DONOR ADDRESS!!!
# # (SST method dependent. Defaults to the first IP of the first interface)
wsrep_sst_receive_address=192.168.56.105

  之前说过的,加入到集群里面随便一个节点的ip都可以。启动机器c的mysql服务,然后执行类似操作

[root@centos6 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.33a-MariaDB MariaDB Server, wsrep_23.7.6.rXXXX Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use asdf;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.00 sec) MariaDB [asdf]> insert into aatt values (null);
Query OK, 1 row affected (0.00 sec) MariaDB [asdf]> select * from aatt;
+----+
| aa |
+----+
| 2 |
| 4 |
| 5 |
| 7 |
| 9 |
| 12 |
+----+
6 rows in set (0.00 sec)

  auto_increment的步进自动变成3了,看到没有?

  这里我只是简单的列举了Galera的一个使用场景,还有很多它先进的地方这里没有提到,它大家可以上它的官方网站看看。

  参考网址:

  1. http://www.codership.com/
  2. https://launchpad.net/wsrep
  3. http://blog.sina.com.cn/s/blog_704836f40101lixp.html

实战MySQL集群,试用CentOS 6下的MariaDB-Galera集成版的更多相关文章

  1. mysql集群安装(centos)

    mysql cluster : 1. 基于NDB Cluster 的分布式数据库系统 2. mysql集群中各服务器节点不共享数据 3. 在mysql cluster中节点指的是进程,区别于其他的集群 ...

  2. MySQL集群高可用

    目录 MySQL高可用 Galera Cluster Galera Cluster Galera Cluster特点 Galera Cluster 缺点 Galera Cluster工作过程 Gale ...

  3. 2-20 MySQL集群搭建实现高可用

    MySQL集群概述和安装环境 MySQL Cluster是MySQL适合于分布式计算环境的高实用.高冗余版本.Cluster的汉语是"集群"的意思.它采用了NDB Cluster ...

  4. 超详细,多图文使用galera cluster搭建mysql集群并介绍wsrep相关参数

    超详细,多图文使用galera cluster搭建mysql集群并介绍wsrep相关参数 介绍galera cluster原理的文章已经有一大堆了,百度几篇看一看就能有相关了解,这里就不赘述了.本文主 ...

  5. windows+mysql集群搭建-三分钟搞定集群

    注:本文来源:  陈晓婵   <  windows+mysql集群搭建-三分钟搞定集群   > 一:mysql集群搭建教程-基础篇 计算机一级考试系统要用集群,目标是把集群搭建起来,保证一 ...

  6. mysql集群搭建教程-基础篇

           计算机一级考试系统要用集群,目标是把集群搭建起来,保证一个库dang了,不会影响程序的运行.于是在孟海滨师哥的带领下开始了我的第一次搭建mysql集群,首先看了一些关于集群的资料,然后根 ...

  7. centos下mysql集群初尝试

    原文:http://www.lvtao.net/database/mysql-cluster.html 五台服务器篇 安装要求 安装环境:CentOS-6.3安装方式:源码编译安装软件名称:mysql ...

  8. docker 下 mysql 集群的搭建

    下载程序&&创建docker容器 从mysql官网https://dev.mysql.com/downloads/cluster/上下载mysql集群库mysql-cluster-gp ...

  9. mysql集群基于docker 在centos上

    新博客https://blog.koreyoshi.work/ mysql集群(PXC)基于docker 在centos上 常用设计方案 Replication(复制) 速度快 弱一致性 低价值 场景 ...

随机推荐

  1. 海外支付:抵御信用卡欺诈的CyberSource

    海外支付:抵御信用卡欺诈的CyberSource 吴剑 2014-06-04 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian 吴剑 http://www.cn ...

  2. JAVA中求解对象所占字节大小

    该类为cache4j缓存框架中的工具类方法,该方法实现了两个接口 接口1:计算对象在内存中所占字节数 接口2:复制对象,实现深度克隆效果,实现原理为先序列化对象,然后在反序列化对象:返回一个新的对象, ...

  3. Jackson 框架,轻易转换JSON(转)

    Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 相比json-lib框架,Jackson所依赖的jar包较少,简单易用并且性能也 ...

  4. 设置.Net多线程默认CultureInfo

    .net编码过程中,当我们新开一个线程时,其默认的CurrentCulture属性为当前系统的Culture,在软件的本地化没有完成的情况下,采用默认系统的文化编码方式,可能会导致软件在界面显示,数字 ...

  5. 压缩上传并预览 flash

    最近研究一个功能:用as3写的上传图片并实现预览.觉得花了很多时间也学到很多知识,将自己的所得记录下来供大家分享. 首先是预览功能的实现,大家自然而然就想到了loader来加载图片并显示,由于项目没有 ...

  6. ASP.NET运行机制原理 ---浏览器与IIS的交互过程 自己学习 网上查了下别人写的总结的很好 就转过来了 和自己写的还好里嘻嘻

    一.浏览器和服务器的交互原理 (一).浏览器和服务器交互的简单描述: 1.通俗描述:我们平时通过浏览器来访问网站,其实就相当于你通过浏览器去访问一台电脑上访问文件一样,只不过浏览器的访问请求是由被访问 ...

  7. iOS 如何根据经纬度来定位位置

    /** *  初始化一个经纬度结构体 */ CLLocationCoordinate2D center = {[latitudeTF.text floatValue],[longitudeTF.tex ...

  8. Linux选型:开源不是免费 首选红帽和SUSE

    首发:http://tech.it168.com/a2014/0324/1606/000001606245.shtml 企业级服务器系统选型报告:http://www.it168.com/redian ...

  9. APUE第五章:标准IO库

    5.2流和file对象 #include <wchar.h> int fwide(FILE *fp, int mode); Returns: positive if stream is w ...

  10. STL容器迭代器失效分析

    连续内存序列容器(vector, string, deque) 对于连续内存序列STL容器,例如vector,string,deque,删除当前iterator会使得后面所有的iterator都失效, ...