在上一篇文章中描述了MySQL HA on Azured 设计思路,本篇文章中将描述具体的部署,每个组件的安装和配置。

整体的设计架构如下:

下面将是所有组件的安装配置过程,所有的虚拟机是CentOS 6.5的操作系统。Azure上虚拟机的新建、Vnet的配置等本文就不再涉及。如有需要,请参考张磊同学的博客:

http://www.cnblogs.com/threestone

  1. 配置Azure Internal Load Balance及添加硬盘

    本文采用Xplate CLI部署Internal Load balancer,其地址为静态的10.1.1.200,Distribution模式采用sourceIP。

    1. 首先创建ILB:

    azure service internal-load-balancer add -a 10.1.1.200 -t Subnet-2 mysql-ha mysql-ha-ilb

    info: service internal-load-balancer add command OK

    1. 创建Endpoint和LoadBalanceSet

    azure vm endpoint create -n mysql -o tcp -t 3306 -r tcp -b mysql-ha-lbs -i mysql-ha-ilb -a sourceIP mysql-ha1 3306 3306

    info: vm endpoint create command OK

    azure vm endpoint create -n mysql -o tcp -t 3306 -r tcp -b mysql-ha-lbs -i mysql-ha-ilb -a sourceIP mysql-ha2 3306 3306

    info: vm endpoint create command OK

    1. 查看ILB
    2. 固定两台VM的DIP地址

    azure vm static-ip set mysql-ha1 10.1.1.6

    azure vm static-ip set mysql-ha2 10.1.1.7

    1. 为每台VM添加20G的硬盘

    azure vm disk attach-new mysql-ha1 20 https://portalvhds68sv75c8hs05m.blob.core.chinacloudapi.cn/hwmysqltest/mysqlha1sdc.vhd

    azure vm disk attach-new mysql-ha2 20 https://portalvhds68sv75c8hs05m.blob.core.chinacloudapi.cn/hwmysqltest/mysqlha2sdc.vhd

  1. 在Server上安装部署DRBD
    1. 安装依赖包

    yum -y install gcc rpm-build kernel-devel kernel-headers flex ncurses-devel

    1. 下载DRBD的安装包并安装

    wget http://elrepo.org/linux/elrepo/el5/x86_64/RPMS/drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm

    wget http://elrepo.org/linux/elrepo/el6/x86_64/RPMS/kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm

    yum -y install drbd84-utils-8.4.3-1.el5.elrepo.x86_64.rpm

    yum install -y kmod-drbd84-8.4.3-1.el6_4.elrepo.x86_64.rpm

    1. 关闭SELinux

    setenforce 0

    或者修改配置文件/etc/sysconfig/selinux

    SELINUX=disabled

    1. 修改配置文件

    vim /etc/drbd.d/mysql.res

    resource mysql {

    protocol C;

    device /dev/drbd0;

    disk /dev/sdc1;

    meta-disk internal;

    on mysql-ha1 {

    address 10.1.1.6:7789;

    }

    on mysql-ha2 {

    address 10.1.1.7:7789;

    }

    }

    1. 修改hosts文件

    为保证DRBD的工作正常,修改hosts文件,把DRBD集群的机器都加入到hosts文件中

    vim /etc/hosts

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    10.1.1.6 mysql-ha1

    10.1.1.7 mysql-ha2

    1. 给/dev/sdc分区

    注意此时不要进行格式化。具体方法不再累述。

    1. 创建DRBD的工作盘

    在两台VM上运行drbdadm create-md mysql,分别创建DRBD的工作盘

    在mysql-ha1上运行:drbdadm -- --overwrite-data-of-peer primary mysql,使这台vm的成为DRBD组的Primary。此时通过drbd-overview查看DRBD的状态,可以看到两块磁盘此时正在进行同步:

    0:mysql/0 SyncSource Primary/Secondary UpToDate/Inconsistent C r-----

    [>....................] sync'ed: 0.6% (20372/20476)M

    此时在主节点上进行格式化:mkfs.ext4 /dev/drbd0

    至此,DRBD安装配置完成。这时,只能在Primary的VM上mount这块DRBD的盘,在secondary的VM上只能看到这块盘,但不能对它进行操作。

  2. 在Server上安装部署Corosync、Pacemaker和CRM

