Heartbeat+DRBD+MySQ+NFS部署文档

系统环境

系统:CentOS6.6

系统位数 x86_64

软件环境

heartbeat-3.0.4-2

drbd-8.4.3

nfs-utils-1.2.3-26

部署环境

角色 IP

VIP 192.168.1.13(内网提供服务的地址)

data-09.com br0:192.168.1.9

data-11.com br0:192.168.1.11

1、DRBD 篇

注意:DRBD可使用硬盘、分区、逻辑卷,但不能建立文件系统

1)、安装依赖包

[[email protected] ~]# yum install gcc gcc-c++ make glibc flex kernel-devel kernel-headers

2)、安装drbd

[[email protected] ~]#wget http://oss.linbit.com/drbd/8.4/drbd-8.4.3.tar.gz

[[email protected] ~]#tar zxvf drbd-8.4.3.tar.gz

[[email protected] ~]#cd drbd-8.4.3

[[email protected] ~]#./configure --prefix=/usr/local/tdoa/drbd --with-km

[[email protected] ~]#make KDIR=/usr/src/kernels/2.6.32-279.el6.x86_64/

[[email protected] ~]#make install

[[email protected] ~]#mkdir -p /usr/local/tdoa/drbd/var/run/drbd

[[email protected] ~]#cp /usr/local/tdoa/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d

[[email protected] ~]#加载DRBD模块:

[[email protected] ~]# modprobe drbd

3)、配置DRBD

主备节点两端配置文件完全一致

[[email protected] ~]#cat /usr/local/drbd/etc/drbd.conf

resource r0{

protocol C;

startup { wfc-timeout 0; degr-wfc-timeout 120;}

disk { on-io-error detach;}

net{

timeout 60;

connect-int 10;

ping-int 10;

max-buffers 2048;

max-epoch-size 2048;

}

syncer { rate 100M;}

on data-09.com{

device /dev/drbd0;

disk   /dev/data/data_lv;

address 192.168.1.9:7788;

meta-disk internal;

}

on data-11.com{

device /dev/drbd0;

disk   /dev/data/data_lv;

address 192.168.1.11:7788;

meta-disk internal;

}

}

4)、初始化drbd的r0资源并启动

在两个节点都要做的操作

[[email protected] ~]# drbdadm create-md r0

[[email protected] ~]# drbdadm up r0

查看data-09.com和data-11.com的状态应该类似下面的:

[[email protected] ~]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-02-26 07:26:07

0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----

ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

5)、将data-09.com提升为主节点并设置启动

[[email protected] ~]# drbdadm primary --force r0

查看data-09.com的状态应该类似下面的:

[[email protected] ~]# cat /proc/drbd

version: 8.4.3 (api:1/proto:86-101)

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-02-26 07:28:26

0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----

ns:4 nr:0 dw:4 dr:681 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

注意:DRBD服务需要开机自启动

2.NFS篇

yum install nfs-utils portmap -y   安装NFS服务

vim /etc/exports

/usr/local/tdoa/data/attach     192.168.100.0/24(rw,no_root_squash)

/usr/local/tdoa/data/attachment 192.168.100.0/24 (rw,no_root_squash)

service rpcbind restart

service nfs restart

chkconfig rpcbind on

chkconfig nfs off

service nfs stop

测试NFS可被前端Web服务器挂载并可写后停止NFS服务

3.Mysql篇

1.建立高可用目录/usr/local/data

data5 目录用于数据库文件

2.heartbeat主修改Mysql数据库存放目录至/usr/local/data/data5

3.主heartbeat和备heartbeat服务器上的Mysql安装完毕后切换DRBD分区切换至备机,备机的Mysql是否正常工作。

将主机降级为备机

[[email protected] /]# drbdadm secondary r0

[[email protected] /]# cat /proc/drbd

在备机data-11.com上, 将它升级为”主机”.

[[email protected]/]# drbdadm primary r0

4、heartbeat篇

(1.1)、YUM安装heartbeat

[[email protected] ~]#wget http://mirrors.sohu.com/fedora-epel/6Server/x86_64/epel-release-6-8.noarch.rpm

[[email protected] ~]# rpm -ivh epel-release-6-8.noarch.rpm

[[email protected] ~]# yum install heartbeat -y

(1.2)、RPM安装heartbeat

