heartbeat+drbd+nfs安裝配置

wang_0720發表於2013-11-05
所需軟體
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部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775759/,如需轉載,請註明出處,否則將追究法律責任。

相關文章