集羣和存儲管理之DRBD+Heartbeat+NFS的實現

(下面是DRBD+NFS的簡介,因爲heartbeat筆者已在上篇博客介紹過,就不再贅述)

DRBD基礎

Distributed Replicated Block Device(DRBD)是一個用軟件實現的、無共享的、服務器之間鏡像塊設備內容的存儲複製解決方案。

數據鏡像:實時、透明、同步(所有服務器都成功後返回)、異步(本地服務器成功後返回)

DRBD的核心功能通過Linux的內核實現,最接近系統的IO棧,但它不能神奇地添加上層的功能比如檢測到EXT3文件系統的崩潰。

DRBD的位置處於文件系統以下,比文件系統更加靠近操作系統內核及IO棧。

工具:

drbdadm:高級管理工具,管理/etc/drbd.conf,向drbdsetup和drbdmeta發送指令,

drbdsetup:配置裝載進kernel的DRBD模塊,平時很少直接用

drbdmeta:管理META數據結構,平時很少直接用。

在DRBD中,資源是特指某複製的存儲設備的所有方面。包括資源名稱、DRBD設備(/dev/drbdm,這裏m是設備最小號,最大號可到147)、磁盤配置(使本地數據可以爲DRBD所用)、網絡配置(與對方通信)

每個資源有個角色,是Primary或Secondary,下面簡稱“主”和“備”

主角色的DRBD設備可以不受限制的讀和寫,比如創建和映射文件系統、對於塊設備的raw或直接IO訪問。

備角色的DRBD設備接受來自對方的所有修改,但是不能被應用程序讀寫,甚至只讀也不行。

角色可以改變。

DRBD功能

單主模式:典型的高可靠性集羣方案。

復主模式:需要採用共享cluster文件系統,如GFS和OCFS2。用於需要從2個節點併發訪問數據的場合,需要特別配置。

複製模式:3種模式:

協議A:異步複製協議。本地寫成功後立即返回,數據放在發送buffer中,可能丟失。

協議B:內存同步(半同步)複製協議。本地寫成功並將數據發送到對方後立即返回,如果雙機掉電,數據可能丟失。

協議C:同步複製協議。本地和對方寫成功確認後返回。如果雙機掉電或磁盤同時損壞,則數據可能丟失。

一般用協議C。選擇協議將影響流量,從而影響網絡時延。

有效的同步:按線性而不是當初寫的順序同步塊。同步損壞時間內的不一致數據。

在線的設備檢驗:一端順序計算底層存儲,得到一個數字,傳給另一端,另一端也計算,如果不一致,則稍後進行同步。建議一週或一月一次。

複製過程的一致性檢驗:加密後,對方若不一致則要求重傳。防止網卡、緩衝等問題導致位丟失、覆蓋等錯誤。

Split brain:當網絡出現暫時性故障,導致兩端都自己提升爲Primary。兩端再次連通時,可以選擇email通知,建議手工處理這種情況。

當數據寫在緩衝區裏,沒有真正寫到磁盤上時,系統崩潰會導致數據丟失。而disk flush是指將數據真正寫到磁盤上後才返回。

有些帶電池的硬盤控制器,如帶電池的帶點出Dell PERC Raid卡,不但自帶緩存而且自帶電池,會在系統意外斷電或者崩潰後將最後的數據寫入磁盤,對這類控制器,可以使用disk flush,從而在保證性能的前提下提高了數據的安全性。

磁盤錯誤處理策略:

傳遞給上層:可能造成文件系統remounting成只讀,不推薦。

對上層屏蔽:用另一端的相應塊進行讀寫,應用不中斷。可以在任何方便的時候再切換。

不一致的(inconsistent)數據:不能以任何方式訪問和使用的數據。如正在同步時的目標節點數據,這些數據不能識別,不能mount,甚至不能通過磁盤的自動檢測。

過期的(outdated)數據:在備機上的數據,與主機一致,但不需要同步。如主備機網絡中斷後,備機上的數據就是過期的。

DRBD有接口允許應用程序在網絡中斷時將備機數據標識爲過期的。DRBD拒絕將這個節點提升爲主角色。這些管理接口在Heartbeat框架上得到完整實現。

