乐虎游戏|乐虎国际登录|欢迎你

Heartbeat+DRBD+NFS案例详解

日期:2019-12-05编辑作者:计算机资讯

DRBD简介

DRBD+Heartbeat 解决NFS单点故障

1.1  环境准备
1.1.1          添加新磁盘,分区并格式化

fdisk -uc /dev/sdb
mkfs.ext4 /dev/sdb1
dd if=/dev/zero of=/dev/sdb1bs=1M count=1

1.1.2          在hosts文件中添加以下记录

cat /etc/host
172.16.1.111 test01
172.16.1.112 test02
172.16.1.113 web

1.1.3          关闭selinux和iptables

setenforce 0
/etc/init.d/iptables stop

1.1.4          测试约定

主机名,系统版本及内核版本:

[[email protected] ~]# uname -nr
test01 2.6.32-573.el6.x86_64
[[email protected] ~]# cat /etc/RedHat-release
CentOS release 6.7 (Final)

[[email protected] ~]# uname -nr
test02 2.6.32-573.el6.x86_64
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)

[[email protected] ~]# uname -nr
web 2.6.32-573.el6.x86_64
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)

测试IP:

test01 172.16.1.111
test02 172.16.1.112
web  172.16.1.113
虚拟IP 172.16.1.100

1.2  DRBD的安装
1.2.1          配置DRBD
默认官方源中没有drbd软件,所以使用elrepo源

[[email protected] ~]# rpm --import
[[email protected] ~]# rpm -Uvh
Retrieving
Preparing...              ########################################### [100%]
  1:elrepo-release        ########################################### [100%]
[[email protected] ~]# yum installdrbd84-utils kmod-drbd84 -y

[[email protected] ~]# modprobe drbd
[[email protected] ~]# lsmod|grepdrbd
drbd                  365931  0
libcrc32c              1246  1 drbd

编辑配置文件

[[email protected] ~]# vim/etc/drbd.conf
# You can find an examplein  /usr/share/doc/drbd.../drbd.conf.example
#include"drbd.d/*.res";
global{
    usage-count no;
}
common{
    syncer{
        rate 200M;
    }
}
resource r1 {
      protocol C;
      startup{
          wfc-timeout 120;
          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;
          cram-hmac-alg"sha1";
          shared-secret"Mysql-abcD";
      }
      on test01 {
          device /dev/drbd0;
          disk /dev/sdb1;
          address 172.16.1.31:6666;
          meta-disk internal;
      }
      on test02 {
          device /dev/drbd0;
          disk /dev/sdb1;
          address 172.16.1.41:6666;
          meta-disk internal;
      }
}

1.2.3          初始化设

[[email protected] ~]# drbdadmcreate-md r1
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data blocksuccessfully created.
[[email protected] ~]# drbdadm up r1
[[email protected] ~]# cat /proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 2015-04-0914:35:00
 0: cs:Connected ro:Secondary/Secondaryds:Inconsistent/Inconsistent C r-----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0ua:0 ap:0 ep:1 wo:f oos:5241660

现在两个节点都处于Secondary状态     

将test01手动提升至primary。并将/dev/drbd0进行格式化以供挂在使用

[[email protected] ~]# drbdadmprimary --force r1
[[email protected] ~]# cat/proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70build by [email protected], 2015-12-07 10:40:31
 0: cs:Connected ro:Primary/Secondaryds:UpToDate/UpToDate C r-----
    ns:1047484 nr:0 dw:0 dr:1048148 al:0 bm:0lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

1.2.4          格式化虚拟分区

[[email protected] ~]# mkfs.ext4/dev/drbd0
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
..
...
Writing superblocks andfilesystem accounting information: 完成
 
This filesystem will beautomatically checked every 33 mounts or
180 days, whichever comesfirst.  Use tune2fs -c or -i to override.
[[email protected] ~]# tune2fs -c -1/dev/drbd0
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to-1

1.2.5          挂载测试

