澳门在线威尼斯官方 > 电脑操作 > 【澳门在线威尼斯官方】drbd+nfs+heartbeat高可用

原标题:【澳门在线威尼斯官方】drbd+nfs+heartbeat高可用

浏览次数:169 时间:2019-12-01

        }

echo "running (Primary)"

global {

 

                cram-hmac-alg "sha1";   //DRBD同步时使用的验证方式和密码信息

yum install ncurses* -y

                on-io-error detach;

# vi /etc/ha.d/ha.cf

安装DRBD

# vi /etc/ha.d/haresources

        }

sync'ed:同步进度

 chkconfig nfs off

yum install gcc-c++ -y

测试

fi

        }

set -- $out

   p   primary partition (1-4)

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

}

                fencing resource-only;

tar xf libnet-1.1.2.1.tar.gz

fi

 

done

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

                meta-disk internal;                                                //DRBD的源数据存方式

                address 10.10.10.167:7788;

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

###

mkdir /data

 

;;

配置主机名、IP、hosts文件、关闭selinux、iptables

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

   p   primary partition (1-4)

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

                 out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";

         IP1:10.10.10.167

IPADDR=10.10.10.50

 

                 wfc-timeout 120;

 

 

cd ..

此时备机node2上的DRBD状态:

模拟将主节点node1 的heartbeat服务停止,则备节点node2会立即无缝接管;测试客户端挂载的NFS共享读写正常。

启动DRBD(同时)

fdisk /dev/ddb

                fencing resource-only;

 

 

if ! test -e /proc/drbd; then