一旦過期資源的複製鏈接恢復,他的過期標誌自動清除,接着進行後臺同步。

工作原理

在高可用(HA)中使用DRBD功能,可以代替使用一個共享盤陣.因爲數據同時存在於本地主機和遠程主機上,

切換時,遠程主機只要使用它上面的那份備份數據,就可以繼續進行服務了.

DRBD的工作原理如下圖:

+--------+ | 文件系統 | +--------+

|

V

+--------+| 塊設備層 | | (/dev/drbd1) +--------+

| |

V V

| 本地硬盤 | | (/dev/hdb1) | | 遠程主機硬盤 | | (/dev/hdb1) |

 

NFS簡介

NFS是Network File System的簡寫,即網絡文件系統.

網絡文件系統是FreeBSD支持的文件系統中的一種,也被稱爲NFS. NFS允許一個系統在網絡上與他人共享目錄和文件。通過使用NFS,用戶和程序可以像訪問本地文件一樣訪問遠端系統上的文件。

NFS好處

飛客數據恢復中心提供

以下是NFS最顯而易見的好處:

1.本地工作站使用更少的磁盤空間,因爲通常的數據可以存放在一臺機器上而且可以通過網絡訪問到。

2.用戶不必在每個網絡上機器裏頭都有一個home目錄。Home目錄 可以被放在NFS服務器上並且在網絡上處處可用。

3.諸如軟驅,CDROM,和 Zip(是指一種高儲存密度的磁盤驅動器與磁盤)之類的存儲設備可以在網絡上面被別的機器使用。這可以減少整個網絡上的可移動介質設備的數量。

NFS組成
NFS至少有兩個主要部分:一臺服務器和一臺(或者更多)客戶機。客戶機遠程訪問存放在服務器上的數據。爲了正常工作,一些進程需要被配置並運行。
實際應用
NFS 有很多實際應用。下面是比較常見的一些:

1.多個機器共享一臺CDROM或者其他設備。這對於在多臺機器中安裝軟件來說更加便宜跟方便。

2.在大型網絡中,配置一臺中心 NFS 服務器用來放置所有用戶的home目錄可能會帶來便利。這些目錄能被輸出到網絡以便用戶不管在哪臺工作站上登錄,總能得到相同的home目錄。

3.幾臺機器可以有通用的/usr/ports/distfiles 目錄。這樣的話,當您需要在幾臺機器上安裝port時,您可以無需在每臺設備上下載而快速訪問源碼。

NFS配置方式
NFS的配置過程相對簡單。這個過程只需要對/etc/rc.conf文件作一些簡單修改。

1 在NFS服務器這端,確認/etc/rc.conf 文件裏頭以下開關都配上了:

rpcbind_enable="YES"

nfs_server_enable="YES"

mountd_flags="-r"

只要NFS服務被置爲enable,mountd 就能自動運行。

2 在客戶端一側,確認下面這個開關出現在 /etc/rc.conf裏頭:

nfs_client_enable="YES"

/etc/exports文件指定了哪個文件系統 NFS應該輸出(有時被稱爲“共享”)。 /etc/exports裏面每行指定一個輸出的文件系統和哪些機器可以訪問該文件系統。在指定機器訪問權限的同時,訪問選項開關也可以被指定。

 

 

實驗拓撲圖:

image

 

一:準備工作》

1.1配置node1的地址:

image

 

image

1.2構建一個新的磁盤空間有利於實現DRBD技術

[root@nodel drbd.d]# fdisk -l

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+  83  Linux
[root@nodel drbd.d]# fdisk /dev/sda

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
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
You must delete some partition and add an extended partition first

Command (m for help): d
Partition number (1-4): 4

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): +1G

Command (m for help): n
First cylinder (1354-1476, default 1354):
Using default value 1354
Last cylinder or +size or +sizeM or +sizeK (1354-1476, default 1476): +1G

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@nodel drbd.d]#
[root@nodel drbd.d]# fdisk -l

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        1476      987997+   5  Extended
/dev/sda5            1354        1476      987966   83  Linux