[[email protected] ~]# mkdir /data
[[email protected] ~]# mount -t ext4/dev/drbd0 /data
[[email protected] ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.5G  7.4G  17% /
tmpfs          495M    0  495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data
[[email protected] ~]# touch/data/drbd.test
[[email protected] ~]# ls /data/
drbd.test lost+found

手动切换连个节点状态,并进行挂载测试

[[email protected] ~]# umount /data
[[email protected] ~]# drbdadmsecondary r1
[[email protected] ~]# cat/proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 2015-12-0710:40:31
 0: cs:Connected ro:Secondary/Secondaryds:UpToDate/UpToDate C r-----
    ns:1080828 nr:0 dw:33344 dr:1048921 al:10bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

将test01手动提升至primary。并将/dev/drbd0进行格式化以供挂在使用

[[email protected]]# drbdadm primary r1
[[email protected]]# cat /proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 2015-12-0710:40:31
 0: cs:Connected ro:Primary/Secondaryds:UpToDate/UpToDate C r-----
    ns:0 nr:1080828 dw:1080828 dr:664 al:0 bm:0lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] ~]# mkdir /data
[[email protected] ~]# mount -t ext4/dev/drbd0 /data
[[email protected] ~]# ls /data/
drbd.test lost+found
[[email protected] ~]# umount /data
[[email protected] ~]# drbdadmsecondary r1

现在drbd两个节点已经配置成功,并手动测试成功。drbd的两个节点,同时时间只有primary状态的节点提供服务。

1.3  配置nfs服务
test01 test02 web配置nfs的共享目录为/data ,test01 test02同时/dev/drbd0的挂载目录也是/data

1.3.1          将test01 drbd状态提升为primary并将/dev/drbd0挂载至/data,编辑/etc/exports文件,并本地测试。