如前文所述,Corosync整个集群Message Layer,Pacemaker是集群的大脑,而CRM软件是集群的编辑器。集群的安装部署过程如下:

  1. 添加epel的yum源

在国内访问国外的epel源因为受到GFW的影响,不能访问。所以选择国内yahoo的yum源。具体操作如下:

vim /etc/yum.repos.d/epel.repo

[epel]

name=epel

baseurl=http://mirrors.sohu.com/fedora-epel/6/$basearch

enabled=1

gpgcheck=0

  1. 按照下面的顺序安装

    yum install -y corosync pacemaker -y

    yum install cluster-glue -y

    wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/src/crmsh-2.1-1.6.src.rpm

    wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/src/pssh-2.3.1-4.2.src.rpm

    yum install python-devel python-setuptools gcc make gcc-c++ rpm-build python-lxml cluster-glue-libs-devel pacemaker-libs-devel asciidoc autoconf automake redhat-rpm-config -y

    rpmbuild --rebuild crmsh-2.1-1.6.src.rpm

    rpmbuild --rebuild pssh-2.3.1-4.2.src.rpm

    cd /root/rpmbuild/RPMS/x86_64/

    yum install * -y

  2. 配置Corosync配置文件

    其中的member配置和transport: udpu就是指定采用udp单播(unicast)的配置。

    在所有节点做full mesh的节点配置:

    vim /etc/corosync/corosync.conf

    compatibility: whitetank

    totem {

    version: 2

    secauth: off

    threads: 0

    interface {

    member{

    memberaddr: 10.1.1.6

    }

    member{

    memberaddr: 10.1.1.7

    }

    ringnumber: 0

    bindnetaddr: 10.1.1.0

    mcastport: 5405

    ttl: 1

    }

    transport: udpu

    }

    logging {

    fileline: off

    to_stderr: no

    to_logfile: yes

    logfile: /var/log/cluster/corosync.log

    to_syslog: yes

    debug: off

    timestamp: on

    logger_subsys {

    subsys: AMF

    debug: off

    }

    }

    amf {

    mode: disabled

    }

    service {

    ver: 1

    name: pacemaker

    use_mgmtd: no

    use_logd: no

    }

    aisexec {

    user: root

    group: root

    }

  3. 生成corosync的密钥文件

mv /dev/random /dev/random.bak

ln -s /dev/urandom /dev/random

corosync-keygen

scp /etc/corosync/authkey mysql-ha2:/etc/corosync

  1. 启动corosync和pacemaker服务

service corosync start

ssh mysql-ha2 'service corosync start'

service pacemaker start

ssh mysql-ha2 'service pacemaker start'

  1. 安装Azure组件,创建mdfilb服务

安装Azure cli:

yum install nodejs –y

yum install npm –y

npm install azure-cli –g

在/etc/init.d里创建文件mdfilb

#!/bin/sh

start()

{

echo -n $"Starting Azure ILB Modify: "

/root/mdfilb.sh

echo

}

stop()

{

echo -n $"Shutting down Azure ILB Modify: "

echo

}

MDFILB="/root/mdfilb.sh"

[ -f $MDFILB ] || exit 1

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep 3

start

;;

*)

echo $"Usage: $0 {start|stop|restart}"

exit 1

esac

exit 0

vim /root/mdfilb.sh

azure vm endpoint delete mysql-ha2 mysql

azure vm endpoint create -i mysql-ha-ilb -o tcp -t 3306 -k 3306 -b mysql-ha-lbs -r tcp -a sourceIP mysql-ha1 3306 3306

但实测下来,VM对ILB对修改结果不稳定。

  1. 通过crm对pacemaker进行编排
  1. crm configure 进入编辑界面,对两个全局参数进行调整:

property stonith-enabled=false

property no-quorum-policy=ignore

  1. 编排

业务的编排前,需要把两台VM重新启动。

  1. DRBD服务

crm configure

primitive mysqldrbd ocf:linbit:drbd params drbd_resource="mysql" op start timeout=240 op stop timeout=240

ms mydrbd mysqldrbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

verify

commit

  1. 文件挂载服务

primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/mydata fstype=ext4 op start timeout=60 op stop timeout=60

verify

commit

保证文件挂载和DRBD在一台机器上,同时保证启动顺序

colocation mystore_with_mysqldrbd inf: mystore mydrbd:Master