[root@nodel drbd.d]# partprobe /dev/sda
[root@nodel drbd.d]#  cat /proc/partitions
major minor  #blocks  name

   8     0   20971520 sda
   8     1     104391 sda1
   8     2   10241437 sda2
   8     3     522112 sda3
   8     4          0 sda4
   8     5     987966 sda5

 

 

1.4配置node2的地址:

image

[root@node2 ~]# hostname
node2.a.com

image

1.5構建一個新的磁盤空間有利於實現DRBD技術

[root@node2 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 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

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 1
Partition 1 is already defined.  Delete it before re-adding it.

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (124-2610, default 124):
Using default value 124
Last cylinder or +size or +sizeM or +sizeK (124-2610, default 2610): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (247-2610, default 247):
Using default value 247
Last cylinder or +size or +sizeM or +sizeK (247-2610, default 2610): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (370-2610, default 370):
Using default value 370
Last cylinder or +size or +sizeM or +sizeK (370-2610, default 2610): +1000M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@node2 ~]# fdisk -l

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        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 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/sdb1               1         123      987966    5  Extended
/dev/sdb2             124         246      987997+  83  Linux
/dev/sdb3             247         369      987997+  83  Linux
/dev/sdb4             370         492      987997+  83  Linux
[root@node2 ~]# partprobe /dev/sdb
[root@node2 ~]# cat  /proc/partitions
major minor  #blocks  name

   8     0   20971520 sda
   8     1     104391 sda1
   8     2   20860402 sda2
   8    16   20971520 sdb
   8    17          0 sdb1
   8    18     987997 sdb2
   8    19     987997 sdb3
   8    20     987997 sdb4
253     0   19791872 dm-0
253     1    1048576 dm-1
[root@node2 ~]#


1.6在node1和node2上配置ssh密鑰信息,有利於以後在一個節點對另一節點直接操作:

在node1上配置ssh密鑰信息

[root@node1 ~]# ssh-keygen -t rsa

[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub  root@node2.a.com

在node2上配置ssh密鑰信息

[root@node2 ~]# ssh-keygen -t rsa

[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub  root@node2.a.com

二、DRBD安裝配置步驟

在node1和node2做以下操作:

我下載的軟件包是:(放在/root/下了)

drbd83-8.3.8-1.el5.centos.i386.rpm

kmod-drbd83-8.3.8-1.el5.centos.i686.rpm

2.1、安裝DRBD 套件

[root@node1 ~]# rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm

[root@node1 ~]# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm

[root@node2 ~]# rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm

[root@node2 ~]# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm

2.2、加載DRBD 模塊

[root@node1 ~]# modprobe drbd

[root@node1 ~]# lsmod | grep drbd

drbd 228528 0

[root@node1 ~]#

[root@node2 ~]# modprobe drbd

[root@node2 ~]# lsmod | grep drbd

drbd 228528 0

[root@node2 ~]#

2.3、修改配置文件

drbd.conf配置文件DRBD運行時,會讀取一個配置文件/etc/drbd.conf.這個文件裏描述了DRBD設備與硬盤分區的映射關係

2.3.1 在node1上作以下配置

image

[root@node1 ~]# cd /etc/drbd.d/

[root@node1 drbd.d]# ll

total 4

-rwxr-xr-x 1 root root 1418 Jun 4 2010 global_common.conf

[root@node1 drbd.d]# cp global_common.conf global_common.conf.bak

修改全局配置文件:vim global_common.conf

image

修改資源配置文件:vim /etc/drbd.d/nfs.res

image

2.3.2 複製配置到node2上:
[root@nodel drbd.d]# scp /etc/drbd.conf node2.a.com:/etc/
drbd.conf                                                                                  100%  133     0.1KB/s   00:00   
[root@nodel drbd.d]# scp /etc/drbd.d/* node2.a.com:/etc/drbd.d/
global_common.conf                                                                         100% 1148     1.1KB/s   00:00   
global_common.conf.bak                                                                     100% 1418     1.4KB/s   00:00   
nfs.res                                                                                    100%  352     0.3KB/s   00:00   

2.4、 檢測配置文件

// 檢測配置文件

[root@nodel drbd.d]# drbdadm   adjust nfs
[root@nodel drbd.d]# drbdadm   create-md nfs
Device '0' is configured!
Command 'drbdmeta 0 v08 /dev/sda5 internal create-md' terminated with exit code 20
drbdadm create-md nfs: exited with code 20
[root@nodel drbd.d]#

2.5、創建nfs 的資源

2.5.1 在node1上創建nfs 的資源

[root@node1 drbd.d]# drbdadm create-md nfs

Device '0' is configured!
Command 'drbdmeta 0 v08 /dev/sda5 internal create-md' terminated with exit code 20
drbdadm create-md nfs: exited with code 20

2.5.2 在node2上創建nfs 的資源

[root@nodel drbd.d]#  ssh node2.a.com 'drbdadm create-md nfs'
NOT initialized bitmap
Writing meta data...
initializing activity log
New drbd meta data block successfully created.
[root@nodel drbd.d]#

2.6 啓動DRBD服務

[root@node2 ~]# service drbd start
Starting DRBD resources: drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node2 ~]# ssh node2.a.com 'service drbd start'
The authenticity of host 'node2.a.com (192.168.145.99)' can't be established.
RSA key fingerprint is b5:21:65:8a:4b:b1:5a:71:92:81:cc:89:06:56:9a:77.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2.a.com,192.168.145.99' (RSA) to the list of known hosts.
[email protected]'s password:
Starting DRBD resources: drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node2 ~]#