ROLE=${ST%/**}

NFS2

try=6

case $ROLE in

主设备进行格式化

DRBD在IP网络传输,所有在集中使用DRBD作为共享存储设备,不需要任何硬件投资,可以节约很多成本

 

        

         version: 8.3.16 (api:88/proto:86-97)

keepalive       2

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

 

         CentOS 6

 

 

        }

         VIP:10.10.10.50

编辑脚本文件killnfsd,用来重启NFS服务:(node1,node2)

DEVICE=eth0:0

m:res  cs         ro                 ds                 p  mounted     fstype

 

0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /store      ext4

fi

sleep 1

 

 service nfs restart

drbd_set_role_from_proc_drbd

         drbdadm primary r0或者 drbdadm primary all

 

        on master-drbd {                                                                       //每个主机的说明以on开头后面是hostname(与uname -n一样)

 

;;

NFS1

 

Sector size (logical/physical): 512B/512B

 service heartbeat start

                disk /dev/sdb1;                                                                 // drbd0使用的磁盘分区是/dev/sdb1

编辑drbddisk,添加下面的脚本内容

        net {

parted -s /dev/sdb mkpart primary 81% 100%                           

                 pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

 

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

yum install imake* -y

#  

fi

case $ROLE in

minor=${dev#/dev/drbd}

         ns表示网络发送的数据包信息

         IP1:10.10.10.166     心跳和数据传输网卡  不配置网关,添加路由即可

                # They may have severe implications,

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

        protocol C;                                             //使用的协议

case "$CMD" in

          

         mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

此时node2上的DRBD状态:

主宕机后先启动drbd  然后再起的heartbeat

global {

$DRBDADM primary $RES && break

# heartbeat (haresources mode) will retry failed stop

DRBDADM="/sbin/drbdadm"

deadtime        5

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd2.corp.com, 2015-05-12 21:05:41

                   echo "modprobe drbd > /dev/null 2>&1" > /etc/sysconfig/modules/drbd.modules

;;

在两个节点上启动HeartBeat服务,先启动node1:(node1,node2)

Command action

yum install glibc* -y

cp ifcfg-eth0 ifcfg-eth0:0

 

         disk {                                                                                                                //使用dpod功能保证在数据不同步时不进行切换

在执行执行一次分出sdb2  w保存分区                                          

 

ds状态变为UpToDate/UpToDate说明成功了

                address 192.168.100.10:7788;                          //

重启NFS服务:

 

*)

   exit 10

yum install glib* -y

 chmod 755 /etc/ha.d/resource.d/drbddisk

common {

chmod 755 /etc/ha.d/resource.d/killnfsd

                shared-secret "nfs-ha";

                                                                 p

安装Heartbeat

 

 

         mount只能用在主设备上,因此只要主设备才能格式化挂载。

 

1、正常热备切换

        on nfs2 {

                address 10.10.10.166:7788;

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

         mkfs.ext4 /dev/drbd0

# vi /etc/exports

        }

挂载DRBD设备

# this is a "heartbeat" resource script,

 

# service drbd status

}

# mount -t nfs 192.168.0.190:/store /tmp

# vi /etc/ha.d/authkeys

分出两个区,一个数据同步使用sdb1,一个记录日志sdb2

Secondary|Unconfigured)

 

yum install perl-Parse-* perl-Mail-DKIM* -y

 

 

ROLE="Unconfigured"

Command (m for help): n

# And don't do config errors...

ROLE=Unknown

resource nfsha {

 

 RES="all"

 

 

                on-io-error detach;

 

                   lsmod | grep -i drbd

}

 

else

 

esac

/data        *(rw,no_root_squash)

esac

                # These are EXAMPLE handlers only.

CentOS 6

        

yum install perl-LDAP-0.40-1.el6.noarch.rpm -y

                 degr-wfc-timeout 120;

                 pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

         mount /dev/drbd0 /data

 CMD="$2"

        

                address 192.168.100.20:7788;

;;

Primary)

# try several times, in case heartbeat deadtime

Number  Start   End     Size    File system  Name     标志

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

                cram-hmac-alg "sha1";

# rpm -Uvh

                   modprobe drbd

 

#

 

         tune2fs -c -1 /dev/drbd0

 

 

 

         检查是否安装成功

                disk /dev/sdb1;

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

 

Last cylinder, +cylinders or +size{K,M,G} (1305-2610, default 2610):+10G

ROLE=Unknown

logfile         /var/log/ha-log

设置主用节点

 

        

0:r0   Connected  Primary/Unknown    UpToDate/DUnknown  C  /store      ext4

        

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

 

                meta-disk internal;

                   startup {

                # like hard resetting the node under certain circumstances.

*)

 

                   启动DRBD service drbd start

编辑双机互联验证文件authkeys,添加以下内容:(node1,node2)

 

 

yum install autoconf* -y

 

                  

CentOS 7

node           nfs1 nfs2

        

Partition Table: gpt

#

GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37

# unexpected. whatever...

1 crc

cp ha.cf haresources authkeys /etc/ha.d/

# vi /etc/ha.d/resource.d/drbddisk

打印分区结果

yum install lm_sensors* -y

        }

 

                disk /dev/sdb1;

配置vip

 

fi

在客户端挂载NFS共享目录

resource r0 {                                                   //资源名称

 

yum install beecrypt* -y

 

                 wfc-timeout 120;

给验证文件600权限

ucast           eth0 10.10.10.166

#include "drbd.d/global_common.conf";

 

ucast           eth0 10.10.10.167    # 指定对方网卡及IP

赋予755执行权限:

# sh-minor is only supported since drbd 8.3.1

drbd_set_role_from_proc_drbd()

 

                   cat /proc/drbd

#include "drbd.d/*.res";

                            添加路由:route add -host IP dev eth0并且写在rc.local内

 

 

 

                 degr-wfc-timeout 120;

        device /dev/drbd0;

        }

echo "stopped ($ROLE)"

 

ONBOOT=yes

cd /etc/sysconfig/network-scripts/

Command (m for help): n

keepalive       2

auth 1

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

安装drbd源

    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:5242684

;;

         ro表示角色信息,第一次启动时都为Secondary(备)状态

                meta-disk internal;

        syncer {rate 200M; }                  //设置主备节点同步时速率的最大值单位是字节

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

yum install openssl openssl-devel -y

 

设置从 drbdadm secondary nfsha

exit 0

         主操作

# stop, do a recovery by reboot.

 

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

复制配置信息到另一台主机

deadtime        5

 

 

# NOTE the "running" in below message.

}

#!/bin/bash

# the exit code is _ignored_.

artition number (1-4): 1

 

                meta-disk internal;

 . $DEFAULTFILE

                disk /dev/sdb1;

$DRBDADM secondary $RES && break

         查看drbd.ko安装路径

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

vim /etc/drbd.confi

# rpm --import

          mount /dev/drbd0 /data

parted -s /dev/sdb mkpart primary 0% 80%

}

node2节点也会立即无缝接管,测试客户端挂载的NFS共享读写正常。

         version: 8.3.16 (api:88/proto:86-97)

 chkconfig rpcbind on

if [ -f $DEFAULTFILE ]; then

logfacility     local0

   status)

 

        

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

#

exit 3 # LSB status "service is not running"

         关闭DRBD开机自启动

## EXIT CODES

 

drbd driver loaded OK; device status:

          drbdadm primary nfsha

exit 0 # LSB status "service is OK"

while true; do

强制关机,直接关闭node1电源

# service drbd status

yum install libnet* -y

         加载DRBD到内核

 

sleep 1

# chmod 600 /etc/ha.d/authkeys

   *)

yum makecache

编辑ha.cf,添加下面配置:

编辑集群资源文件:(nfs1,nfs2)

cd /etc/ha.d/

配置DRBD

;;

        startup {

          挂载查看是否含有test.file

        handlers {

         drbdsetup /dev/drbd0 primary -o

安装nfs  yum install nfs-utils rpcbind

                # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";

CentOS 7

return

 

GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd2.corp.com, 2015-05-12 21:05:41

DRBD是一种基于软件的、基于网络的块复制存储解决方案

升级内核yum install kernel kernel-devel kernel-headers -y

 

yum install bzip2* -y

try=3

 

                   modprobe -l | grep -i drbd

 

启动之后再次查看状态        

 

解释:

# Don't lie to your cluster manager.

         dw表示磁盘写信息

Filesystem::/dev/drbd0::/data::ext4:用Filesystem脚本实现磁盘挂载和卸载

GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37

 service rpcbind restart

                 local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";

   stop)

   e   extended

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

         VIP:10.10.10.150

 

rpm -Uvh

         两台主机分别磁盘分区

fi

        

####

# vi /etc/ha.d/resource.d/killnfsd

 

          drbdadm secondary all

        }

Disk /dev/sdb: 21.5GB

./ConfigureMe configure --enable-fatal-warnings=no --disable-swig --disable-snmp-subagent

 2      17.4GB  21.5GB  4079MB               primary

配置NFS:(nfs1,nfs2)

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

 

(nfs2)

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

nfs  heartbeat、drbd不要设置成开机自启动

DEFAULTFILE="/etc/default/drbd"

# where we can.

# vi /etc/ha.d/ha.cf

 RES="$1"

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

现在从其他机器能够ping通虚IP 192.168.0.190,表示配置成功

IPaddr::10.10.10.0/24/eth0:用IPaddr脚本配置对外服务的浮动虚拟IP

         要在备设备上挂载,必须先卸载主,在升级备为主,然后再挂载

        syncer { rate 200M; }

                                                                 p

nfs1 IPaddr::10.10.10.50/24/eth0 drbddisk::nfsha Filesystem::/dev/drbd0::/data::ext4 killnfsd

drbd driver loaded OK; device status:

GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2014-11-24 14:51:37

 

        }

等待一段时间再次查看(同步时间可能很长)

 

         disk {

         备用节点升级为主

esac

# Copright 2003-2008 LINBIT Information Technologies

        }

赋予755执行权限:

NETMASK=255.255.255.255

common {

         查看节点状态        

                   加载不成功执行depmod然后重启

创建DRBD脚本文件drbddisk:(nfs1,nfs2)

设置heartbeat配置文件

        device /dev/drbd0;

        usage-count no;

(nfs1)

fi

yum install perl-Compress* perl-libwww* perl-HTML* perl-XML* perl-Net* perl-IO* perl-Digest* -y

挂载

rpm -Uvh elrepo-release-6-6.el6.elrepo.noarch.rpm

make &&make install

        net {

配置阿里云源

                   version: 8.3.16 (api:88/proto:86-97)

Model: VMware, VMware Virtual S (scsi)

启动HeartBeat服务

         首先创建供DRBD记录信息的数据块

                   两台主机分别执行drbdadm create-md nfsha或者drbdadm create-md all

          dd if=/dev/zero of=/data/test.file bs=100M count=2

五、测试高可用

 

while true; do

         [=================>..] sync'ed: 91.9% (416/5116)M

 

yum install net-snmp* -y

parted -s /dev/sdb mklabel gpt                                             #分区表转换为GPT       

                 split-brain "/usr/lib/drbd/notify-split-brain.sh root";

 

 

 

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

 

                # Be careful when chosing your poison.

cd /usr/share/doc/heartbeat-2.0.7/

;;

        

return

                shared-secret "nfsha";

# Philipp Reisner, Lars Ellenberg

exit 4 #  LSB status "service status is unknown"

编辑exports配置文件,添加以下配置:

yum install pam-devel -y

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

yum install python-devel -y

;;

 

          umount /data

yum install tkinter* -y

tar xf heartbeat-2.0.7.tar.gz

node            nfs1 nfs2

编辑ha.cf,添加下面配置:

cd libnet

                # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";

# expected

注:这里设置NFS开机不要自动运行,因为/etc/ha.d/resource.d/killnfsd 该脚本会控制NFS的启动。

[root@mfsmaster ~]# parted /dev/sdb p

Primary|Secondary|Unconfigured)

 

        on slave-drbd {

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

 

 1      1049kB  17.2GB  17.2GB               primary

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

yum install elfutils* -y

yum install flex -y

         安装成功之后drbd相关工具(drbdadm,drbdsetup)被安装在/sbin/目录下       

 

}

这里ip为虚ip   注意网卡(eth0)资源名(nfsha)和挂载点(data)

 

drbddisk::nfsha:用drbddisk脚本实现DRBD主从节点资源组的挂载和卸载

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

        on nfs1 {

ST=$( $DRBDADM role $RES )

 

         DRBD至少使用两个分区需要单独分出来

 

异常宕机切换

wget -O /etc/yum.repos.d/CentOS-Base.repo

make install

auto_failback   off

 

logfacility     local0

}

 

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

注:该文件内IPaddr,Filesystem等脚本存放路径在/etc/ha.d/resource.d/下,也可在该目录下存放服务启动脚本(例如:mysql,www),将相同脚本名称添加到/etc/ha.d/haresources内容中,从而跟随heartbeat启动而启动该脚本。

 

          

#  

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

查看备用节点是否同步

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

 

   start)

cd heartbeat-2.0.7

yum install libxslt* -y

或者

 

 

auto_failback   off

logfile         /var/log/ha-log

else

m:res  cs         ro                 ds                 p  mounted     fstype

         finish: 0:00:10 speed: 40,304 (38,812) K/sec

        }

                # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;

        usage-count no;  #允不允许官方统计

local out

./configure

ROLE=${5%/**}

 

   e   extended

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

First cylinder (1-2610, default 1): 回车

{

        

 CMD="$1"

         dr表示磁盘读信息

         ds表示磁盘信息,Inconsistent表示磁盘数据不一致状态

wget -O /etc/yum.repos.d/CentOS-Base.repo

         yum install kmod-drbd83 drbd83 -y

done

 

exit 1

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

 

 

Command action

 

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

配置drbd

# was smaller than drbd ping time

./ConfigureMe make --enable-fatal-warnings=no || gmake

 

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

        protocol C;

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

本文由澳门在线威尼斯官方发布于电脑操作,转载请注明出处:【澳门在线威尼斯官方】drbd+nfs+heartbeat高可用

关键词:

上一篇:【澳门在线威尼斯官方】教你分分钟搞定Docker私

下一篇:没有了