order mystore_after_ms_mydrbd mandatory: mydrbd:promote mystore:start

verify

commit

  1. 更改ILB的服务

primitive mdfilb lsb:mdfilb

要保证与文件挂载在一个服务器上,同时保证启动顺序

colocation mdfilb_with_mystore inf: mdfilb mystore

order mdfilb_after_mystore mandatory: mystore mdfilb

verify

commit

  1. MySQL服务

primitive mysqld lsb:mysqld

要保证与文件挂载在一个服务器上,同时保证启动顺序

colocation mysqld_with_mystore inf: mysqld mystore

order mysqld_after_mdfilb mandatory: mdfilb mysqld

verify

commit

至此,所有的配置都配置完成。在测试中,VM控制ILB的部分不稳定,可以视情况选择是否部署。

可以查看状态:

在mysql-ha1上:

[root@mysql-ha1 /]# crm status

Last updated: Sun Dec 6 03:33:21 2015

Last change: Sun Dec 6 02:57:11 2015

Stack: classic openais (with plugin)

Current DC: mysql-ha2 - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

5 Resources configured

Online: [ mysql-ha1 mysql-ha2 ]

Master/Slave Set: mydrbd [mysqldrbd]

Masters: [ mysql-ha2 ]

Slaves: [ mysql-ha1 ]

mystore    (ocf::heartbeat:Filesystem):    Started mysql-ha2

mdfilb    (lsb:mdfilb):    Started mysql-ha2

mysqld    (lsb:mysqld):    Started mysql-ha2

[root@mysql-ha1 /]# drbd-overview

0:mysql/0 Connected Secondary/Primary UpToDate/UpToDate C r-----

[root@mysql-ha1 /]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 29G 3.3G 24G 13% /

tmpfs 1.7G 30M 1.7G 2% /dev/shm

/dev/sdb1 50G 180M 47G 1% /mnt/resource

[root@mysql-ha1 /]# service mysqld status

mysqld is stopped

在mysql-ha2上:

[root@mysql-ha2 ~]# crm status

Last updated: Sun Dec 6 03:36:30 2015

Last change: Sun Dec 6 02:57:11 2015

Stack: classic openais (with plugin)

Current DC: mysql-ha2 - partition with quorum

Version: 1.1.11-97629de

2 Nodes configured, 2 expected votes

5 Resources configured

Online: [ mysql-ha1 mysql-ha2 ]

Master/Slave Set: mydrbd [mysqldrbd]

Masters: [ mysql-ha2 ]

Slaves: [ mysql-ha1 ]

mystore    (ocf::heartbeat:Filesystem):    Started mysql-ha2

mdfilb    (lsb:mdfilb):    Started mysql-ha2

mysqld    (lsb:mysqld):    Started mysql-ha2

[root@mysql-ha2 ~]# drbd-overview

0:mysql/0 Connected Primary/Secondary UpToDate/UpToDate C r----- /mydata ext4 20G 193M 19G 2%

