Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of DRBD compilation, installation and configuration in linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about the sample analysis of DRBD compilation, installation and configuration in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

DRBD introduction

DRBD is a software-implemented, non-shared storage replication solution that mirrors the content of block devices between servers. DRBD Logo data mirroring: real-time, transparent, synchronous (return after success of all servers), asynchronous (return after success of local server). The core function of DBRD is implemented through the kernel of Linux, which is closest to the IO stack of the system, but it cannot magically add upper-layer functions such as detecting the crash of the EXT3 file system. DBRD is located below the file system, closer to the operating system kernel and IO stack than the file system.

DRBD compilation and installation

Dependencies required for installation:

Yum-y install gcc kernel-devel kernel-headers flex

Start installing drbd, download address: http://oss.linbit.com/drbd/

Install the user space tools:

Cd / tmpwget http://oss.linbit.com/drbd/8.4/drbd-8.4.1.tar.gztar xzf drbd-8.4.1.tar.gzcd drbd-8.4.1./configure-- prefix=/usr/local/drbd-- with-kmmake KDIR=/usr/src/kernels/2.6.18-274.18.1.el5-i686/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

Install the drbd module:

Cd drbd make clean make KDIR=/usr/src/kernels/2.6.18-274.18.1.el5-i686/ cp drbd.ko / lib/modules/ `uname-r` / kernel/lib/ depmod

Note: the usr/src/kernels/2.6.18-274.18.1.el5-i686/ kernel source tree path needs to be modified according to your own system.

DRBD configuration

Establish Partition

If you now have a second hard drive hdb, both node should be partitioned.

# fdisk / dev/hdb / / prepare to set up a partition The number of cylinders for this disk is set to 20805 for hdb. There is nothing wrong with that, but this is larger than 1024, and could 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 establish a primary partition Partition number (1-4): 1 / / Type 1 for this primary partition code First cylinder (1-20805) Default 1): / / start column value Press enter to Using default value 1 Last cylinder or + size or + sizeM or + sizeK (1-20805, default 20805): / / end the column value, press enter to Using default value 20805 Command (m for help): W / / type w to confirm the execution of the The partition table has been altered you just set! Calling ioctl () to re-read partition table. Syncing disks. [root@node1 yum.repos.d] # partprobe / / to make the partition table changes take effect

After setting up the partition, use the instruction fdisk-l to determine the partition talbe status.

# fdisk-l Disk / dev/hda: 21.4 GB, 21474754560 bytes 255heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System / dev/hda1 * 1 13 104391 83 Linux / dev/hda2 14 2610 20860402 + 8e Linux LVM Disk / dev/hdb: 10.7 GB, 107377280 bytes 16 heads, 63 sectors/track 20805 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot Start End Blocks Id System / dev/hdb1 1 20805 10485688 + 83 Linux

Please create the / db directory after the partition has been created. (both Node1 and Node2 must be established)

# mkdir / db

Establish a Drbd profile

Mainly define two pieces of global and resource.

Vi / usr/local/drbd/etc/drbd.conf write: include "drbd.d/global_common.conf"; include "drbd.d/*.res"; vi / usr/local/drbd/etc/drbd.d/global_common.conf write global {usage-count yes;} common {net {protocol C;}} vi / usr/local/drbd/etc/drbd.d/r0.res write resource r0 {device / dev/drbd1; disk / dev/hdb1 Address 192.168.1.101on node2 7789; meta-disk internal;} on node2 {device / dev/drbd1; disk / dev/hdb1; address 192.168.1.103 virtual 7789; meta-disk internal;}

Set up Hostname

According to the resource configuration file above, you need to set hostname to node1 and node2 for 192.168.1.101 and 192.168.1.103, respectively, as follows:

Vi / etc/sysconfig/network modify HOSTNAME to node1vi / etc/hosts write 192.168.1.101 node1192.168.1.103 node2

Give temporary effect to node1 hostnmae

Hostname node1

The node2 machine settings are similar.

Set up Resource

The following operations are required in node1 and node2.

# modprobe drbd / / load drbd module # lsmod | grep drbd / / confirm whether the drbd module is loaded with drbd 228528 0 # dd if=/dev/zero of=/dev/hdb1 bs=1M count=100 / / insert some data into the hdb (otherwise errors may occur during create-md) # drbdadm create-md R0 / / establish drbd resource # drbdadm up R0 / / start resource R0

To see the status of node1 and node2, you should look like this:

Cat / proc/drbdversion: 8.4.1 (api:1/proto:86-100s) GIT-hash: 91b4c048c1a0e06777b5f65d312b38d47abaea80 build by root@localhost.localdomain, 2012-02-12 06:05:36 m:res cs ro ds p mounted fstype 0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C

Indicates that the service has now been started, but synchronization has not been set (that is, Primary Node needs to be set)

Set up Primary Node

The following operations are performed only in node1.

Set node1 to primary node:

Drbdadm primary-- force R0

Drbdadm primary-- force R0

Check the status of node1 again:

# cat / proc/drbdversion: 8.4.1 (api:1/proto:86-100) GIT-hash: 91b4c048c1a0e06777b5f65d312b38d47abaea80 build by root@localhost.localdomain, 2012-02-12 06:47:37 1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-ns:52892 nr:0 dw:0 dr:52892 al:0 bm:10 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

We see that the state has changed to Primary/Secondary, that is, the primary node has been set successfully.

Create a DRBD file system

The following operations are performed only in node1.

Now that the initialization of / dev/drbd1 is complete, let's format / dev/drbd1 into a file system in ext3 format.

# mkfs.ext3 / dev/drbd1

Then mount / dev/drbd1 to the / db directory you created earlier.

# mount / dev/drbd1 / db

Now all you have to do is write the data to the / db directory and drbd will immediately synchronize the data to the / dev/hdb1 partition of the standby 192.168.1.103.

Drbd synchronous testing

When drbd is started on the standby node2, it cannot mount the / dev/hdb1 partition. We can try to write some data to the directory / db of node1, and then stop the drbd of node2.

Drbdadm down r0

The / dev/hdb1 of node2 can then be mounted to the directory / db

Mount-t ext3 / dev/hdb1 / db

We can check the / db directory of node2 to see if there is data for node1.

Manually switch between master and standby

We can change node1 to standby and node2 to mainframe.

Operate on node1:

Umount / dev/drbd1drbdadm secondary r0

Operate on node2:

Drbdadm primary r0

At this point, the switch should have been successful.

Thank you for reading! This is the end of this article on "sample analysis of DRBD compilation, installation and configuration in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report