Image Technology DRBD

Source: Internet
Author: User

For small and medium-sized enterprises, the pressure on devices that want to purchase shared storage is quite high. DRBD can play a role when it cannot afford such an expensive cost. In fact, it is similar to network-based raid1 and has a complete backup on the disk of each host, so when a single machine goes down, it will not have a big impact on the business. Before I did the experiment, I had a misunderstanding in my understanding. I would like to mention it here: At the beginning, I thought DRBD was like this, the disks of each server in the LAN have exactly the same data. Each server is attached with its own hard disk and data is synchronized through DRBD. However, when I did the experiment below, I found that the slave node could not mount the relevant DRBD device/dev/drbd1). That is to say, only the DRBD device on the master server can provide read and write capabilities, the device on the slave server cannot be used at all, but it has data and is synchronized with the master server. This shows that my previous understanding is incorrect. In fact, when using DRBD, it is usually used in a architecture similar to HeartBeat + NFS + DRBD. DRBD only provides data redundancy. This time, we will not introduce that much. We will do it in the next experiment. Tutorial topology: 650) this. width = 650; "style =" width: 615px; height: 292px "title =" 123.jpg" src = "http://www.bkjia.com/uploads/allimg/131227/1H6231A7-0.jpg" width = "732" height = "286"/> experiment environment: minimize virtual box centos 6.4
Lab procedure]1. Configure the Host Name[Root @ localhost ~] # Vim/etc/sysconfig/networkHOSTNAME = node1
[Root @ localhost ~] # Vim/etc/hosts192.168.56.120 node11942556.121 node2
[Root @ localhost ~] # Hostname node1 ============================== [root @ localhost ~] # Vim/etc/sysconfig/networkHOSTNAME = node2
[Root @ localhost ~] # Vim/etc/hosts192.168.56.120 node11942556.121 node2
[Root @ localhost ~] # Hostname node2
2. Add the hard disk to be synchronized650) this. width = 650; "title =" clipboard.png "src =" http://www.bkjia.com/uploads/allimg/131227/1H623K03-1.png "/>3. Create a partition[Root @ node1 ~] # Fdisk-U/dev/sdb The number of cylinders for this disk is set to 20805. there is nothing wrong with that, but this is larger than 1024, and cocould in certain setups cause problems with: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software from other OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help): n // type n to create a partition Command action e extended p Primary partition (1-4) p // type p to create the primary Partition partition number (1-4): 1 // type 1 First cylinder (1-20805, default 1): // start the magnetic column value. Press enter to Using default value 1 Last cylinder or + size or + sizeM or + sizeK (1-20805, default 20805 ): // end The magnetic column value. Press enter to Using default value 20805 Command (m for help): w // type w to confirm The execution of The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks.
[Root @ node1 ~] # Partprobe // make the change to the partition table take effect
Note: Only the newly added hard disk is partitioned, neither formatted nor attached. After the partition is created, create the/db directory [root @ node1 drbd] # mkdir/db
4. Install DRBDNode 1 and node 2 follow the same configuration. Here, only the steps of node1 are recorded, and node2 follows node1. [Root @ node1 ~] # Yum-y install kernel-devel kernel-headers flex wget gcc-c ++ make [root @ node1 src] # wget unzip src] # tar xf drbd-8.4.3.tar.gz [root @ node1 src] # cd drbd-8.4.3 [root @ node1 drbd-8.4.3] #. /configure -- prefix =/usr/local/drbd -- with-km [root @ node1 drbd-8.4.3] # make KDIR =/usr/src/kernels/2.6.32-358.14.1.el6.i686/[root @ node1 drbd-8.4.3] # make install [root @ node1 drbd-8.4.3] # mkdir-p/usr/local/drbd/var/run/drbd [root @ node1 drbd-8.4.3] # cp/usr/local/ drbd/etc/rc. d/init. d/drbd/etc/rc. d/init. d/[root @ node1 drbd-8.4.3] # chkconfig -- add drbd [root @ node1 drbd-8.4.3] # chkconfig drbd on
According to the drbd module [root @ node1 drbd-8.4.3] # cd/usr/src/drbd-8.4.3/drbd [root @ node1 drbd] # make clean [root @ node1 drbd] # make KDIR =/usr /src/kernels/2.6.32-358.14.1.el6.i686/[root @ node1 drbd] # cp drbd. ko/lib/modules/'uname-R'/kernel/lib/[root @ node1 drbd] # depmod
5. Configure drbdIt mainly defines two global and resource [root @ node1 drbd] # vim/usr/local/drbd/etc/drbd. conf include "drbd. d/global_common.conf "; include" drbd. d /*. res "; the content of the master configuration file has been written and does not need to be modified. In fact, this configuration file only references the global and resource files.
[Root @ node1 drbd] # vim/usr/local/drbd/etc/drbd. d/global_common.conf global {usage-count yes ;}
Common {net {protocol C ;}}
[Root @ node1 drbd] # vim/usr/local/drbd/etc/drbd. d/r0.res resource r0 {on node1 {device/dev/drbd1; disk/dev/sdb1; address 192.168.56.120: 7789; meta-disk internal ;}
On node2 {device/dev/drbd1; disk/dev/sdb1; address 192.168.56.121: 7789; meta-disk internal ;}}
[Root @ node1 drbd] # modprobe drbd // load drbd module [root @ node1 drbd] # lsmod | grep drbd // check whether drbd module is loaded to drbd 292339 0
[Root @ node1 drbd] # dd if =/dev/zero of =/dev/sdb1 bs = 1 M count = 100 // create information for the new hard disk or create-md an error is reported) [root @ node1 drbd] # drbdadm create-md r0 // create drbd resource [root @ node1 drbd] # drbdadm up r0 // start resource r0
The status of node1 and node2 should be similar to the following: [root @ node1 drbd] # cat/proc/drbdversion: 8.4.3 (api: 1/proto: 86-101) GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root @ node1, 2013-07-2
1: cs: Connected ro: Secondary/Secondaryds: 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: 1047484