[root@mysql-ha2 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 29G 3.2G 24G 12% /

tmpfs 1.7G 45M 1.7G 3% /dev/shm

/dev/sdb1 50G 180M 47G 1% /mnt/resource

/dev/drbd0 20G 193M 19G 2% /mydata

[root@mysql-ha2 ~]# service mysqld status

mysqld (pid 2367) is running...

[root@mysql-ha2 ~]# cd /mydata/

[root@mysql-ha2 mydata]# ls

hengwei ibdata1 ib_logfile0 ib_logfile1 lost+found mysql test

此时在前端通过mysql客户端访问10.1.1.200的3306端口,在两台机器随意关停机的情况下,可以快速的恢复连接,保持业务的连续性!

MySQL on Azure高可用性设计 DRBD - Corosync - Pacemaker - CRM (二)的更多相关文章

  1. MySQL on Azure高可用性设计 DRBD - Corosync - Pacemaker - CRM (一)

    MySQL迁移到Azure上后,由于云的特性,在自建数据中心的MySQL的HA的方法在云上很多都不能部署. 这主要是因为,目前Public Cloud不支持:1. 共享存储:2. Multicast: ...

  2. Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群

    大纲一.前言二.环境准备三.Corosync 安装与配置四.Pacemaker 安装与配置五.DRBD 安装与配置六.MySQL 安装与配置七.crmsh 资源管理 推荐阅读: Linux 高可用(H ...

  3. 【原】ubuntu下Mysql的HA(corosync+pacemaker+drbd)

    一.前提准备: 1.OS:ubuntu 12.04 2.cat /etc/hosts: 127.0.0.1 localhost 192.168.153.154 ha1 192.168.153.155 ...

  4. Centos 7 下 Corosync + Pacemaker + DRBD + psc + crmsh 实现 mysql 服务高可用

    一.介绍 高可用,大家可能会想到比较简单的Keepalived,或者更早一点的 heartbeat,也可能会用到 Corosync+Pacemaker,那么他们之间有什么区别. Heartbeat到了 ...

  5. 基于corosync+pacemaker+drbd+LNMP做web服务器的高可用集群

    实验系统:CentOS 6.6_x86_64 实验前提: 1)提前准备好编译环境,防火墙和selinux都关闭: 2)本配置共有两个测试节点,分别coro1和coro2,对应的IP地址分别为192.1 ...

  6. CentOS 6.5环境实现corosync+pacemaker实现DRBD高可用

    DRBD (Distributed Replicated Block Device)分布式复制块设备,它是 Linux 平台上的分散式储存系统,通常用于高可用性(high availability, ...

  7. 使用 Load Balancer,Corosync,Pacemaker 搭建 Linux 高可用集群

    由于网络架构的原因,在一般虚拟机或物理环境中常见的用 VIP 来实现双机高可用方案,无法照搬到 Azure 平台.但利用 Azure 平台提供的负载均衡或者内部负载均衡功能,可以达到类似的效果. 本文 ...

  8. Corosync+Pacemaker+crmsh构建Web高可用集群

    一.概述: 1.1 AIS和OpenAIS简介 AIS应用接口规范,是用来定义应用程序接口(API)的开放性规范的集合,这些应用程序作为中间件为应用服务提供一种开放.高移植性的程序接口.是在实现高可用 ...

  9. corosync+pacemaker实现高可用(HA)集群

    corosync+pacemaker实现高可用(HA)集群(一)     重要概念 在准备部署HA集群前,需要对其涉及的大量的概念有一个初步的了解,这样在实际部署配置时,才不至于不知所云 资源.服务与 ...

随机推荐

  1. why factory pattern and when to use factory pattern

    1 factory pattern本质上就是对对象创建进行抽象 抽象的好处是显然的,可以方便用户去获取对象. 2 使用factory pattern的时机 第一,当一个对象的创建依赖于其它很多对象的时 ...

  2. javascript中apply和call的区别

    请补充   136页  pdf  高级javascript设计

  3. bug-3——onload,onbeforeunload,Onunload的区别

    window.onload事件设置页面加载时执行的动作,即进入页面的时候执行的动作.   window.onunload已经从服务器上读到了需要加载的新的页面,在即将替换掉当前页面时调用 一般用于设置 ...

  4. 请简单介绍一下Spring

    Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 J2EE 应用程序开发提供集成的框架. Spring ...

  5. 小程序连接百度ai

    function getTextFromImage(res) { var access_token = '24.c649256d2e*****0.282335-11449805'; var url = ...

  6. platform-tools

    platform-tools包含开发app的平台依赖的开发和调试工具,包括 adb.fastboot等 android sdk里的各目录作用 AVD Manager.exe:虚拟机管理工具,用于建立和 ...

  7. Spark Structured Streaming框架(4)之窗口管理详解

    1. 结构 1.1 概述 Structured Streaming组件滑动窗口功能由三个参数决定其功能:窗口时间.滑动步长和触发时间. 窗口时间:是指确定数据操作的长度: 滑动步长:是指窗口每次向前移 ...

  8. Centos7 配置yum源 安装epel

    一.什么是epel如果既想获得 RHEL 的高质量.高性能.高可靠性,又需要方便易用(关键是免费)的软件包更新功能,那么 Fedora Project 推出的 EPEL(Extra Packages ...

  9. Delphi UniDAC 通过http协议连接数据库的设置

    Connection through HTTP tunnel(using http protocol) Sometimes client machines are shielded by a fire ...

  10. Java大坑之Integer对象比较相等

    public class IntegerTest { /*** * 对于Integer var = ? 在 -128到127之间的复制,Integer对象是在IntegerCache.cache产生 ...