歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習Linux

Centos6下DRBD的安裝配置

Centos6下DRBD的安裝配置


Centos6下DRBD的安裝配置


導讀Distributed Replicated Block Device(DRBD)是一個用軟件實現的、無共享的、服務器之間鏡像塊設備內容的存儲復制解決方案。數據鏡像:實時、透明、同步(所有服務器都成功後返回)、異步(本地服務器成功後返回)。DRBD的核心功能通過Linux的內核實現,最接近系統的IO棧,但它不能神奇地添加上層的功能比如檢測到EXT3文件系統的崩潰。DRBD的位置處於文件系統以下,比文件系統更加靠近操作系統內核及IO棧。

drbd_01

一、安裝環境說明
系統版本:CentOS6.5DRBD版本:DRBD-8.4.3node1:  192.168.7.88(drbd1)node2:  192.168.7.89 (drbd2)(node1)為僅主節點配置(node2)為僅從節點配置(node1,node2)為主從節點共同配置
二、准備環境:(node1,node2)

1.關閉iptables和SELINUX,避免安裝過程中報錯

service iptables stop            //關閉iptablessetenforcing 0                 //暫時關閉selinuxsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux    //永久關閉selinux

2.設置hosts文件

vi /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.7.88  drbd1192.168.7.89  drbd2

3.在兩台虛擬機上添加一塊2G硬盤sdb作為DRBD,分別分區為sdb1,大小1G,並在本地系統創建/data目錄,不做掛載操作。

fdisk /dev/sdb----------------n-p-1-回車-"+1G"-wq----------------mkdir /data

4.時間同步:

ntpdate -u asia.pool.ntp.org
三、DRBD的安裝部署

1.安裝依賴包:(node1,node2)

yum install gcc gcc-c++ make glibc flex kernel-devel kernel-headers

2.安裝DRBD:(node1,node2)

wget http://oss.linbit.com/drbd/8.4/drbd-8.4.3.tar.gztar zxvf drbd-8.4.3.tar.gzcd drbd-8.4.3./configure --prefix=/usr/local/drbd --with-kmmake && make installmkdir -p /usr/local/drbd/var/run/drbdcp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.dchkconfig --add drbdchkconfig drbd on加載DRBD模塊:modprobe drbd查看DRBD模塊是否加載到內核:lsmod |grep drbd
四、DRBD的配置

1.參數配置:(node1,node2)

vim /usr/local/drbd/etc/drbd.conf清空裡面的配置,添加如下配置: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 30M;}on drbd1.example.com{  device /dev/drbd0;  disk   /dev/sdb1;  address 192.168.7.88:7788;  meta-disk internal;}on drbd2.example.com{  device /dev/drbd0;  disk   /dev/sdb1;  address 192.168.7.89:7788;  meta-disk internal;}}

2.創建DRBD設備並激活r0資源:(node1,node2)

mknod /dev/drbd0 b 147 0drbdadm create-md r0等待片刻,顯示success表示drbd塊創建成功----------------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]        //出現[RETURN]按回車success----------------再次輸入該命令:# drbdadm create-md r0成功激活r0----------------[need to type 'yes' to confirm] yesWriting meta data...initializing activity logNOT initializing bitmapNew drbd meta data block successfully created.

3.啟動DRBD服務:(node1,node2)

service drbd start

注:需要主從共同啟動方能生效
4.查看狀態:(node1,node2)

cat /proc/drbdversion: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:45:190: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----   ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:1060184或者service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:45:19m:res  cs         ro                   ds                         p  mounted  fstype0:r0   Connected  Secondary/Secondary  Inconsistent/Inconsistent  C

注:這裡ro:Secondary/Secondary表示兩台主機的狀態都是備機狀態,ds是磁盤狀態,顯示的狀態內容為“不一致”,這是因為DRBD無法判斷哪一方為主機,應以哪一方的磁盤數據作為標准。

5.將drbd1主機配置為主節點:(node1)

drbdsetup /dev/drbd0 primary --force

分別查看主從DRBD狀態:

(node1)service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:45:19m:res cs     ro         ds         p mounted fstype0:r0  Connected Primary/Secondary UpToDate/UpToDate C(node2)service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:49:06m:res cs     ro         ds         p mounted fstype0:r0  Connected Secondary/PrimaryUpToDate/UpToDateC

注:ro在主從服務器上分別顯示 Primary/Secondary和Secondary/Primary ds顯示UpToDate/UpToDate表示主從配置成功。
6.掛載DRBD:(node1)

從剛才的狀態上看到mounted和fstype參數為空,所以我們這步開始掛載DRBD到系統目錄mkfs.ext4 /dev/drbd0mount /dev/drbd0 /data注:Secondary節點上不允許對DRBD設備進行任何操作,包括只讀,所有的讀寫操作只能在Primary節點上進行,只有當Primary節點掛掉時,Secondary節點才能提升為Primary節點繼續工作。
五、模擬故障

(node1)

cd /datatouch 1 2 3 4 5cd ..umount /datadrbdsetup /dev/drbd0 secondary

注:這裡實際生產環境若DRBD1宕機,在DRBD2狀態信息中ro的值會顯示為Secondary/Unknown,只需要進行DRBD提權操作即可。

(node2)

drbdsetup /dev/drbd0 primarymount /dev/drbd0 /datacd /datatouch 6 7 8 9 10ls--------------1 10 2 3 4 5 6 7 8 9 lost+found

查看(node1)(node2)DRBD狀態:

(node2)service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:49:06m:res  cs         ro                 ds                 p  mounted  fstype0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /data    ext4(node1)service drbd statusdrbd driver loaded OK; device status:version: 8.4.3 (api:1/proto:86-101)GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected],2013-05-27 20:45:19m:res  cs         ro                 ds                 p  mounted  fstype0:r0   Connected  Secondary/Primary  UpToDate/UpToDate  C

原文來自:http://www.showerlee.com/archives/295

轉載地址:http://www.linuxprobe.com/centos6-drdb-setup-instal.htm


http://xxxxxx/Linuxjc/1134273.html TechArticle

Copyright © Linux教程網 All Rights Reserved