DRBD以其開源,簡單,高效,性能不俗為廣大運維者們所青睐。主要功能是在不同節點上兩個相同大小的設備塊級別之間的數據同步鏡像。drbd是由內核模塊和相關腳本而構成,用以構建高可用性的集群。本文主要描述其安裝方式,供大家參考。
有關DRBD的特性,功能及其相關基礎知識,大家可以參考: DRBD原理及特性概述
OS版本:CentOS release 6.5 (Final)
orasrv1: 192.168.21.10
orasrv2: 192.168.21.13
DRBD版本Version: 8.3.15 (api:88)
二、yum方式安裝drbd(兩節點)
1、以下通過yum方式安裝
配置epel源,可以從這裡下載,或者直接用wget方式獲取
http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
# yum -y install drbd83 kmod-drbd83
# modprobe drbd
# lsmod |grep drbd
drbd 345363 0
2、配置部分,請參考第三點編譯方式安裝drbd之第4小點後續部分
###注,通過yum方式安裝時,drbd配置文件目錄有所不同
###drbd.conf文件放置到/etc目錄下,其余的2個配置文件存放到/etc/drbd.d目錄下
三、編譯方式安裝drbd
1、安裝用戶空間工具(兩節點)
# yum -y install kernel-devel kernel-headers flex gcc
# pwd
usr/local/src ###drbd壓縮文件存放位置
# tar -xvf drbd-8.3.15.tar.gz
# cd drbd-8.3.15
# ./configure --prefix=/usr/local/drbd --with-km
# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64/
# make install
# ls /usr/local/drbd/ ##查看安裝後的文件
etc lib sbin share var
# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/init.d/drbd
# chkconfig --add drbd
# chkconfig drbd on
2、安裝drbd模塊(兩節點)
# cd /usr/local/src/drbd-8.3.15/drbd
# make clean
# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64/
# cp drbd.ko /lib/modules/`uname -r`/kernel/lib/
# depmod
# modprobe drbd ###加載drbd模塊到Linux內核
注:/usr/src/kernels/2.6.18-274.18.1.el5-i686/這個內核源碼樹路徑需要根據自己的系統修改。
3、驗證drbd內核加載(兩節點)
# lsmod |grep drbd
drbd 345363 0
4、配置系統磁盤(兩節點)
### Author : Leshami
### Blog : http://blog.csdn.net/leshami
###本示例種為當前2節點單獨分配了/dev/sdb磁盤,以下操作在2節點完成
# fdisk /dev/sdb ###依次輸入n,p,1,回車(enter),回車(enter),w
# partprobe ###如果依舊無法看到分區,請reboot以及查找原因
# fdisk -l /dev/sdb
5、配置drbd.conf及global_common.conf(兩節點)
# mv /usr/local/drbd/etc/drbd.conf /usr/local/drbd/etc/drbd.conf.bk
# cp /usr/local/src/drbd-8.3.15/scripts/drbd.conf /usr/local/drbd/etc/drbd.conf
# more /usr/local/drbd/etc/drbd.conf ###查看drbd.conf應包含下列include內容
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
# mv /usr/local/drbd/etc/drbd.d/global_common.conf /usr/local/drbd/etc/drbd.d/global_common.conf.bk
# vi /usr/local/drbd/etc/drbd.d/global_common.conf ###global_common.conf可以參考drbd.conf.example
global {
usage-count yes;
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C;
handlers {
}
startup {
wfc-timeout 0; degr-wfc-timeout 120;
}
disk {
on-io-error detach;
}
net {
# sndbuf-size rcvbuf-size timeout connect-int ping-int ping-timeout max-buffers
# max-epoch-size ko-count allow-two-primaries cram-hmac-alg shared-secret
# after-sb-0pri after-sb-1pri after-sb-2pri data-integrity-alg no-tcp-cork
cram-hmac-alg sha1;
shared-secret "MySQL-HA";
}
syncer {
# rate after al-extents use-rle cpu-mask verify-alg csums-alg
rate 35M;
}
}
###配置資源文件redisk.res
# vi /usr/local/drbd/etc/drbd.d/redisk.res
resource redisk {
on orasrv1.xlk.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.21.10:7789;
meta-disk internal;
}
on orasrv2.xlk.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.21.13:7789;
meta-disk internal;
}
}
###也可以通過copy方式直接將配置文件copy到節點2,則無需單獨配置2個配置文件,如下:
# scp /usr/local/drbd/etc/drbd.d/* 192.168.21.13:/usr/local/drbd/etc/drbd.d/
# scp /usr/local/drbd/etc/drbd.conf 192.168.21.13:/usr/local/drbd/etc/
6、創建device metadata(兩節點執行)
# drbdadm create-md redisk
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@orasrv1 drbd.d]# drbdadm up redisk
[root@orasrv1 drbd.d]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 09:16:05
m:res cs ro ds p mounted fstype
0:redisk WFConnection Secondary/Unknown Inconsistent/DUnknown C
5、設置Primary節點(主節點)
以下操作僅在節點1(orasrv1)執行
# drbdadm primary --force redisk
0: State change failed: (-2) Need access to UpToDate data
Command 'drbdsetup 0 primary' terminated with exit code 17
# drbdadm -- --overwrite-data-of-peer primary redisk
# mkfs.ext3 /dev/drbd0
# mkdir /data
# mount /dev/drbd0 /data
# df -h |grep data
/dev/drbd0 2.0G 36M 1.9G 2% /data
###在第二個節點上創建/data目錄
# mkdir /data
###查看drbd狀態信息:
#cat /proc/drbd
四、DRBD數據鏡像功能測試
###首先在主節點完成如下操作
# cp -R /usr/local/drbd /data
# ls /data/drbd
etc lib sbin share var
# du -sh /data/drbd
324K /data/drbd
# umount /data
# drbdadm secondary redisk
# cat /proc/drbd
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 10:58:13
0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:1044700 nr:0 dw:33780 dr:1045517 al:3 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
###在備用節點完成如下操作
# drbdadm primary redisk
# cat /proc/drbd
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 10:59:26
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:0 nr:1044700 dw:1044700 dr:672 al:0 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
# mount /dev/drbd0 /data
# du -sh /data/drbd ###兩節點數據目錄及大小完全一致
324K /data/drbd