歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> DRBD安裝過程

DRBD安裝過程

日期:2017/2/27 11:59:36   编辑:Linux文化

DRBD 是由內核模塊和相關腳本而構成,用以構建高可用性的集群。其實現方式是通過網絡來鏡像整個設備。 您可以把它看作是一種網絡RAID。 Drbd 負責接收數據,把數據寫到本地磁盤,然後發送給另一個主機。另一個主機再將數據存到自己的磁盤中。 源碼下載http://oss.linbit.com/drbd/0.7/drbd-0.7.19.tar.gz 核心參考文檔:http://www.drbd.org/drbd-howto.html ============

1、主要實現

假設有兩台機器nannan:192.168.0.136 需要鏡像的硬盤:/dev/hdc3 root:192.168.0.139 需要鏡像的硬盤:/dev/hdc2 主服務器為192.168.0.136 簡稱為136 備份服務器為192.168.0.139 簡稱為139 平常對數據讀寫都在136上實現,當136 down掉後可以啟動139,實現數據的熱備份。 真正的熱切換需要才用HA 來實現。

2、下載安裝

安裝環境:fc2,內核版本:2.6.12.4 確認內核源碼存在。 下載源碼注意:當前最新的drbd-8.0pre3,配置文件無法正常配置,出現一大堆錯誤,所以下載以前的穩定版本。 tar開源碼包後 運行: A、make KDIR=/usr/src/linux /*內核所在的位置*/ /*如果你沒有更改內核可以直接運行make,軟件會直接到/lib/module裡邊去尋找系統環境,如果是新的內核需要對內核進行編譯安裝, 否則make時候會錯誤中斷掉*/ B、make install 安裝完主要生成命令:drbdsetup ,drbdadmin 和配置文件:/etc/drbd.conf ,啟動文件,/etc/init.d/drbd 模塊文件:drbd.ko(在編譯好的安裝包目錄下的drbd下可以找到) 所有命令和配置文件都可以在源碼包編譯成功的目錄下面找到。 ./scripts/drbd.conf是最原始的配置文件,當/etc/drbd.conf被破壞,可以直接拷貝覆蓋掉。

C、創建硬件設備drbd mknod /dev/drbd0 b 147 0 mknod /dev/drbd1 b 147 1 mknod /dev/drbd2 b 147 2 或者用shell來建立多個: #for i in $(seq 0 15) ; do mknod /dev/drbd$i b 147 $i ; done

3、配置drbd

修改/etc/drbd.conf 主要修改了:機器名和設備名ip地址 ====================================================== on nannan{ device /dev/drbd0; disk /dev/hdc3; address 192.168.0.136:7788; meta-disk internal;

# meta-disk is either 'internal' or '/dev/ice/name [idx]' # # You can use a single block device to store meta-data # of multiple DRBD's. # E.g. use meta-disk /dev/hde6[0]; and meta-disk /dev/hde6[1]; # for two different resources. In this case the meta-disk # would need to be at least 256 MB in size. # # 'internal' means, that the last 128 MB of the lower device # are used to store the meta-data. # You must not give an index with 'internal'. }

on root { device /dev/drbd0; disk /dev/hdc2; address 192.168.0.139:7788; meta-disk internal; } ====================================================== 下面是整個drbd.conf的配置文件 注意:配置的版本是drbd-0.7.19.tar.gz 不同版本無法兼容。 修改的地方就以上幾個地方和注釋 還有把除了resource r0 外的其他配置塊如resource r1等。 也就是說/**** on root { device /dev/drbd0; disk /dev/hdc2; address 192.168.0.139:7788; meta-disk internal; } } ****/後面的所有內容

# # drbd.conf example #

skip { As you can see, you can also comment chunks of text with a 'skip[optional nonsense]{ skipped text }' section. This comes in handy, if you just want to comment out some 'resource {...}' section: just precede it with 'skip'.

The basic format of option assignment is ; It should be obvious from the examples below, but if you really care to know the details: := valid options in the respective scope := |||... depending on the set of allowed values for the respective option. := [0-9]+, sometimes with an optional suffix of K,M,G := (|\"([^\"\\\n]*|\\.)*\")+ := [/_.A-Za-z0-9-]+ } # global { # use this if you want to define more resources later # without reloading the module. # by default we load the module with exactly as many devices # as configured mentioned in this file. # # minor-count 5;

# The user dialog counts and displays the seconds it waited so # far. You might want to disable this if you have the console # of your server connected to a serial terminal server with # limited logging capacity. # The Dialog will print the count each 'dialog-refresh' seconds, # set it to 0 to disable redrawing completely. [ default = 1 ] # # dialog-refresh 5; # 5 seconds

# You might disable one of drbdadm's sanity check. # disable-ip-verification; # } # # this need not be r#, you may use phony resource names, # like "resource web" or "resource mail", too #

resource r0 {

protocol C;

# what should be done in case the cluster starts up in # degraded mode, but knows it has inconsistent data. incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";

startup { degr-wfc-timeout 120; # 2 minutes. }

disk { }

net { }

syncer { rate 10M; group 1; al-extents 257; }

on nannan{ device /dev/drbd0; disk /dev/hdc3; address 192.168.0.136:7788; meta-disk internal;

}

on root { device /dev/drbd0; disk /dev/hdc2; address 192.168.0.139:7788; meta-disk internal; } }

=================================================

4、啟動drbd 先確認兩台要鏡像的機器是否正常,之間的網絡是否通暢,需要加載的硬盤是否處於umount狀態。 確認好後就可以開始啟動drbd

先後在136和139機器上面 運行

A、drbd采用的是模塊控制的方式 所以先要加載drbd.ko 模塊 insmod drbd.ko drbd.ko可以在編譯好的源碼包裡找到。 判斷是否加載成功可以使用lsmod來查看: Module size Used by drbd 143088 - 有的話表示加載模塊成功

B、drbdadm up all 啟動drbd服務,使他掛在後台狀態下運行 可以使用命令netstat -an查看 有啟動端口7788,同時也監聽對方的7788端口,來實現數據交換。

5、drbd的基本服務都起來了,現在需要對主的服務器也就使192.168.0.136這台服務器進行配置, 讓他能夠對drbd0設備進行讀寫。 在136機器上運行 drbdadm -- --do-what-I-say primary all 注意命令格式需要一樣 沒有任何提示的話表示基本上成功了 sfdisk -s 可以看見有一個硬件設備:/dev/drbd0 如果原來硬盤沒有文件系統的話,現在您可以在設備/dev/drbd0上創建一個文件系統,然後把它加載到136上。

現在/dev/drbd0就等於你服務器上面的一個硬件設備,你可以對他進行任何的讀寫操作。

Copyright © Linux教程網 All Rights Reserved