Distributed Replicated Block Device(DRBD)是一個(gè)用軟件實(shí)現(xiàn)的、無(wú)共享的、服務(wù)器之間鏡像塊設(shè)備內(nèi)容的存儲(chǔ)復(fù)制解決方案。
我們可以理解為它其實(shí)就是個(gè)網(wǎng)絡(luò)Raid 1,兩臺(tái)服務(wù)器間就算某臺(tái)因斷電或宕機(jī)也不會(huì)對(duì)數(shù)據(jù)有任何影響,而真正的熱切換可以通過(guò)Heartbeat方案解決,不需要人工干預(yù)。
一、環(huán)境描述
系統(tǒng)版本:centos6.6 x64(內(nèi)核2.6.32-504.16.2.el6.x86_64)
DRBD版本:DRBD-8.4.3
node1(主節(jié)點(diǎn))IP: 192.168.0.191 主機(jī)名:drbd1.corp.com
node2(從節(jié)點(diǎn))IP: 192.168.0.192 主機(jī)名:drbd2.corp.com
(node1) 僅為主節(jié)點(diǎn)配置
(node2) 僅為從節(jié)點(diǎn)配置
(node1,node2) 為主從節(jié)點(diǎn)共同配置
二、安裝前準(zhǔn)備:(node1,node2)
1、關(guān)閉iptables和SELINUX,避免安裝過(guò)程中報(bào)錯(cuò)。
1234567 | # service iptables stop# chkconfig iptables off# setenforce 0# vi /etc/selinux/config---------------SELINUX=disabled--------------- |
2、配置hosts文件
123 | # vi /etc/hosts192.168.0.191 drbd1.corp.com192.168.0.191 drbd2.corp.com |
3、在兩臺(tái)虛擬機(jī)分別添加一塊10G硬盤分區(qū)作為DRBD設(shè)備磁盤,分別都為sdb1,大小10G,并在本地系統(tǒng)創(chuàng)建/store目錄,不做掛載操作。
12345 | # fdisk /dev/sdb----------------n-p-1-1-"+10G"-w----------------# mkdir /store |
4、時(shí)間同步:
1 | # ntpdate -u asia.pool.ntp.org |
三、DRBD的安裝配置:
1、安裝依賴包:(node1,node2)
1 | # yum install gcc gcc-c++ make glibc flex kernel-devel kernel-headers |
2、安裝DRBD:(node1,node2)
12345678910 | # wget http://oss.linbit.com/drbd/8.4/drbd-8.4.3.tar.gz# tar zxvf drbd-8.4.3.tar.gz# cd drbd-8.4.3# ./configure --prefix=/usr/local/drbd --with-km# make KDIR=/usr/src/kernels/2.6.32-504.16.2.el6.x86_64/# make install# mkdir -p /usr/local/drbd/var/run/drbd# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d# chkconfig --add drbd# chkconfig drbd on |
3、加載DRBD模塊:(node1,node2)
1 | # modprobe drbd |
查看DRBD模塊是否加載到內(nèi)核:
123 | # lsmod |grep drbddrbd 310172 4libcrc32c 1246 1 drbd |
4、參數(shù)配置:(node1,node2)
1 | # vi /usr/local/drbd/etc/drbd.conf |
清空文件內(nèi)容,并添加如下配置:
123456789101112131415161718192021222324252627 | resource r0{protocol C; startup { wfc-timeout 0; degr-wfc-timeout 120;}disk { on-io-error detach;}net{timeout 60;connect-int 10;ping-int 10;max-buffers 2048;max-epoch-size 2048;}syncer { rate 200M;} on drbd1.corp.com{device /dev/drbd0;disk /dev/sdb1;address 192.168.0.191:7788;meta-disk internal;}on drbd2.corp.com{device /dev/drbd0;disk /dev/sdb1;address 192.168.0.192:7788;meta-disk internal;}} |
注:請(qǐng)修改上面配置中的主機(jī)名、IP、和disk為自己的具體配置
5、創(chuàng)建DRBD設(shè)備并激活r0資源:(node1,node2)
12345678910111213141516171819202122232425 | # mknod /dev/drbd0 b 147 0# drbdadm create-md r0 等待片刻,顯示success表示drbd塊創(chuàng)建成功Writing meta data...initializing activity logNOT initializing bitmapNew drbd meta data block successfully created. --== Creating metadata ==--As with nodes, we count the total number of devices mirrored by DRBDat http://usage.drbd.org. The counter works anonymously. It creates a random number to identifythe device and sends that random number, along with the kernel andDRBD version, to usage.drbd.org. http://usage.drbd.org/cgi-bin/insert_usage.pl? nu=716310175600466686&ru=15741444353112217792&rs=1085704704 * If you wish to opt out entirely, simply enter 'no'.* To continue, just press [RETURN] success |
再次輸入該命令:
12345678 | # drbdadm create-md r0成功激活r0[need to type 'yes' to confirm] yes Writing meta data...initializing activity logNOT initializing bitmapNew drbd meta data block successfully created. |
6、啟動(dòng)DRBD服務(wù):(node1,node2)
1 | # service drbd start |
注:需要主從共同啟動(dòng)方能生效
7、查看狀態(tài):(node1,node2)
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd1.corp.com, 2015-05-12 21:05:41m:res cs ro ds p mounted fstype0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C |
這里ro:Secondary/Secondary表示兩臺(tái)主機(jī)的狀態(tài)都是備機(jī)狀態(tài),ds是磁盤狀態(tài),顯示的狀態(tài)內(nèi)容為“Inconsistent不一致”,這是因?yàn)镈RBD無(wú)法判斷哪一方為主機(jī),應(yīng)以哪一方的磁盤數(shù)據(jù)作為標(biāo)準(zhǔn)。
8、將drbd1.example.com主機(jī)配置為主節(jié)點(diǎn):(node1)
1 | # drbdsetup /dev/drbd0 primary --force |
分別查看主從DRBD狀態(tài):
(node1)
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd1.corp.com, 2015-05-12 21:05:41m:res cs ro ds p mounted fstype0:r0 Connected Primary/Secondary UpToDate/UpToDate C |
(node2)
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd2.corp.com, 2015-05-12 21:05:46m:res cs ro ds p mounted fstype0:r0 Connected Secondary/Primary UpToDate/UpToDate C |
ro在主從服務(wù)器上分別顯示 Primary/Secondary和Secondary/Primary
ds顯示UpToDate/UpToDate
表示主從配置成功。
9、掛載DRBD:(node1)
從剛才的狀態(tài)上看到mounted和fstype參數(shù)為空,所以我們這步開(kāi)始掛載DRBD到系統(tǒng)目錄/store
12 | # mkfs.ext4 /dev/drbd0# mount /dev/drbd0 /store |
注:Secondary節(jié)點(diǎn)上不允許對(duì)DRBD設(shè)備進(jìn)行任何操作,包括掛載;所有的讀寫(xiě)操作只能在Primary節(jié)點(diǎn)上進(jìn)行,只有當(dāng)Primary節(jié)點(diǎn)掛掉時(shí),Secondary節(jié)點(diǎn)才能提升為Primary節(jié)點(diǎn),并自動(dòng)掛載DRBD繼續(xù)工作。
成功掛載后的DRBD狀態(tài):(node1)
123456 | # service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@drbd1.corp.com, 2015-05-12 21:05:41m:res cs ro ds p mounted fstype0:r0 Connected Primary/Secondary UpToDate/UpToDate C /store ext4 |
原文鏈接:CentOS6.5下DRBD+HeartBeat+NFS配置(一),轉(zhuǎn)載請(qǐng)注明來(lái)源!
聯(lián)系客服