It indicates that the service has been started and both nodes are slave nodes. If synchronization is not set, you need to set the Primary Node)
The following operations are only performed on node1.Set node1 to primary node:
[Root @ node1 drbd] # drbdadm primary -- force r0 check the status of node1 again: [root @ node1 drbd] # cat/proc/drbd version: 8.4.3 (api: 1/proto: 86-101) GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root @ node1, 08:48:43
1: cs: SyncSource ro: Primary/Secondaryds: UpToDate/Inconsistent C r --- n-ns: 172600 nr: 0 dw: 0 dr: 173720 al: 0 bm: 10 lo: 0 pe: 3 ua: 1 ap: 0 ep: 1 wo: f oos: 877500
We can see that the status has changed to Primary/Secondary, that is, the primary node is successfully set.

Create a DRBD File System(The following operations are only performed on node1)Format/dev/drbd1 to an ext3 file system and mount it to the/db directory we created. [root @ node1 ~] # Mkfs. ext3/dev/drbd1 [root @ node1 ~] # Mount/dev/drbd1/db/
[Root @ node1 ~] # Df-hFilesystem Size Used Avail Use % Mounted on/dev/mapper/VolGroup-lv_root 6.5G 903 M 5.2G 15%/tmpfs 250 M 0 250 M 0%/dev/shm/dev/sda1 485 M 30 M 430 M 7%/boot/dev/drbd1 1007 M 18 M 939 M 2%/db now, as long as data is written to the/db directory, drbd will immediately synchronize the data to the backup machine 192.168.56.121 [root @ node1 ~] # Echo "test DRBD">/db/test.txt
6. Test SynchronizationWhen the standby machine node2 starts drbd,/dev/sdb1 cannot be mounted. To perform a synchronization test, we can write data in the/db/directory of node1, then stop the drbd of node2. [Root @ node2 drbd] # mount-t ext3/dev/sdb1/dbmount:/dev/sdb1 already mounted or/db busy // drbd without stopping node2 cannot mount sdb1
[Root @ node2 drbd] # drbdadm down r0 [root @ node2 drbd] # mount-t ext3/dev/sdb1/db [root @ node2 drbd] # cat/db/test.txt test DRBD
We can see that the data above node1 has been synchronized.
If you need to manually switch between the master and slave nodes, you can do this: [root @ node1 ~] # Umount/dev/drbd1 [root @ node1 ~] # Drbdadm secondary r0
[Root @ node2 drbd] # drbdadm primary r0
[Root @ node1 ~] # Cat/proc/drbd version: 8.4.3 (api: 1/proto: 86-101) GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root @ node1, 08:48:43
1: cs: Connected ro: Secondary/Primaryds: UpToDate/UpToDate C r ----- ns: 1080932 nr: 0 dw: 33460 dr: 1049250 al: 14 bm: 67 lo: 0 pe: 0 ua: 0 ap: 0 ep: 1 wo: f oos: 0
The switch is successful! This experiment is complete!

 

This article is from the "pmghong" blog, please be sure to keep this source http://pmghong.blog.51cto.com/3221425/1260138

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.