2.7 啓動DRBD服務,查看DRBD狀態

[root@nodel drbd.d]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
m:res  cs            ro                 ds                     p  mounted  fstype
0:nfs  WFConnection  Secondary/Unknown  Inconsistent/DUnknown  C
[root@nodel drbd.d]#  ssh node2.a.com 'service drbd status'
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
m:res  cs            ro  ds  p  mounted  fstype
0:nfs  Unconfigured
[root@nodel drbd.d]#  drbd-overview
  0:nfs  WFConnection Secondary/Unknown Inconsistent/DUnknown C r----
[root@nodel drbd.d]# ssh node2.a.com 'drbd-overview'
  0:nfs  Unconfigured . . . .
[root@nodel drbd.d]#  chkconfig drbd on
[root@nodel drbd.d]# ssh node2.a.com 'chkconfig drbd on'
[root@nodel drbd.d]#  ssh node2.a.com 'chkconfig --list drbd'
drbd               0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉
[root@nodel drbd.d]#

2.8 在node1主節點上進行以下配置,並查看掛載信息。

[root@node1 drbd.d]# mkdir /mnt/nfs

[root@node1 drbd.d]# ssh node2.a.com 'mkdir /mnt/nfs'

[root@node1 drbd.d]# drbdsetup /dev/drbd0 primary -o

[root@node1 drbd.d]# mkfs.ext3 /dev/drbd0

[root@node1 drbd.d]# mount /dev/drbd0 /mnt/nfs/

[root@nodel drbd.d]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
m:res  cs            ro               ds                 p  mounted   fstype
0:nfs  WFConnection  Primary/Unknown  UpToDate/Outdated  C  /mnt/nfs  ext3
[root@nodel drbd.d]#  drbd-overview
  0:nfs  WFConnection Primary/Unknown UpToDate/Outdated C r---- /mnt/nfs ext3 950M 18M 885M 2%
[root@nodel drbd.d]#  ssh node2.a.com 'service drbd status'
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by [email protected], 2010-06-04 08:04:16
m:res  cs            ro  ds  p  mounted  fstype
0:nfs  Unconfigured
[root@nodel drbd.d]# ssh node2.a.com 'drbd-overview'
  0:nfs  Unconfigured . . . .
[root@nodel drbd.d]# ll /mnt/nfs
總計 16
drwx------ 2 root root 16384 10-17 15:02 lost+found
[root@nodel drbd.d]#

至此DRBD配置成功!!!

三、NFS配置

兩臺服務器都修改nfs 配置文件,都修改nfs 啓動腳本,如下:

vim /etc/exports

