在上一篇文章中描述了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. js绑定键盘enter事件

    js写法: document.onkeydown = function(event){ var event=document.all?window.event:event; if((event.key ...

  2. (转)关于Http协议,一片就够了

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  3. CodeForces - 580C Kefa and Park 【BFS】

    题目链接 http://codeforces.com/problemset/problem/580/C 题意 根节点是 1 然后所有的叶子结点都是饭店 从根节点到叶子结点的路径上 如果存在 大于m 个 ...

  4. 培训笔记——Linux基本命令

    在介绍命令之前,更重要的要先介绍一下快速输入命令的方法. 如果你能记住一些常用命令,毫无疑问,通过命令的操作方式比通过鼠标的操作方式要快. 但是有一些命令或是命令用到的参数如文件名特别复杂特别长,这时 ...

  5. 【leetcode刷题笔记】Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. 题解:以strs[0]为模 ...

  6. android 电池(二):android关机充电流程、充电画面显示【转】

    本文转载自:http://blog.csdn.net/xubin341719/article/details/8498580 上一篇我们讲了锂电池的充放电的流程和电池的一些特性,这一节我们重点说一下a ...

  7. 剑指offer之 数值的整数次方

    问题描述:实现函数double power(double base,int exponent),求base的exponent次方.不能使用库函数,同时不需要考虑大数问题. package Proble ...

  8. EntityFramework 学习 一 Eager Loading

    贪婪加载是指查询一个类型实体的时候同时查询与实体关联的类型 通过Include()方法实现 using (var context = new SchoolDBEntities()) { var stu ...

  9. 算法(Algorithms)第4版 练习 1.3.7

    package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; import ed ...

  10. Oracle的PL_SQL的结构

    --PL/SQL的结构 declare --声明变量和常量关键字 v_name nvarchar2(); v_age integer;--常规变量声明 v_product table_name.col ...