1.yum install "liblrm.so.2()(64bit)"

2.rpm -ivh PyXML-0.8.4-19.el6.x86_64.rpm

3.rpm -ivh perl-TimeDate-1.16-13.el6.noarch.rpm

4.rpm -ivh resource-agents-3.9.5-12.el6_6.1.x86_64.rpm

5.rpm -ivh cluster-glue-1.0.5-6.el6.x86_64.rpm

6.rpm -ivh cluster-glue-libs-1.0.5-6.el6.x86_64.rpm

7.rpm -ivh heartbeat-libs-3.0.4-2.el6.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm

备注:heartbeat-libs和heartbeat要一起安装

(2)、配置heartbeat

主备节点两端的配置文件(ha.cf authkeys haresources)完全相同

cp /usr/share/doc/heartbeat-3.0.4/ha.cf /etc/ha.d/

cp /usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/

cp /usr/share/doc/heartbeat-3.0.4/authkeys /etc/ha.d/

vim /etc/ha.d/ha.cf

#############################################

logfile /var/log/ha-log       #日志目录

logfacility     local0        #日志级别

keepalive 2                 #心跳检测间隔

deadtime 5                 #死亡时间

ucast eth3 75.0.2.33         #心跳网卡及对方的IP(备机仅修改此处)

auto_failback off            #主服务器正常后,资源转移至主

node oa-mysql.com oa-haproxy.com   #两个节点的主机名

###############################################################################

vim /etc/ha.d/authkeys      #心跳密码文件权限必须是600

######################

auth 3              #选用算法3,MD5算法

#1 crc

#2 sha1 HI!

3 md5 heartbeat

######################

vim /etc/ha.d/

#########################################################################

data-09.com IPaddr::192.168.1.13/24/br0 drbddisk::r0 Filesystem::/dev/drbd0::/usr/local/data::ext4 mysql nfs

注释:主服务器的主机名 VIP/绑定的网卡 drbd分区:drbd分区挂载目录:文件系统 mysql服务 NFS服务

(5)、创建drbddisk nfs mysql脚本并授予执行权限(三个资源管理脚本需存放在ha.d/resource.d)

[[email protected] ~]#cat /etc/ha.d/resource.d/drbddisk

##################################################################

#!/bin/bash

#

# This script is inteded to be used as resource script by heartbeat

#

# Copright 2003-2008 LINBIT Information Technologies

# Philipp Reisner, Lars Ellenberg

#

###

DEFAULTFILE="/etc/default/drbd"

DRBDADM="/sbin/drbdadm"

if [ -f $DEFAULTFILE ]; then

. $DEFAULTFILE

fi

if [ "$#" -eq 2 ]; then

RES="$1"

CMD="$2"

else

RES="all"

CMD="$1"

fi

## EXIT CODES

# since this is a "legacy heartbeat R1 resource agent" script,

# exit codes actually do not matter that much as long as we conform to

#  http://wiki.linux-ha.org/HeartbeatResourceAgent

# but it does not hurt to conform to lsb init-script exit codes,

# where we can.

#  http://refspecs.linux-foundation.org/LSB_3.1.0/

#LSB-Core-generic/LSB-Core-generic/iniscrptact.html

####

drbd_set_role_from_proc_drbd()

