MariaDB Galera Cluster 部署(如何快速部署MariaDB集群)

[日期:--]    来源:Linux社区  作者:Linux    [字体:大 中 小]

MariaDB作为Mysql的一个分支,在开源项目中已经广泛使用,例如大热的openstack,所以,为了保证服务的高可用性,同时提高系统的负载能力,集群部署是必不可少的。

MariaDB Galera Cluster 介绍

MariaDB集群是MariaDB同步多主机集群。它仅支持XtraDB/ InnoDB存储引擎(虽然有对MyISAM实验支持 - 看wsrep_replicate_myisam系统变量)。

主要功能:

同步复制
真正的multi-master,即所有节点可以同时读写数据库
自动的节点成员控制,失效节点自动被清除
新节点加入数据自动复制
真正的并行复制,行级
用户可以直接连接集群,使用感受上与MySQL完全一致
优势: 因为是多主,所以不存在Slavelag(延迟)
不存在丢失事务的情况
同时具有读和写的扩展能力
更小的客户端延迟
节点间数据是同步的,而Master/Slave模式是异步的,不同slave上的binlog可能是不同的
技术: Galera集群的复制功能基于Galeralibrary实现,为了让MySQL与Galera library通讯,特别针对MySQL开发了wsrep API。 Galera插件保证集群同步数据,保持数据的一致性,靠的就是可认证的复制,工作原理如下图: 当客户端发出一个commit的指令,在事务被提交之前,所有对数据库的更改都会被write-set收集起来,并且将 write-set 纪录的内容发送给其他节点。 write-set 将在每个节点进行认证测试,测试结果决定着节点是否应用write-set更改数据。 如果认证测试失败,节点将丢弃 write-set ;如果认证测试成功,则事务提交。 .安装环境准备 安装MariaDB集群至少需要3台服务器(如果只有两台的话需要特殊配置,请参照官方文档) 在这里,我列出试验机器的配置: 操作系统版本:CentOS7 node4:10.128.20.16 node5:10.128.20.17 node6:10.128.20.18 以第一行为例,node4为 hostname ,10.128..16为 ip ,在三台机器修改 /etc/hosts文件,我的文件如下:
10.128.20.16 node4
10.128.20.17 node5
10.128.20.18 node6 为了保证节点间相互通信,需要禁用防火墙设置(如果需要防火墙,则参照官方网站增加防火墙信息设置) 在三个节点分别执行命令:
systemctl stop firewalld 然后将/etc/sysconfig/selinux 的 selinux 设置成 disabled ,这样初始化环境就完成了。 .安装 MariaDB Galera Cluster
[root@node4 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync [root@node5 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync [root@node6 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync .配置 MariaDB Galera Cluster 初始化数据库服务,只在一个节点进行 [root@node4 mariadb]# systemctl start mariadb
[root@node4 mariadb]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here. Enter current password for root (enter for none):
OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success! By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment. Remove anonymous users? [Y/n] n
... skipping. Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y
... Success! By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment. Remove test database and access to it? [Y/n] n
... skipping. Reloading the privilege tables will ensure that all changes made so far
will take effect immediately. Reload privilege tables now? [Y/n] y
... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB
installation should now be secure. Thanks for using MariaDB! 关闭数据库,修改 /etc/my.cnf.d/galera.cnf
[root@node4 mariadb]# systemctl stop mariadb
[root@node4 ~]# vim /etc/my.cnf.d/galera.cnf 修改以下内容:
[mysqld]
......
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address = "gcomm://node4,node5,node6"
wsrep_node_name = node4
wsrep_node_address=10.128.20.16
#wsrep_provider_options="socket.ssl_key=/etc/pki/galera/galera.key; socket.ssl_cert=/etc/pki/galera/galera.crt;" 提示:如果不用ssl的方式认证的话,请把wsrep_provider_options 注释掉。 将此文件复制到node5、node6,注意要把 wsrep_node_name和 wsrep_node_address改成相应节点的 hostname和ip。 .启动 MariaDB Galera Cluster 服务
[root@node4 ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root & 观察日志:
[root@node4 ~]# tail -f /var/log/mariadb/mariadb.log :: [Note] WSREP: wsrep_load(): loading provider library 'none'
:: [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.40-MariaDB-wsrep' socket: '/var/lib/mysql/mysql.sock' port: MariaDB Server, wsrep_25..r4026 出现 ready for connections ,证明我们启动成功,继续启动其他节点:
[root@node5 ~]# systemctl start mariadb
[root@node6 ~]# systemctl start mariadb 可以查看/var/log/mariadb/mariadb.log,在日志可以看到节点均加入了集群中。 警告⚠:--wsrep-new-cluster 这个参数只能在初始化集群使用,且只能在一个节点使用。 .查看集群状态 我们可以关注几个关键的参数: wsrep_connected = on 链接已开启 wsrep_local_index = 1在集群中的索引值 wsrep_cluster_size =3集群中节点的数量 wsrep_incoming_addresses = 10.128.20.17:,10.128.20.16:,10.128.20.18: 集群中节点的访问地址 .验证数据同步 我们在node4上新建数据库 galera_test ,然后在node5 和node6 上查询,如果可以查询到 galera_test 这个库,说明数据同步成功,集群运行正常。 [root@node4 ~]# mysql -uroot -proot -e "create database galera_test" [root@node5 ~]# mysql -uroot -proot -e "show databases"
+--------------------+
| Database |
+--------------------+
| information_schema |
| galera_test |
| mysql |
| performance_schema |
+--------------------+ [root@node6 ~]# mysql -uroot -proot -e "show databases"
+--------------------+
| Database |
+--------------------+
| information_schema |
| galera_test |
| mysql |
| performance_schema |
+--------------------+ 至此,我们的 MariaDB Galera Cluster 已经成功部署。 --------------------------------------分割线 -------------------------------------- 在 CentOS/RHEL/Scientific Linux 下安装 LAMP (Apache with MariaDB and PHP) http://www.linuxidc.com/Linux/2013-07/86755.htm MariaDB Proxy读写分离的实现 http://www.linuxidc.com/Linux/2014-05/101306.htm Linux下编译安装配置MariaDB数据库的方法 http://www.linuxidc.com/Linux/2014-11/109049.htm CentOS系统使用yum安装MariaDB数据库 http://www.linuxidc.com/Linux/2014-11/109048.htm 安装MariaDB与MySQL并存 http://www.linuxidc.com/Linux/2014-11/109047.htm Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB http://www.linuxidc.com/Linux/2014-11/109471.htm [翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB http://www.linuxidc.com/Linux/2014-12/110048htm MariaDB 的详细介绍:请点这里
MariaDB 的下载地址:请点这里 本文系OneAPM工程师原创文章。OneAPM是中国基础软件领域的新兴领军企业,能帮助企业用户和开发者轻松实现:缓慢的程序代码和SQL语句的实时抓取。想阅读更多技术文章,请访问OneAPM官方技术博客。
 

MariaDB Galera Cluster 部署(如何快速部署MariaDB集群)的更多相关文章

  1. MariaDB Galera Cluster部署手册

    MariaDB Galera Cluster部署手册 galara保证双主数据库的同步及一致性 1.环境准备 基于新部署.最小化安装centos6.5 1>  yum install opens ...

  2. 利用MariaDB Galera Cluster实现mariadb的多主复制

    一.MariaDB Galera Cluster概要: .简述: MariaDB Galera Cluster 是一套在mysql innodb存储引擎上面实现multi-master及数据实时同步的 ...

  3. 构建 MariaDB Galera Cluster 分布式数据库集群(二)

    MariaDB的安装 构建 MariaDB Galera Cluster之前,首先安装MariaDB,本文使用的版本是10.1 1.环境准备 主机: MariaDB01(192.168.56.102) ...

  4. MariaDB Galera Cluster 部署(如何快速部署 MariaDB 集群)

    MariaDB Galera Cluster 部署(如何快速部署 MariaDB 集群)  OneAPM蓝海讯通7月3日 发布 推荐 4 推荐 收藏 14 收藏,1.1k 浏览 MariaDB 作为 ...

  5. MariaDB Galera Cluster 部署

    原文  http://code.oneapm.com/database/2015/07/02/mariadb-galera-cluster/MariaDB作为Mysql的一个分支,在开源项目中已经广泛 ...

  6. Mariadb Galera Cluster 群集 安装部署

    #Mariadb Galera Cluster 群集 安装部署 openstack pike 部署  目录汇总 http://www.cnblogs.com/elvi/p/7613861.html # ...

  7. MariaDB Galera Cluster 部署 + keepalived实现高可用

    MariaDB Galera Cluster 部署 MariaDB作为Mysql的一个分支,在开源项目中已经广泛使用,例如大热的openstack,所以,为了保证服务的高可用性,同时提高系统的负载能力 ...

  8. MariaDB Galera Cluster部署实践

    原理 官方地址:http://galeracluster.com/documentation-webpages/index.html Galera Cluster与传统的复制方式不同,不通过I/O_t ...

  9. MariaDB Galera Cluster集群搭建

    MariaDB Galera Cluster是什么?   Galera Cluster是由第三方公司Codership所研发的一套免费开源的集群高可用方案,实现了数据零丢失,官网地址为http://g ...

随机推荐

  1. C++ Stacks(堆栈)

    C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. 操作 比较和分配堆栈 empty() 堆栈为空则返回真 pop() ...

  2. OpenGL第6、7讲小结

    因为内容比较多,所以只看了两讲(强行解释). 一讲讲了如何给各个面贴纹理,一讲讲了加光照和按键控制. 现在讲的都是给规则的面贴纹理,像正方形,刚好纹理图也是正方形,那像人物模型的衣服贴起来用代码控制得 ...

  3. 【风马一族_Java】使用java,画出任意大小的菱形

    public class rhombic { public static void main(String[] args){ /** * scriber()画菱形的方法,参数 9 是指菱形的对角线的长 ...

  4. Win7在CMD命令行中使用管理员权限运行命令

    使用命令: runas /user:administrator 需要执行的命令 如下:

  5. linux下文件的复制、移动与删除

    linux下文件的复制.移动与删除命令为:cp,mv,rm 一.文件复制命令cp     命令格式:cp [-adfilprsu] 源文件(source) 目标文件(destination)      ...

  6. Python脚本控制的WebDriver 常用操作 <二十七> 文件下载

    测试用例场景 webdriver允许我们设置默认的文件下载路径.也就是说文件会自动下载并且存在设置的那个目录中. Python脚本 测试用Python代码: # coding=gbk ''' Crea ...

  7. Python的类实例方法,类方法,类静态方法

    以下面的类定义为例: # coding:utf-8 class A: count = 0 def __init__(self, inst_name): self.inst_name = inst_na ...

  8. zendframework 事件管理(二)

    首先需要明确的几个问题: Q1.什么是事件? A:事件就是一个有名字的行为.当这个行为发生的时候,称这个事件被触发. Q2.监听器又是什么? A:监听器决定了事件的逻辑表达,由事件触发.监听器和事件往 ...

  9. Linux 批量解压gz包

    [root@yoon export]# vi gunzip.sh !/bin/bashpath=/export/backup ----备份文件目录路径 for i in `ls ${path}/*`d ...

  10. Linux C C语言库的创建和调用

    C语言库的创建和调用 简介: 假如,你有一个庞大的工程,代码量达到数百兆甚至是数G,你经常会遇到好多重复或常用的地方.每次使用到这些地方时如果都重新写一份基本相同的代码,这当然可以,不过这样会大大地降 ...