一、概述
1、架构图

2、软件简介
Heartbeat(Linux-HA)的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未到对方发送的报文,那么就认为对方失效,这时需启动资源接管模块来接管运 行在对方主机上的资源或者服务。
DRBD:drbd是一个软件来实现数据实时、同步、异步的数据镜像块存储复制解决方案,主要功能是通过Linux内核实现。DRBD类似网络RAID-1功能写入本地的文件会通过网络以相同方式写在另一文件系统。
3、资源分配
系统:CentOS6.5_x64
主机名
|
角色
|
IP地址
|
masternfs
|
主NFS
|
eth0:192.168.0.202/24
|
backupnfs
|
备NFS
|
eth0:192.168.0.203/24
|
|
VIP
|
192.168.0.204/24
|
4、配置两台hosts记录
[root@masternfs ~]# vi /etc/hosts
192.168.0.202 masternfs
192.168.0.203 backupnfs
二、安装配置DRBD(两台服务器配置基本一样)
安装epel源:
rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
下载drbd软件:http://oss.linbit.com/drbd/
1、安装依赖包
2、安装DRBD并加载到内核
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
drbd 333755 0
libcrc32c 1246 1 drbd
|
3、配置DRBD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
[root@masternfs ~]
[root@masternfs ~]
global {
usage-count yes ;
}
common {
protocol C;
disk {
on-io-error detach;
}
syncer {
rate 100M;
}
}
resource web {
on masternfs {
device /dev/drbd0 ;
disk /dev/sdb1 ;
address 192.168.0.202:7899;
meta-disk internal;
}
on backupnfs {
device /dev/drbd0 ;
disk /dev/sdb1 ;
address 192.168.0.203:7899;
meta-disk internal;
}
}
|
4、创建供DRBD记录信息数据块
1
2
3
4
5
6
7
8
|
[root@masternfs ~]
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data blocksuccessfully created.
success
[root@masternfs ~]
[root@masternfs ~]
|

5、默认没有分主备节点的,需要设置
1
2
3
4
5
|
[root@masternfs ~]
version: 8.4.4(api:1 /proto :86-101)
GIT- hash :599f286440bd633d15d5ff985204aff4bccffadd build by phil@Build64R6, 2013-10-1415:33:06
0: cs:Connected ro:Secondary /Secondaryds :UpToDate /UpToDate C r-----
ns:64 nr:112 dw:176 dr:6088 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1wo:f oos:0
|
1
2
|
[root@masternfs ~]
[root@db-backup ~]
|
#再查看状态已经是主从
1
2
|
[root@masternfs ~]
0:mysql /0 Connected Primary /Secondary UpToDate /UpToDate C r-----
|
说明:
cs:两台数据连接状态
ro:两台主机的状态
ds:磁盘状态是“UpToDate/UpToDate”,同步状态。
6、格式化并挂载分区
1
2
3
|
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
|
三、安装配置NFS
1
2
3
4
5
6
7
|
[root@masternfs ~]
[root@masternfs ~]
/web 192.168.0.0 /24 (rw,no_root_squash)
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
|
四、安装配置Heartbeat
1
2
3
4
|
[root@masternfs ~]
[root@masternfs ~]
[root@masternfsheartbeat-3.0.4]
[root@masternfsheartbeat-3.0.4]
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@masternfs ha.d]
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth0
auto_failback off
node masternfs
node backupnfs
ping 192.168.0.1
|
1
2
3
|
[root@masternfs ~]
auth 2
2 sha1 HI!
|
参数说明:
masternfsIPaddr::192.168.0.204/24/eth0 #主机名,后跟虚拟IP地址、接口
drbddisk::web #管理drbd资源
Filesystem::/dev/drbd0::/web::ext4 killnfsd #文件系统,目录及格式,后跟nfs资源脚本
#killnfsd脚本
1
2
|
[root@masternfs ~]
[root@masternfs ~]
|
1
2
3
|
[root@masternfs ~]
[root@masternfs ~]
[root@masternfs ~]
|
五、测试高可用性
1、停掉masternfs服务器heartbeat服务,是否虚拟IP正常切换,可通过ip addr命令查看。
2、通过一台测试机, mount -t nfs 192.168.0.204:/web/media,当故障切换时,nfs无间断提供服务,提供完美冗余。
3、通过ha-log日志可以看出主释放资源,备接管资源。