image  
[root@nodel ~]# chkconfig portmap on
[root@nodel ~]# chkconfig  --list portmap
portmap            0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉
[root@nodel ~]# service portmap start
啓動 portmap:                                             [確定]
[root@nodel ~]# chkconfig nfs on
[root@nodel ~]# chkconfig  --list nfs
nfs                0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉
[root@nodel ~]# service nfs start
啓動 NFS 服務:                                            [確定]
關掉 NFS 配額:                                            [確定]
啓動 NFS 守護進程:                                        [確定]
啓動 NFS mountd:                                          [確定]
[root@nodel ~]#

vim /etc/init.d/nfs

image

 

node2上:

[root@node2 ~]# vim /etc/exports

image
[root@node2 ~]# chkconfig portmap on
[root@node2 ~]# chkconfig  --list portmap
portmap            0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉
[root@node2 ~]# service protmap start
protmap: 未被識別的服務
[root@node2 ~]# service portmap start
啓動 portmap:                                             [確定]
[root@node2 ~]# chkconfig nfs on
[root@node2 ~]# chkconfig  --list nfs
nfs                0:關閉    1:關閉    2:啓用    3:啓用    4:啓用    5:啓用    6:關閉
[root@node2 ~]# service nfs start
啓動 NFS 服務:                                            [確定]
關掉 NFS 配額:                                            [確定]
啓動 NFS 守護進程:                                        [確定]
啓動 NFS mountd:                                          [確定]
[root@node2 ~]# vim /etc/init.d/nfs

image
[root@node2 ~]#

四、Heartbeat配置

在server1和server2做以下操作:

1、安裝Heartbeat套件

[root@node1 ~]# 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

[root@node2 ~]# 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、拷貝配置文檔

[root@node1 ~]# cd /usr/share/doc/heartbeat-2.1.4/

