drbd mysql_DRBD+MYSQL创建高可用集群

drbd + mysql 高可用集群

在上两篇中,我分别写到了 drbd 和 corosync、pacemaker、crm 的配置和使用,在本节中,我讲这两种东西结合起来,做出 drbd + mysql 高可用集群。

一、实验环境

系统版本:centos7

实验机器:

node1:192.168.163.172

node2:192.168.163.173

软件源:阿里云

二、实验过程

drbd 的配置和 corosync 的配置就不再说明,直接开始

首先增加drbd资源

crm(live)#configure

crm(live)configure#primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op start   timeout=240 op stop timeout=100 op monitor role=Master interval=20 timeout=30 op monitor role=Slave interval=30 timeout=30

crm(live)configure#ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2clone-node-max=1 notify=true

crm(live)configure#verify

crm(live)configure#show

crm(live)configure# show

node 1: node1

node 2: node2

primitive mysqldrbd ocf:linbit:drbd \

params drbd_resource=mysql \

op start timeout=240 interval=0 \

op stop timeout=100 interval=0 \

op monitor role=Master interval=20 timeout=30 \

op monitor role=Slave interval=30 timeout=30

ms ms_mysqldrbd mysqldrbd \

meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true

property cib-bootstrap-options: \

have-watchdog=false \

dc-version=1.1.16-12.el7_4.4-94ff4df \

cluster-infrastructure=corosync \

cluster-name=mycluster \

stonith-enabled=false

增加文件系统资源crm(live)configure#  primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/data fstype=xfs op start timeout=60 op stop timeout=60

给文件系统类型和drbd做亲缘性绑定crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master

做顺序约束,当drbd起来之后才对文件系统进行绑定crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start

接下来增加一下mysql资源,并作亲缘性绑定crm(live)configure#primitive mysqld systemd:mariadb

crm(live)configure# colocation mysqld_with_mystoreinf: mysqld mystore

作顺序约束,先挂载文件系统,然后在启动msyqld资源crm(live)configure#order mysqld_after_mystore mandatory: mystore mysqld

增加VIP资源,作虚拟IP调度crm(live)#configure

crm(live)configure#primitive myvip ocf:heartbeat:IPaddr params ip="192.168.113.120" opmonitor interval=20 timeout=20 on-fail=restart

crm(live)configure#  colocation vip_with_ms_mysqldrbd inf:ms_mysqldrbd:Master myvip

检查并提交crm(live)configure#verify

crm(live)configure#commit

查看状态crm(live)# status

Stack: corosync

Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum

Last updated: Wed Oct 25 08:38:22 2017

Last change: Wed Oct 25 08:38:14 2017 by root via crm_attribute on node2

2 nodes configured

5 resources configured

Online: [ node1 node2 ]

Full list of resources:

Master/Slave Set: ms_mysqldrbd [mysqldrbd]

Masters: [ node1 ]

Slaves: [ node2 ]

mystore(ocf::heartbeat:Filesystem):Started node1

mysqld(systemd:mariadb):Started node1

myvip(ocf::heartbeat:IPaddr):Started node1

三、测试

先访问数据库,并新建一个用户,供远程访问使用MariaDB[(none)]> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';

QueryOK, 0 rows affected (0.00 sec)

使用VIP访问数据库

[root@node1 ~]# mysql -uroot -p123456 -h 192.168.163.100Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;

+---------------------+

| Database            |

+---------------------+

| information_schema  |

| #mysql50#lost+found |

| mysql               |

| mysqld              |

| performance_schema  |

| xhk                 |

| xhk777              |

+---------------------+

7 rows in set (0.06 sec)

接下来,将node停掉,服务自行转到node2crm(live)# node standbycrm(live)# status

Stack: corosync

Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum

Last updated: Wed Oct 25 08:43:46 2017

Last change: Wed Oct 25 08:43:41 2017 by root via crm_attribute on node1

2 nodes configured

5 resources configured

Node node1: standby

Online: [ node2 ]

Full list of resources:

Master/Slave Set: ms_mysqldrbd [mysqldrbd]

Slaves: [ node2 ]

Stopped: [ node1 ]

mystore(ocf::heartbeat:Filesystem):Stopped

mysqld(systemd:mariadb):Stoppedcrm(live)# status

Stack: corosync

Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum

Last updated: Wed Oct 25 08:43:46 2017

Last change: Wed Oct 25 08:43:41 2017 by root via crm_attribute on node1

2 nodes configured

5 resources configured

Node node1: standby

Online: [ node2 ]

Full list of resources:

Master/Slave Set: ms_mysqldrbd [mysqldrbd]

Slaves: [ node2 ]

Stopped: [ node1 ]

mystore(ocf::heartbeat:Filesystem):Stopped

mysqld(systemd:mariadb):Stopped

myvip(ocf::heartbeat:IPaddr):Started node2

继续使用VIP访问数据库[root@node1 ~]# mysql -uroot -p123456 -h 192.168.163.100

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;

+---------------------+

| Database            |

+---------------------+

| information_schema  |

| #mysql50#lost+found |

| mysql               |

| mysqld              |

| performance_schema  |

| xhk                 |

| xhk777              |

+---------------------+

7 rows in set (0.06 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Re: MySQL 高可用工具 DRBD 实战部署详解 ========================================# DRBD 是什么(用三句话总结) 目的:类似于 rsync + inotify 数据目录(/data)变化时,实现数据同步 功能:类似于本地磁盘阵列 raid-1,保持磁盘或者分区的一致性,但最终的目的是(/data)数据目录的一致性。 原理:类似于MySQL的主从复制,一份写在磁盘中,一份写在二进制日志中;DRBD原理也是一份写在磁盘中,另一份通过DRBD软件,经过tcp/ip协议,基于block变化,传输到远程磁盘中做记录。 # DRBD 的功能 Distributed Replicated Block Divice(缩略:DRBD)(分布式复制块设备) 基于高可用 HA 服务器之间的数据同步解决方案 基于块设备在不同的高可用服务器之间同步和镜像数据的软件,通过它可以实现在网络中的两台服务器之间基于“块”(block)设备级别的实时或异步镜像或同步复制(【原理】:类似MySQL主从复制) # DRBD 的目的 类似于DRBD ≈(rsync + inotify)的架构:单inotify基于文件系统‘上层’,当文件系统中有数据发生变化,就调用 rsync 服务,将文件系统中的文件同步到备库。 但是DRBD是基于文件系统底层(主要区别),即 block 块级别的更‘底层’,而 inotify是在文件系统之上的实际物理文件(文件复制),因此DRBD效率更高(类似克隆方式 GHOST 克隆软件)! 相对而言:(rsync + inotify)工作原理(效率低...)... # DRBD 的应用 heartbeat + DRBD + nfs/mfs/gfs    下章演示... heartbeat + DRBD + mysql    本章演示... heartbeat + DRBD + oracle   甚至放弃 Oracle 原厂 RAC + DataGuard 等标配 HA方案        

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值