{

local out

if ! test -e /proc/drbd; then

ROLE="Unconfigured"

return

fi

dev=$( $DRBDADM sh-dev $RES )

minor=${dev#/dev/drbd}

if [[ $minor = *[!0-9]* ]] ; then

# sh-minor is only supported since drbd 8.3.1

minor=$( $DRBDADM sh-minor $RES )

fi

if [[ -z $minor ]] || [[ $minor = *[!0-9]* ]] ; then

ROLE=Unknown

return

fi

if out=$(sed -ne "/^ *$minor: cs:/ { s/:/ /g; p; q; }" /proc/drbd); then

set -- $out

ROLE=${5%/**}

: ${ROLE:=Unconfigured} # if it does not show up

else

ROLE=Unknown

fi

}

case "$CMD" in

start)

# try several times, in case heartbeat deadtime

# was smaller than drbd ping time

try=6

while true; do

$DRBDADM primary $RES && break

let "--try" || exit 1 # LSB generic error

sleep 1

done

;;

stop)

# heartbeat (haresources mode) will retry failed stop

# for a number of times in addition to this internal retry.

try=3

while true; do

$DRBDADM secondary $RES && break

# We used to lie here, and pretend success for anything != 11,

# to avoid the reboot on failed stop recovery for "simple

# config errors" and such. But that is incorrect.

# Don‘t lie to your cluster manager.

# And don‘t do config errors...

let --try || exit 1 # LSB generic error

sleep 1

done

;;

status)

if [ "$RES" = "all" ]; then

echo "A resource name is required for status inquiries."

exit 10

fi

ST=$( $DRBDADM role $RES )

ROLE=${ST%/**}

case $ROLE in

Primary|Secondary|Unconfigured)

# expected

;;

*)

# unexpected. whatever...

# If we are unsure about the state of a resource, we need to

# report it as possibly running, so heartbeat can, after failed

# stop, do a recovery by reboot.

# drbdsetup may fail for obscure reasons, e.g. if /var/lock/ is

# suddenly readonly.  So we retry by parsing /proc/drbd.

drbd_set_role_from_proc_drbd

esac

case $ROLE in

Primary)

echo "running (Primary)"

exit 0 # LSB status "service is OK"

;;

Secondary|Unconfigured)

echo "stopped ($ROLE)"

exit 3 # LSB status "service is not running"

;;

*)

# NOTE the "running" in below message.

# this is a "heartbeat" resource script,

# the exit code is _ignored_.

echo "cannot determine status, may be running ($ROLE)"

exit 4 #  LSB status "service status is unknown"

;;

esac

;;

*)

echo "Usage: drbddisk [resource] {start|stop|status}"

exit 1

;;

esac

exit 0

##############################################################

[[email protected] ~]#cat /etc/ha.d/resrouce.d/nfs

killall -9 nfsd; /etc/init.d/nfs restart;exit 0

mysql启动脚本用mysql自带的启动管理脚本即可

cp /etc/init.d/mysql /etc/ha.d/resrouce.d/

注意:nfs mysql drbddisk 三个脚本需要+x 权限

(6)、启动heartbeat

[[email protected] ~]# service heartbeat start (两个节点同时启动)

[[email protected] ~]# chkconfig heartbeat off

说明:关闭开机自启动,当服务器重启时,需要人工去启动

5、测试

在在另外一台LINUX的客户端挂载虚IP:192.168.7.90,挂载成功表明NFS+DRBD+HeartBeat大功告成.

测试DRBD+HeartBeat+NFS可用性:

1.向挂载的/tmp目录传送文件,忽然重新启动主端DRBD服务器,查看变化能够实现断点续传,但是drbd+heartbeat正常切换需要时间

2. 假设此时把primary的eth0 给ifdown了, 然后直接在secondary上进行主的提升,并也给mount了, 发现在primary上测试拷入的文件确实同步过来了。之后把primary的 eth0 恢复后, 发现没有自动恢复主从关系, 经过支持查询,发现出现了drbd检测出现了Split-Brain 的状况, 两个节点各自都standalone了,故障描术如下:Split-Brain detected, dropping connection!这个即时传说中的脑裂了,DRBD官方推荐手动恢复(生产环境下出现这个机率的机会很低的,谁会去故障触动生产中的服务器)

以下手动恢复Split-Brain状况:

1. drbdadm secondary r0

2. drbdadm disconnect all

3. drbdadmin -- --discard-my-data connect r0

ii.在primary上:

1. drbdadm disconnect all

2. drbdadm connect r0

3. 假设Primary因硬件损坏了,需要将Secondary提生成Primay主机,如何处理,方法如下:

在primaty主机上,先要卸载掉DRBD设备.

umount /tmp

将主机降级为备机

[[email protected] /]# drbdadm secondary r0

[[email protected] /]# cat /proc/drbd

1: cs:Connected st:Secondary/Secondary ds:UpToDate/UpToDate C r—

现在,两台主机都是”备机”.

在备机data-11.com上, 将它升级为”主机”.

[[email protected]/]# drbdadm primary r0

[[email protected] /]# cat /proc/drbd

1: cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate C r—

已知问题:

heartbeat无法监控资源,也就是说当drbd或者nfs挂掉了,也不会发生任何动作,它只认为对方的机器dead之后才会发生动作。也就是机器宕机,网络断掉才会发生主备切换,因此有另外一种方案:corosync+pacemaker

时间: 2024-10-10 13:28:31

Heartbeat+DRBD+MySQ+NFS部署文档的相关文章

LVS+Heartbeat安装部署文档

LVS+Heartbeat安装部署文档 发表回复 所需软件: ipvsadm-1.24-10.x86_64.rpmheartbeat-2.1.3-3.el5.centos.x86_64.rpmheartbeat-pils-2.1.3-3.el5.centos.x86_64.rpmheartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpmPyXML-0.8.4-4.x86_64.rpm 系统环境:CentOS 5.4 64-bit HA1            

VDP VMware 备份部署文档

文档内容 安装VDP ova虚拟机,部署VDP备份机制. 基础知识 vSphere Data Protection (VDP) 是一个基于磁盘的备份和恢复解决方案,可靠且易于部署. vSphere Data Protection 与 VMware vCenter Server 完全集成,可以对备份作业执行有效的集中式管理,同时将备份存储在经过重复数据消除的目标存储中,支持Web界面访问. 系统环境 操作系统:ESXi 6.0 预安装准备 在安装 vSphere Data Protection 之

Open-falcon部署文档(绘图及报警)

Open-falcon部署文档(绘图及报警) 部署绘图组件   Agent 采集机器的监控指标, agent与Transfer建立了长连接,数据发送速度比较快,agent提供了一个http接口/v1/push用于接收用户手工push的一些数据,然后通过长连接迅速转发给Transfer. cd agent mv cfg.example.json cfg.json vim cfg.json 修改如上图三处ip, heartbeat hbs的地址,端口是hbs的rpc端口transfer 根据需求可以

Sqlserver2008安装部署文档

Sqlserver2008部署文档 注意事项: 如果你要安装的是64位的服务器,并且是新机器.那么请注意,你需要首先需要给64系统安装一个.net framework,如果已经安装此功能,请略过这一步.   具体安装.net framework的方法是:在图标<我的电脑>上右击选择<管理>,打开以后选择<功能>选项卡,如下图所示,然后点击添加功能,勾选..net framework,然后一直点击下一步安装即可. 安装的过程中,需要注意如果你要安装的服务器有外挂或者附加的

loganalyzer部署文档-(第一部分)

loganalyzer部署文档 环境准备: 简介 LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端.它提供了对日志的简单浏览.搜索.基本分析和一些图表报告的功能.数据可以从数据库或一般的syslog文本文件中获取,所以LogAnalyzer不需要改变现有的记录架构.基于当前的日志数据,它可以处理syslog日志消息,Windows事件日志记录,支持故障排除,使用户能够快速查找日志数据中看出问题的解决方案. LogAnalyzer 获取客户端日志会有两种保存模式,一种是

Nginx部署文档(二进制包安装)

Nginx部署文档(二进制包安装) 创建时间:2016-06-27 修改时间:2017-03-04 修改时间:2017-03-06 文档目的2 基础知识2 常用命令2 系统环境2 操作步骤3 1. 安装依赖3 2. 安装nginx3 3. 启动nginx5 3. 关闭防火墙6 4. 修改生产环境配置6 常见问题7 问题一:报错"cp: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file"7 问题二:[

Wcp知识管理系统部署文档

Wcp知识管理系统部署文档 环境 CentOS-6.5-x86_64-bin-DVD1.iso jdk-7u79-linux-x64.tar.gz apache-tomcat-7.0.72.tar.gz MySQL-5.6.33-1.el6.x86_64.rpm-bundle.tar WCP知识管理系统v3.2.0(免费版.开源) http://www.wcpdoc.com/webdoc/view/Pub8a2831b350e6b01f0150e6c1ad5a009f.html 下载地址:百度云

ElasticSearch部署文档(Ubuntu 14.04)

ElasticSearch部署文档(Ubuntu 14.04) 参考链接 https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html#setup-configuration https://www.elastic.co/guid

zabbix监控安装部署文档

Zabbix监控部署文档 创建时间:2017.02.19          文档目的 安装部署Zabbix服务器和Zabbix客户端,监控客户端服务器的硬件状态 基础知识 zabbix(音同 zbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题. zabbix由2部分构成,zabbix server与可选组件zabbix agent. z