[[email protected] ~]# cat/proc/drbd 
version: 8.4.6(api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70build by [email protected], 2015-12-07 10:40:31
 0: cs:Connected ro:Secondary/Secondaryds:UpToDate/UpToDate C r-----
    ns:1080828 nr:8 dw:33352 dr:1048921 al:10bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[[email protected] ~]# drbdadmprimary r1
[[email protected] ~]# mount -t ext4/dev/drbd0 /data
[[email protected] ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
计算机,/dev/sda2      9.4G 1.5G  7.4G  17% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

[[email protected] ~]# cat/etc/exports 
/data172.16.1.0/24(rw,sync,all_squash)

[[email protected] ~]#/etc/init.d/rpcbind start
[[email protected] ~]#/etc/init.d/nfs start
[[email protected] ~]# chown -R nfsnobody.nfsnobody/data
[[email protected] ~]# showmount -e172.16.1.111
Export list for 172.16.1.111:
/data 172.16.1.0/24

[[email protected] ~]# mount -t nfs172.16.1.111:/data /mnt
[[email protected] ~]# ls /mnt
drbd.test lost+found
[[email protected] ~]# touch/mnt/test01.test
[[email protected] ~]# ls /mnt
drbd.test lost+found  test01.test

1.3.2          将test01状态降为secondary,将test02状态提升为primary,并将/dev/drbd0挂载至/data,编辑/etc/exports文件,并本地测试

[[email protected] ~]# umount /mnt
[[email protected] ~]#/etc/init.d/nfs stop
[[email protected] ~]# umount /data
[[email protected] ~]# drbdadmsecondary r1
[[email protected] ~]# cat/proc/drbd
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 2015-12-0710:40:31
 0: cs:Connected ro:Secondary/Secondaryds:UpToDate/UpToDate C r-----
    ns:1080952 nr:8 dw:33476 dr:1049979 al:10bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

[[email protected] ~]# drbdadm primary r1
[[email protected] ~]# mount -t ext4/dev/drbd0 /data
[[email protected] ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.5G  7.4G  17% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

[r[email protected] ~]# cat/etc/exports 
/data172.1.6.0/24(rw,sync,all_squash)

[[email protected] ~]#/etc/init.d/rpcbind start
[[email protected] ~]#/etc/init.d/nfs start
[[email protected] ~]# chown -Rnfsnobody.nfsnobody /data
[[email protected] ~]# showmount -e172.16.1.112
Export list for 172.16.1.112:
/data 172.16.1.0/24

[[email protected] ~]# mount -t nfs172.16.1.112:/data /mnt
[[email protected] ~]# ls /mnt
drbd.test lost+found  test01.test
[[email protected] ~]# touch/mnt/test02.test
[[email protected] ~]# ls /mnt
drbd.test lost+found  test01.test  test02.test

[[email protected] ~]# umount /mnt
[[email protected] ~]#/etc/init.d/nfs stop
[[email protected] ~]# umount /data
[[email protected] ~]# drbdadmsecondary r1
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 2015-12-0710:40:31
 0: cs:Connected ro:Secondary/Secondaryds:UpToDate/UpToDate C r-----
    ns:124 nr:1080952 dw:1081076 dr:1726 al:2bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

至此:drbd nfs手动挂载测试成功

1.4  配置heartbeat
配置heartbeat以达到nfs主节点失效自动将所有资源切换到备用节点

1.4.1          两台nfs服务器上安装heartbeat
添加epel扩展源。官方yum源没有heartbeat

yum -y install epel-release
yum install heartbeat -y

1.4.2          将两台服务器默认配置文件拷贝到/etc/ha.d/并做更改

[[email protected] ~]# rpm -qdheartbeat|grep doc
/usr/share/doc/heartbeat-3.0.4/AUTHORS
/usr/share/doc/heartbeat-3.0.4/COPYING
/usr/share/doc/heartbeat-3.0.4/COPYING.LGPL
/usr/share/doc/heartbeat-3.0.4/ChangeLog
/usr/share/doc/heartbeat-3.0.4/README
/usr/share/doc/heartbeat-3.0.4/apphbd.cf
/usr/share/doc/heartbeat-3.0.4/authkeys
/usr/share/doc/heartbeat-3.0.4/ha.cf
/usr/share/doc/heartbeat-3.0.4/haresources

1 [[email protected] ~]# cp/usr/share/doc/heartbeat-3.0.4/authkeys /usr/share/doc/heartbeat-3.0.4/ha.cf/usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/

[[email protected] ~]# egrep -v"#|^$" /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility    local0
keepalive 2
deadtime 30
warntime 10
initdead 60
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node    test01
node    test02

[[email protected] ~]# egrep -v"#|^$" /etc/ha.d/authkeys
auth 1
1 sha1 liyanan
[[email protected] ~]# chmod600  /etc/ha.d/authkeys
[[email protected] ~]# ll  /etc/ha.d/authkeys       
-rw------- 1 root root 647 12月  7 15:13 /etc/ha.d/authkeys
 
[[email protected] ~]#echo " test01drbddisk::r1 Filesystem::/dev/drbd0::/data::ext4 nfsIPaddr::172.16.1.100/24/eth1
" >>/etc/ha.d/haresources

将附件的脚本加入到/etc/ha.d/resource.d/ 下并赋予可执行权限。

1.4.3          启动两台服务器heartbeat

[[email protected] ~]#/etc/init.d/heartbeat start
[[email protected] ~]#/etc/init.d/heartbeat status
heartbeat OK [pid 5362 et al]is running on test01 [test01]...

1.4.4          测试heartbeat

全部启动heartbeat服务

[[email protected] ha.d]#/etc/init.d/heartbeat status
heartbeat OK [pid 22646 et al]is running on test01 [test01]...
[[email protected] ~]#/etc/init.d/heartbeat status
heartbeat OK [pid 13217 et al]is running on test02 [test02]...

检查test01挂载

[[email protected] ha.d]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

检查test02挂载

[[email protected] ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot

关闭test01的heartbeat服务后再检查挂载

[[email protected] ha.d]#/etc/init.d/heartbeat stop
Stopping High-Availabilityservices: Done.

[[email protected] ha.d]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0  495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot

再次检查test02挂载

[[email protected] ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

再次启动test01的heartbeat服务,并检查挂载

[[email protected] ha.d]#/etc/init.d/heartbeat start
Starting High-Availabilityservices: Done.

[[email protected] ha.d]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

再次检查test02挂载

[[email protected] ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot

经过循环测试,证明heartbeat服务已经成功接管drbd nfs VIP服务

可通过VIP向外部提供nfs挂载解决nfs单点故障。

终极测试,循环写入数据测试丢包率

测试方式:由test01为主,提供nfs服务、test02为备,接管nfs服务。web挂载test01提供的nfs共享目录。通过间隔 1S 连续在web的挂载点上写入数据,期间手动关闭test01的heartbeat服务,造成意外宕机的实验效果,等脚本执行完毕后,在web端查看写入的数据,以便检测丢包率。

检查挂载情况及虚拟IP

[[email protected] ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2      9.4G  1.6G  7.4G  18% /
tmpfs          242M    0  242M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      4.8G  11M  4.6G  1% /data
[[email protected] ~]# ip add |grep 172.16
    inet 172.16.1.111/24 brd 172.16.1.255 scope global eth1
    inet 172.16.1.100/24 brd 172.16.1.255 scope global secondary eth1


[[email protected] ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2      9.4G  1.6G  7.4G  18% /
tmpfs          242M    0  242M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
[[email protected] ~]# ip add |grep 172.16
    inet 172.16.1.112/24 brd 172.16.1.255 scope global eth1


[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2            9.4G  2.1G  6.9G  24% /
tmpfs                242M    0  242M  0% /dev/shm
/dev/sda1            190M  36M  145M  20% /boot
172.16.1.100:/data  4.8G  11M  4.6G  1% /data/www/

测试脚本:

for ((n=1;n<30;n++))
do 
  touch /data/www/$n
  sleep 1
done

期间关闭test01的heartbeat服务,并检查最终测试结果

[[email protected] ~]# ls /data/www/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29

测试结果表明数据丢包率为0,试验成功。

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是www.bkjia.com

具体下载目录在 /2015年资料/12月/22日/DRBD+Heartbeat 解决NFS单点故障/

下载方法见

------------------------------------------分割线------------------------------------------

有关DRBD的相关知识,可以参考:
DRBD原理及特性概述
快速安装及部署DRBD 

Linux 高可用(HA)集群之DRBD详解

DRBD中文应用指南 PDF

CentOS 6.3下DRBD安装配置笔记

基于DRBD+Corosync实现高可用MySQL

CentOS 6.4下DRBD 安装配置

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

本文永久更新链接地址:

解决NFS单点故障 1.1 环境准备 1.1.1 添加新磁盘,分区并格式化 fdisk -uc /dev/sdb mkfs.ext4 /dev/sdb1 dd if=/dev/zero of=/dev/sdb1bs=1M count=1 1....

   Distributed Replicated Block Device(DRBD)是一个用软件实现的、无共享的、服务器之间镜像块设备内容的存储复制解决方案。      数据镜像:实时、透明、同步所有服务器都成功后返回)、异步本地服务器成功后返回)         DBRD的核心功能通过Linux的内核实现,最接近系统的IO栈,但它不能神奇地添加上层的功能比如检测到EXT3文件系统的崩溃。        DBRD的位置处于文件系统以下,比文件系统更加靠近操作系统内核及IO栈。 实验背景: 本实验部署DRBD + HEARDBEAT + NFS 环境,建立一个高可用(HA)的文件服务器集群。在方案中,通过DRBD保证了服务器数据的完整性和一致性。DRBD类似于一个网络RAID-1功能。当你将数据写入本地文件系统时,数据还将会被发送到网络中另一台主机上,以相同的形式记录在一个另文件系统中。主节点与备节点的数据可以保证实时相互同步。当本地主服务器出现故障时,备份服务器上还会保留有一份相同的数据,可以继续使用。在高可用(HA)中使用DRBD功能,可以代替使用一个共享盘阵。因为数据同时存在于本地主服务器和备份服务器上。切换时,远程主机只要使用它上面的那份备份数据,就可以继续提供主服务器上相同的服务,并且client用户对主服务器的故障无感知。 实验拓扑:

计算机 1 

实验步骤:

一、准备环境 1、系统环境 # uname –r            #内核版本 2.6.18-164.el5 # cat /etc/redhat-release #查看系统信息 Red Hat Enterprise Linux Server release 5.4 (Tikanga) 2、修改主机名称等 在节点1上进行修改 # hostname node1.a.com          #修改主机名称 # vim /etc/sysconfig/network         #修改文件 NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=node1.a.com       之后退出再次登陆 # hostname                       #查看名称 node1.a.com # vim /etc/hosts                  #修改hosts文件 127.0.0.1                localhost.localdomain localhost ::1             localhost6.localdomain6 localhost6 192.168.10.20 node1.a.com 192.168.10.30 node2.a.com 在节点2上进行修改 # hostname node2.a.com            #修改主机名称 # vim /etc/sysconfig/network           #修改文件 NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=node2.a.com 之后退出再次登陆 # vim /etc/hosts              #修改hosts文件 127.0.0.1                localhost.localdomain localhost ::1             localhost6.localdomain6 localhost6 192.168.10.20 node1.a.com 192.168.10.30 node2.a.com 3、同步时钟 要求两个节点上的始终必须要一致。 [[email protected] ~]# hwclock -s            #同步时钟 [[email protected] ~]# hwclock –s 4、新建分区 在节点1上新建分区 [[email protected] ~]# fdisk /dev/sda 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs    (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): n            #增加一个新分区 Command action    e   extended    p   primary partition (1-4) e                                    #增加一个扩展分区 Selected partition 4 First cylinder (1799-3916, default 1799): Using default value 1799 Last cylinder or +size or +sizeM or +sizeK (1799-3916, default 3916): Using default value 3916 Command (m for help): p        #显示分区内容 Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id System /dev/sda1   *           1          13      104391   83 Linux /dev/sda2              14        1543    12289725   83 Linux /dev/sda3            1544        1798     2048287+ 82 Linux swap / Solaris /dev/sda4            1799        3916    17012835    5 Extended Command (m for help): n First cylinder (1799-3916, default 1799): Using default value 1799 Last cylinder or +size or +sizeM or +sizeK (1799-3916, default 3916): +1g Command (m for help): p Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id System /dev/sda1   *           1          13      104391   83 Linux /dev/sda2              14        1543    12289725   83 Linux /dev/sda3            1544        1798     2048287+ 82 Linux swap / Solaris /dev/sda4            1799        3916    17012835    5 Extended /dev/sda5            1799        1921      987966   83 Linux Command (m for help): w           #保存以上操作 重新读取sda这块盘上的分区表 [[email protected] ~]# partprobe /dev/sda [[email protected] ~]# cat /proc/partitions major minor #blocks name      8     0   31457280 sda    8     1     104391 sda1    8     2   12289725 sda2    8     3    2048287 sda3    8     4          0 sda4    8     5     987966 sda5 在节点2上创建一个扩展分区和一个逻辑分区 [[email protected] ~]# fdisk /dev/sda 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs    (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): n Command action    e   extended    p   primary partition (1-4) e Selected partition 4 First cylinder (1354-2610, default 1354): Using default value 1354 Last cylinder or +size or +sizeM or +sizeK (1354-2610, default 2610): Using default value 2610 Command (m for help): n First cylinder (1354-2610, default 1354): Using default value 1354 Last cylinder or +size or +sizeM or +sizeK (1354-2610, default 2610): +1g  #两个节点的分区大小要一致 Command (m for help): p                      #显示分区 Disk /dev/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes    Device Boot      Start         End      Blocks   Id System /dev/sda1   *           1          13      104391   83 Linux /dev/sda2              14        1288    10241437+ 83 Linux /dev/sda3            1289        1353      522112+ 82 Linux swap / Solaris /dev/sda4            1354        2610    10096852+   5 Extended /dev/sda5            1354        1476      987966   83 Linux Command (m for help): w             #保存以上操作 重新加载sda这块盘上的分区 [[email protected] ~]# partprobe /dev/sda 二、安装DRBD主程序和提供内核模块的rpm包 [[email protected] ~]# ll -rw-r--r-- 1 root root 221868 10-18 10:14 drbd83-8.3.8-1.el5.centos.i386.rpm -rw-r--r-- 1 root root 125974 10-18 10:14 kmod-drbd83-8.3.8-1.el5.centos.i686.rpm 1、在node1和node2节点安装 # rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm # rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm 以下操作要求在节点node1和node2上都做。 2、修改conf配置文件 # cd /usr/share/doc/drbd83-8.3.8/ #cp drbd.conf /etc/            #复制配置文件到相关目录 #cd /etc/drbd.d/ # cp -p global_common.conf global_common.conf.bak  #最好对文件进行备份 vim global_common.conf global {         usage-count no;         # minor-count dialog-refresh disable-ip-verification } common {         protocol C;         startup {                 wfc-timeout 120;                 degr-wfc-timeout 120;          }         disk {                   on-io-error detach;                   fencing resource-only;           }         net {                 cram-hmac-alg "sha1";                 shared-secret "mydrbdlab";          }         syncer {                   rate 100M;          } 3、修改资源文件 # cd /etc/drbd.d/ # vim web.res 1 resource web { 2        on node1.a.com { 3        device /dev/drbd0; 4        disk /dev/sda5; 5        address 192.168.10.20:7789; 6        meta-disk internal; 7        } 8        on node2.a.com { 9        device /dev/drbd0; 10        disk /dev/sda5; 11        address 192.168.10.30:7789; 12        meta-disk internal; 13        } 14 } 4、node1和node2分别进行初始化 [[email protected] drbd.d]# drbdadm   create-md web Writing meta data... initializing activity log NOT initialized bitmap New drbd meta data block successfully created. [[email protected] drbd.d]# drbdadm   create-md web 5、在节点1和2上启动drbd服务 [[email protected] drbd.d]# service drbd start [[email protected] drbd.d]# service drbd start 在节点1和节点2上全是辅助设备,都为second 状态,没有同步 [[email protected] drbd.d]# cat /proc/drbd version: 8.3.8 (api:88/proto:86-94) GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16  0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent 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:b oos:987896 也可以采用drbd-overview指令,查看设备状态 6、指明节点1为主设备 [[email protected] drbd.d]# drbdadm   -- --overwrite-data-of-peer primary web 查看同步 [[email protected] drbd.d]# cat /proc/drbd version: 8.3.8 (api:88/proto:86-94) GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16  0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----     ns:132164 nr:0 dw:0 dr:140352 al:0 bm:8 lo:1 pe:10 ua:256 ap:0 ep:1 wo:b oos:856024        [=>..................] sync'ed: 14.1% (856024/987896)K delay_probe: 11        finish: 0:00:51 speed: 16,484 (16,484) K/sec 查看同步过程 [[email protected] drbd.d]#watch -n 1 'cat /proc/drbd' 7、格式化文件系统 [[email protected] drbd.d]# mkfs -t ext3 -L drbdweb /dev/drbd0 8、定义资源  [[email protected] drbd.d]# mkdir /mnt/web [[email protected] drbd.d]# mount /dev/drbd0 /mnt/web/ [[email protected] drbd.d]# df –h       #查看挂载情况 文件系统              容量  已用 可用 已用% 挂载点 /dev/sda2              12G 2.6G 8.3G 24% / /dev/sda1              99M   12M   83M 12% /boot tmpfs                 119M     0 119M   0% /dev/shm /dev/drbd0            950M   18M 885M   2% /mnt/web [[email protected] drbd.d]# cd /mnt/web/ #创建资源 [[email protected] web]# cp /etc/passwd ./ [[email protected] web]# cp /etc/inittab ./ #drbdadm create-md web Writing meta data... initializing activity log NOT initialized bitmap New drbd meta data block successfully created. 9、把node1变成辅助设备,node2变成主设备 节点1变成辅助设备 [[email protected] ~]# umount /mnt/web/ [[email protected] ~]# df -h 文件系统              容量  已用 可用 已用% 挂载点 /dev/sda2              12G 2.6G 8.3G 24% / /dev/sda1              99M   12M   83M 12% /boot tmpfs                 119M     0 119M  0% /dev/shm [[email protected] ~]# drbdadm secondary web [[email protected] ~]# drbdadm   role web Secondary/Secondary 节点2变成主设备 [[email protected] ~]# mkdir /mnt/web [[email protected] ~]# mount /dev/drbd0 /mnt/web/ [[email protected] ~]# df -h [[email protected] ~]# drbdadm   primary web [[email protected] ~]# mount /dev/drbd0 /mnt/web/ [[email protected] ~]# cd /mnt/web/ [[email protected] web]# ll 总计 24 -rw-r--r-- 1 root root 1666 10-18 11:20 inittab drwx------ 2 root root 16384 10-18 11:17 lost+found -rw-r--r-- 1 root root 1649 10-18 11:20 passwd [[email protected] web]# touch aa.txt 10、转换主辅设备 把node2变为辅助 [[email protected] ~]# umount /mnt/web/ [[email protected] ~]# drbdadm secondary web Node1变为主设备 [[email protected] ~]# drbdadm   primary web [[email protected] ~]# drbdadm   role web Primary/Secondary [[email protected] web]# mount /dev/drbd0 /mnt/web/ [[email protected] web]# cd /mnt/web/ [[email protected] web]# ll 总计 24 -rw-r--r-- 1 root root     0 10-18 11:29 aa.txt  #我们看到了在node2节点创建的aa.txt文件 -rw-r--r-- 1 root root 1666 10-18 11:20 inittab drwx------ 2 root root 16384 10-18 11:17 lost+found -rw-r--r-- 1 root root 1649 10-18 11:20 passwd 三、NFS配置 #两台服务器的nfs配置必须要一致 在节点2上的操作  1、修改相关文件 [[email protected] ~]# vim /etc/exports   /mnt/web *(rw,sync,insecure,no_root_squash,no_wdelay) 2、执行相关操作。 [[email protected] ~]#service portmap start && chkconfig portmap on [[email protected] ~]#service nfs start && chkconfig nfs on 3、修改nfs启动脚本 [[email protected] ~]# vim /etc/init.d/nfs 122         killproc nfsd –9 4、在节点1上作上述相同的操作 [[email protected] ~]# scp /etc/exports node1.a.com:/etc/ [[email protected] ~]# scp /etc/init.d/nfs node1.a.com:/etc/init.d/ 5、在节点1和节点2上启动 portmap: [[email protected] ~]# service portmap start [[email protected] ~]# chkconfig portmap on [[email protected] ~]# service portmap start [[email protected] ~]# chkconfig portmap on 四、Heartbeat配置 Heartbeat的配置要求两个节点的配置一致 在node1和node2上进行如下操作 1、挂载光盘,安装软件包 [[email protected] ~]# mkdir /mnt/cdrom [[email protected] ~]# mount /dev/cdrom /mnt/cdrom [[email protected] ~]# yum localinstall -y heartbeat-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpm –nogpgcheck 2、复制模版文件 [[email protected] ~]# cd /usr/share/doc/heartbeat-2.1.4/ [[email protected] heartbeat-2.1.4]#cp authkeys ha.cf haresources /etc/ha.d/ 3、修改相关的配置信息 [[email protected] ~]# cd /etc/ha.d/          #切换到相关目录 [[email protected] ha.d]# vim ha.cf 24 debugfile /var/log/ha-debug 29 logfile /var/log/ha-log 34 logfacility     local0 48 keepalive 2 56 deadtime 10 76 udpport 694 77 bcast eth0                   #此行可以添加在任意一行 158 auto_failback off 212 node    node1.a.com 213 node    node2.a.com 4、修改资源文件 [[email protected] ha.d]# vim /etc/ha.d/haresources     #加入下列内容 node1.a.com IPaddr::192.168.10.1/24/eth0 drbddisk::web Filesystem::/dev/drbd0::/mnt/web::ext3 killnfsd #修改node2资源文件的时候节点名称为node2.a.com 5、修改key文件 [[email protected] ha.d]# # vim authkeys      #去掉23和24行的注释 23 auth 1 24 1 crc 6、手工创建文件 [[email protected] ~]# vim /etc/ha.d/resource.d/killnfsd #加入下列内容 killall -9 nfsd ; /etc/init.d/nfs restart ; exit 0 7、修改配置文件的权限 [[email protected] ~]# chmod 600 /etc/ha.d/authkeys [[email protected] ~]# chmod 755 /etc/ha.d/resource.d/killnfsd 8、启动服务 [[email protected] ~]# service heartbeat start 五、测试 1、服务器进行测试, 1、启动heartbeat服务节点2为主设备 [[email protected] ha.d]# drbd-overview  0:web Connected Primary/Secondary UpToDate/UpToDate C r---- /mnt/web ext3 950M 18M 885M 2% 在节点2上可以看到vip地址

计算机 2

2、把节点1变为主设备

本文由乐虎游戏发布于计算机资讯,转载请注明出处:Heartbeat+DRBD+NFS案例详解

关键词:

乐虎国际登录:Win2008 R2 mysql 5.5 zip格式mysql 安装与配置

Win2008 R2 mysql 5.5 zip格式mysql 安装与配置 Win2008 R2 zip格式mysql 安装与配置 一、百度mysql5.6 ZIP 64位免安装版 下载好后 解...

详细>>

SQL计算timestamp的差值的方法

SQL计算timestamp的差值的方法 SQL计算timestamp的差值的方法 mg电子游戏网址 , mg娱乐电子游戏 , 概述 有时候我们需要按...

详细>>

Ubuntu16.04+Cuda8.0+Theano深度学习环境搭建一

ubuntu 16.04安装nVidia显卡驱动和cuda/cudnn踩坑过程,cudacudnn 推荐新版安装教程 安装深度学习框架需要使用cuda/cudnn(GPU)来...

详细>>

虚拟化架构下虚拟交换机和分布式虚拟交换机解析

在VMwarevSphere虚拟化架构下服务器可以虚拟出交换机来供虚拟机使用,虚拟交换机可分为两种,vSwitch虚拟交换机和vN...

详细>>