[root@node1 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/

[root@node1 heartbeat-2.1.4]# cd /etc/ha.d/

vim /etc/ha.d/ha.cf

image

image

image

image

image

image

vim /etc/ha.d/haresources

image

vim /etc/ha.d/authkeys

image

[root@node2 heartbeat-2.1.4]# cd /etc/ha.d/
[root@node2 ha.d]# echo "killall -9 nfsd; /etc/init.d/nfs restart; exit 0" >>resource.d/killnfsd
[root@node2 ha.d]# chmod 600 /etc/ha.d/authkeys
[root@node2 ha.d]# chmod 755 /etc/ha.d/resource.d/killnfsd
[root@node2 ha.d]# scp ha.cf authkeys  haresources
haresources: Not a directory
[root@node2 ha.d]# hostname server1.a.com
[root@node2 ha.d]# vim /hosts
[root@node2 ha.d]# vim /etc/hosts
[root@node2 ha.d]# vim /etc/sysconfig/net
netconsole       network          networking/      network-scripts/
[root@node2 ha.d]# vim /etc/sysconfig/network
[root@node2 ha.d]# scp ha.cf authkeys  haresources server2.a.com:/etc/ha.d/
The authenticity of host 'server2.a.com (192.168.145.102)' can't be established.
RSA key fingerprint is 0c:84:f6:dd:8b:bd:9c:5b:b0:4c:cc:5c:6a:a6:32:f5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server2.a.com,192.168.145.102' (RSA) to the list of known hosts.
[email protected]'s password:
ha.cf                                                                        100%   10KB  10.3KB/s   00:00   
authkeys                                                                     100%  643     0.6KB/s   00:00   
haresources                                                                  100% 6014     5.9KB/s   00:00   
[root@node2 ha.d]# vim /hosts

[root@server1 ~]# cd /etc/ha.d/
[root@server1 ha.d]# scp resource.d/killnfsd server2.a.com:/etc/ha.d/resource.d/killnfsd
[email protected]'s password:
killnfsd                                                                     100%   49     0.1KB/s   00:00   
[root@server1 ha.d]#

server2.a.com上:

vim ha.cf

image

配置server1的地址:

image

[root@server1 ha.d]# service heartbeat restart
Stopping High-Availability services:
                                                           [確定]
Waiting to allow resource takeover to complete:
                                                           [確定]
Starting High-Availability services:
2012/10/10_03:39:13 INFO:  Resource is stopped
                                                           [確定]

[root@server1 ha.d]# ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:13:81:77 
          inet addr:192.168.145.103  Bcast:192.168.145.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:193 Base address:0x2000

 

五、測試

1、在測試機上將192.168.145.103:/mnt/nfs掛到本地/data下

[root@client ~]# mkdir /data

[root@client ~]# mount 192.168.145.103:/mnt/nfs/ /data/

[root@client ~]# cd /data/

[root@client data]# ll

total 20

-rw-r--r-- 1 root root 4 Feb 8 17:41 f1

drwx------ 2 root root 16384 Feb 8 14:57 lost+found

[root@client data]# touch f-client-1

[root@client data]# ll

total 20

-rw-r--r-- 1 root root 0 Feb 8 19:50 f-client-1

-rw-r--r-- 1 root root 4 Feb 8 17:41 f1

drwx------ 2 root root 16384 Feb 8 14:57 lost+found

[root@client data]#cd

[root@client ~]#

2、在測試機上創建測試shell,每秒一次

clip_image001

3、將主節點node1 的heartbeat服務停止,則備節點node2 接管服務

[root@node1 ha.d]# service heartbeat stop

Stopping High-Availability services:

[ OK ]

[root@node1 ha.d]# drbd-overview

0:nfs Connected Secondary/Primary UpToDate/UpToDate C r----

[root@node1 ha.d]# ifconfig eth0:0

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Interrupt:67 Base address:0x2000

[root@node1 ha.d]#

[root@node2 ha.d]# drbd-overview

0:nfs Connected Primary/Secondary UpToDate/UpToDate C r---- /mnt/nfs ext3 950M 18M 885M 2%

[root@node2 ha.d]# ifconfig eth0:0

eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D1:D4:32

inet addr:192.168.145.103 Bcast:192.168.145.254 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

Interrupt:67 Base address:0x2000

[root@node2 ha.d]#

4、在客戶端上運行nfs.sh測試文件,一直顯示的信息如下:

[root@client ~]# ./nfs.sh

---> trying touch x : Wed Feb 8 20:00:58 CST 2012

<----- done touch x : Wed Feb 8 20:00:58 CST 2012

---> trying touch x : Wed Feb 8 20:00:59 CST 2012

<----- done touch x : Wed Feb 8 20:00:59 CST 2012

---> trying touch x : Wed Feb 8 20:01:00 CST 2012

<----- done touch x : Wed Feb 8 20:01:00 CST 2012

---> trying touch x : Wed Feb 8 20:01:01 CST 2012

<----- done touch x : Wed Feb 8 20:01:01 CST 2012

---> trying touch x : Wed Feb 8 20:01:02 CST 2012

<----- done touch x : Wed Feb 8 20:01:02 CST 2012

---> trying touch x : Wed Feb 8 20:01:03 CST 2012

<----- done touch x : Wed Feb 8 20:01:03 CST 2012

---> trying touch x : Wed Feb 8 20:01:04 CST 2012

<----- done touch x : Wed Feb 8 20:01:04 CST 2012

---> trying touch x : Wed Feb 8 20:01:05 CST 2012

<----- done touch x : Wed Feb 8 20:01:05 CST 2012

5、查看客戶端的掛載信息如下,磁盤可正常使用:

[root@client ~]# mount

/dev/sda2 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda1 on /boot type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

192.168.101.210:/mnt/nfs on /data type nfs (rw,addr=192.168.101.210)

[root@client ~]#

[root@client ~]# ll /data/

total 20

-rw-r--r-- 1 root root 0 Feb 8 19:50 f-client-1

-rw-r--r-- 1 root root 4 Feb 8 17:41 f1

drwx------ 2 root root 16384 Feb 8 14:57 lost+found

[root@client ~]#

至此,node2 接管服務成功,實驗已實現所需的功能;也可手動在nfs掛載目錄裏建立文件,來回切換node1和node2的drbd服務來進行測試。

5、恢復node1爲主要節點

[root@node1 ha.d]# service heartbeat start

Starting High-Availability services:

2012/02/08_20:04:49 INFO: Resource is stopped

[ OK ]

[root@node1 ha.d]# drbd-overview

0:nfs Connected Primary/Secondary UpToDate/UpToDate C r---- /mnt/nfs ext3 950M 18M 885M 2%

[root@node1 ha.d]#

至此DRBD+Heartbeat+NFS已經實現成功!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章