阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Heartbeat 与DRBD 配置过程

247次阅读
没有评论

共计 3682 个字符,预计需要花费 10 分钟才能阅读完成。

我的 PC 机都只有 1 个网卡,所以我用串口使双机通讯;

192.168.119.1 是我的路由器的 IP,作为一个域外的服务器,检测域内服务器是否正常;

首先配置 host 文件:

127.0.0.1 localhost
127.0.1.1 Ubuntu-Bing

192.168.119.102 ubuntu-Bing
192.168.119.103 Lab-Server

拷贝配置文件:

 cp  /usr/local/ha/share/doc/authkeys  /usr/local/ha/etc/ha.d
 cp  /usr/local/ha/share/doc/ha.cf  /usr/local/ha/etc/ha.d
 cp  /usr/local/ha/share/doc/haresources  /usr/local/ha/etc/ha.d

ha.d 文件:

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
baud 19200
serial /dev/ttyS0 # Linux
auto_failback on
node ubuntu-Bing
node Lab-Server
ping 192.168.119.1
respawn hacluster /usr/lib/ocf/resource.d/heartbeat/pingd -m 100 -d 5s
apiauth pingd gid=haclient uid=hacluster

compression bz2
compression_threshold 2

resource.d 目录下 drbddisk 脚本

#!/bin/bash
#
# This script is intended 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

先配置好 DRBD 服务,然后再启动 heartbeat 服务;测试 Heartbeat!

停止主服务器的 heartbeat 服务,然后查看 /mnt/drbd 下是否可以看到文件!如果可以,说明成功了!

DRBD 的详细介绍 :请点这里
DRBD 的下载地址 :请点这里

相关阅读

Linux 高可用(HA)集群之 DRBD 详解 http://www.linuxidc.com/Linux/2013-08/89035.htm

DRBD 中文应用指南 PDF http://www.linuxidc.com/Linux/2013-08/89034.htm

CentOS 6.3 下 DRBD 安装配置笔记 http://www.linuxidc.com/Linux/2013-06/85600.htm

基于 DRBD+Corosync 实现高可用 MySQL http://www.linuxidc.com/Linux/2013-05/84471.htm

CentOS 6.4 下 DRBD 安装配置 http://www.linuxidc.com/Linux/2013-09/90536.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计3682字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中