所需软件
libnet-1.1.2.1.tar.gz
MailTools-2.06.tar.gz
heartbeat-2.0.7.tar.gz
drbd-8.3.1.tar.gz
配置hosts文件
将hosts文件按下文提示配置
[root@masterdrbd ~]# cat /etc/hosts
192.168.151.42 masterdrbd
192.168.151.43
slavedrbd
创建磁盘分区
fdisk /dev/sdb
创建一个新的分区,设为主分区,分区号为1,并将信息写入分区表
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
Partition 1 is already defined. Delete it before
re-adding it.
w
kernel重新读取分区表,在不重新启动机器的情况下让系统识别分区
partprobe /dev/sdb1
安装软件drbd
tar zxf drbd-8.3.1.tar.gz
cd drbd-8.3.1
make && make install
加载drbd模块
modprobe drbd
测试模块是否加载成功
lsmod|grep drbd
出现下面提示说明drbd模块加载成功
[root@masterdrbd ~]# lsmod |grep drbd
drbd
221720 3
配置drbd,按下文所示配置drbd.conf配置文件
[root@masterdrbd ~]# cat /etc/drbd.conf
global {
usage-count
yes;
}
common
{
syncer {
rate 100M; }
}
resource nfs
{
protocol
C;
startup
{
wfc-timeout
0;
degr-wfc-timeout 120;
}
disk {
on-io-error
detach;
}
net {
timeout
60;
connect-int
10;
max-buffers
2048;
max-epoch-size 2048;
}
syncer
{
rate
100M;
}
on
masterdrbd {
device
/dev/drbd0;
disk /dev/sdb1;
address 192.168.151.42:7788;
meta-disk
internal;
}
on
slavedrbd {
device
/dev/drbd0;
disk
/dev/sdb1;
address
192.168.151.43:7788;
meta-disk
internal;
}
}
将该文件分别拷贝到两台主机上的/etc下面,两台主机上一样
创建供DRBD记录信息的数据块
# drbdadm create-md nfs(resource名)可能会出现以下错误提示
[root@slavedrbd ~]# drbdadm create-md nfs
md_offset 299992375296
al_offset 299992342528
bm_offset 299983183872
Found ext3 filesystem which uses 292961308 kB
current configuration leaves usable 292952328 kB
Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
* use external meta data
(recommended)
* shrink that filesystem
first
* zero out the device (destroy
the filesystem)
Operation refused.
Command 'drbdmeta 0 v08 /dev/sdb1 internal create-md' terminated
with exit code 40
drbdadm create-md nfs: exited with code 40
删除磁盘分区格式
# dd if=/dev/zero of=/dev/sdb1 bs=1M
count=1
启动drbd服务
# service drbd start
Starting DRBD resources: [ ].
查看drbd状态
service drbd status
drbd driver loaded OK; device status:
version: 8.3.1 (api:88/proto:86-89)
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by
root@localhost.localdomain, 2013-03-18 16:36:27
m:res
cs
ro
ds
p mounted fstype
0:nfs Connected
Secondary/Primary
UpToDate/UpToDate C
初始化一个为主机(在masterdrbd上执行)
drbdsetup /dev/drbd0 primary -o
等待同步完成
验证drbd
格式化块设备(只需要格式化主机上的drbd0)
# mkfs.ext3 /dev/drbd0
挂载
# mount /dev/drbd0 /drbd
安装配置heartbeat
分别在两台主机上安装配置heartbeat,在此不详述。
安装配置nfs
分别在两台主机上安装配置nfs并将/drbd目录共享出去,供其他主机挂载。
nfs服务监控
[root@masterdrbd ~]# cat /etc/init.d/monitornfsd
#!/bin/bash
# write by Andy Wang
#
while true
do
ps -ef |grep
nfsd|grep -v grep|grep -v monitornfsd
>/tmp/tmpfile
[ ! -s
/tmp/tmpfile ] &&
/etc/init.d/heartbeat stop >/dev/null
2>&1
sleep
5
done
监控脚本启动,关闭
[root@masterdrbd ~]# cat /etc/init.d/chknfsd
#!/bin/bash
# write by Andy Wang
#
SPATH=/etc/init.d
PID=`ps -ef|grep monitornfsd|grep -v grep|awk '{print $2}'`
HOSTNAM=`uname -n`
if [ -f /etc/init.d/functions ];then
.
/etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ];then
.
/etc/rc.d/init.d/functions
else
exit 0
fi
start ()
{
if [ -n "$PID" ];then
echo
"monitornfs is running..."
else
cd
$SPATH
sh
monitornfsd &
fi
}
stop ()
{
if [ -z "$PID" ];then
echo
"monitornfsd is stopped"
else
kill -9 $PID
>/dev/null 2>&1
fi
}
status ()
{
if [ -n "$PID" ];then
echo
"monitornfsd is ok pid is "$PID" running on $HOSTNAME"
else
echo
"monitornfsd is stopped on $HOSTNAME"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo
"Usage:$0{start|stop|status}"
exit 1
esac
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27181165/viewspace-775759/
,如需转载,请注明出处,否则将追究法律责任。