Linux under Installation DRBD detailed

Source: Internet
Author: User
Tags deprecated

The knowledge of DRBD theory is not introduced in this article, this article mainly describes how to build DRBD.

first, the system environment   System Platform:Centos6.3 (Kernel 2.6.32-431.29.2.el6.x86_64) node One host name:CENOS-HA1 ip:192.168.1.202 node One host name:CENOS-HA2 ip:192.168.1.202 DRBD Version:DRBD-8.4.3 Second, installation   1. Preparation(1). Close iptables and SELinux to avoid error during installation. Node 1 and node 2#/etc/init.d/iptables stop#/etc/init.d/ip6tables stop#chkconfig iptables off#chkconfig ip6tables off

# Vi/etc/sysconfig/selinux

---------------

Selinux=disabled

---------------

(2). Set the Hosts file (node 1 and Node 2) # Vi/etc/hosts

-----------------

192.168.1.202 CENTOS-HA1
192.168.1.203 CENTOS-HA2-----------------Node 1 and Node 2 (restart) (3). Add a 2G hard disk SDB as DRBD on both virtual machines, partitioned to SDB1, size 2G, and created on the local system Data directory, do not mount operation. (Node 1 and Node 2) node 1[[email protected] ~]# Fdisk/dev/sdbdevice contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel
Building a new DOS disklabel with disk identifier 0XD59786D2.
Changes'll remain in memory only, until the decide to write them.
After that, of course, the previous content won ' t is recoverable.

Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite)

Warning:dos-compatible mode is deprecated. It ' s strongly recommended to
Switch off the mode (command ' C ') and change display units to
Sectors (Command ' u ').

Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-261, default 261):
Using Default Value 261

Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.
Syncing disks. [[Email protected] ~] #mkdir/data node 2[[email protected] ~]# Fdisk/dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel
Building a new DOS disklabel with disk identifier 0x9adc5d39.
Changes'll remain in memory only, until the decide to write them.
After that, of course, the previous content won ' t is recoverable.

Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite)

Warning:dos-compatible mode is deprecated. It ' s strongly recommended to
Switch off the mode (command ' C ') and change display units to
Sectors (Command ' u ').

Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-261, default 261):
Using Default Value 261

Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.
Syncing disks.
[[Email protected] ~] #mkdir/data (4). Time Synchronization

# Ntpdate-u Asia.pool.ntp.org

2. Installation configuration for DRBD (1). Install the Dependent packages: (Node 1 and Node 2) #yum install GCC gcc-c++ make glibc flex kernel kernel-devel kernel-headers (2) Installation DRBD: (section Point 1 and Node 2)

# 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-431.29.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/init.d/

# chkconfig--add DRBD

# chkconfig--level + DRBD on (3) Load DRBD Module (node 1 and Node 2) #modprobe DRBD If the following error occurs [[email protected] drbd-8.4.3]# modprobe DRBD
Fatal:module DRBD not found. Workaround: http://88fly.blog.163.com/blog/static/1226803902013111345347479 (note: Do not use Yum Install kernel* because I did the experiment and then restarted the system. You can use Yum install kernel kernel-devel kernel-headers)

To see if the DRBD module is loaded into the kernel: (Node 1 and Node 2)

# Lsmod |grep DRBD node 1 Node 2

3. Parameter configuration: (Node 1 and Node 2)

# vi/usr/local/drbd/etc/drbd.conf

Clear the contents of the file and add the following configuration:

---------------

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 centos-ha1{

device/dev/drbd0;

DISK/DEV/SDB1;

Address 192.168.1.202:7788;

Meta-disk internal;

}

On centos-ha2{

device/dev/drbd0;

DISK/DEV/SDB1;

Address 192.168.1.203:7788;

Meta-disk internal;

}

}

---------------(note: For details of the parameters please refer to http://www.cnblogs.com/Elliot-wang/p/3994362.html)

(4). Create a DRBD device and activate the RO resource: (Node 1 and Node 2)

# Mknod/dev/drbd0 B 147 0

# Drbdadm CREATE-MD R0

Wait a moment, show success indicates that the DRBD block was created successfully

----------------

Writing Meta Data ...

Initializing activity log

Not initializing bitmap

New DRBD Meta data block successfully created.

--== Creating Metadata ==--

As with nodes, we count the total number of devices mirrored by DRBD

At http://usage.drbd.org.

The counter works anonymously. It creates a random number to identify

The device and sends that random number, along with the kernel and

DRBD version, to usage.drbd.org.

Http://usage.drbd.org/cgi-bin/insert_usage.pl?

nu=716310175600466686&ru=15741444353112217792&rs=1085704704

* If you wish-opt out entirely, simply enter ' no '.

* To continue, just press [RETURN]

Success

----------------

Enter the command again:

# Drbdadm CREATE-MD R0

Successfully activated R0

----------------

[Need to type ' yes ' to confirm] Yes

Writing Meta Data ...

Initializing activity log

Not initializing bitmap

New DRBD Meta data block successfully created.

----------------

5. Start the DRBD Service: (Node 1, node 2)

# service DRBD Start

6. View Status: (Node1,node2) #service DRBD status# CAT/PROC/DRBD

(7). Configure the CENTOS-HA1 host as the primary node: (Node 1)

[[email protected] ~]# DRBDSETUP/DEV/DRBD0 primary--force View host Status node 1[[email protected] ~] #service DRBD Status node 2[[email Protected] ~] #service DRBD Status

RO displays primary/secondary and secondary/primary on the master and slave servers respectively

DS Display Uptodate/uptodate

Indicates a successful master-slave configuration.

(8). Mount DRBD: (node 1)

See the mounted and Fstype parameters as empty from the previous state, so we started to mount DRBD to the system directory

[Email protected] ~]# mkfs.ext4/dev/drbd0

[Email protected] ~]# Mount/dev/drbd0/data

Note: No operations on the DRBD device are allowed on the secondary node, including read-only, and all read and write operations can only be performed on the primary node, and the secondary node can be promoted to continue working for primary nodes only if the primary node is hung out.

(9). Analog DRBD1 Fault, DRBD2 take over and promote to primary

(Node 1)

[[Email protected] ~] #cd/data

[email protected] ~]# Touch a.txt b.txt c.txt d.txt e.txt

[[Email protected] ~] #cd.

[Email protected] ~]# Umount/data

[[email protected] ~]# drbdsetup/dev/drbd0 Secondary Note: Here the actual production environment if DRBD1 down, in the DRBD2 status information, the value of RO will be displayed as Secondary/unknown, You only need to do the DRBD right operation. (Node 2) [Email protected] ~]# DRBDSETUP/DEV/DRBD0 Primary

[Email protected] ~]# Mount/dev/drbd0/data

[Email protected] ~]# Cd/data

[email protected] ~]# Touch f.txt g.txt h.txt j.txt k.txt

[[email protected] ~]# ls

--------------

A.txt b.txt c.txt d.txt e.txt f.txt g.txt h.txt j.txt k.txt lost+found--------------to this DRBD has been installed.

However, how to ensure the intelligent switching of DRBD master-slave structure, to achieve high availability, here need heartbeat to achieve.

Heartbeat will automatically switch from the end to the primary side and automatically mount the/data partition when the DRBD master is hung off.

Note: (from the building of the High Availability Linux Server 2nd edition of Wine Brother)

Assuming that you eth0 the primary, and then directly on the secondary on the master primary host, and mount, you may find that the files tested on the primary are indeed synchronized, and then after Primary's eth0 is restored, See if there is automatic recovery of the master-slave relationship. After reviewing, found that DRBD detected the condition of the split-brain, that is, two nodes are in the standalone state, the fault description is as follows: Split-brain detected,dropping connection!  This is the legendary "brain fissure". Below I do a test first will just the main standby environment switch back, this step I no longer narrated, Yasuteru 9th step in turn operation can below I to simulate Test node 1[[email protected] ~]# Cd/data
[Email protected] ~]# lsa.txt b.txt c.txt d.txt e.txt f.txt g.txt h.txt j.txt k.txt lost+found[[email protected ] ~]# Touch aa.txt bb.txt cc.txt[[email protected] ~]# CD. [[email protected] ~]# umount data[[email protected] ~]# ifdown eth0 node 2[[email protected] ~] #drbdsetup/dev/drbd0 Primar Y[[email protected] ~]# Cd/data[[email protected] ~] #mount/dev/drbd0/data[[email protected] ~] #cd/data[[email protecte D] ~] #ls aa.txt bb.txt cc.txt d.txt f.txt h.txt k.txt
A.txt b.txt c.txt e.txt g.txt j.txt lost+found node 1[[email protected] ~]# ifup eth0 [[email protected] ~] #drbd ADM secondary R0 [[email protected] ~] #service DRBD Status node 2[[email protected] ~]# cd/data [[email protected] ~]# tou CH Aaa.txt bbb.txt Ccc.txt
[[Email protected] ~] #lsaaa. txt a.txt bb.txt ccc.txt c.txt e.txt g.txt j.txt lost+found
Aa.txt bbb.txt b.txt cc.txt d.txt f.txt h.txt k.txt [[email protected] ~]# CD. [[email protected] ~]# umount/data[[email protected] ~]# Drbdadm secondary r0 node 1[[email protected] ~]# drbdsetup/dev/d RBD0 primary [[email protected] ~] #mount/dev/drbd0/data[[email protected] ~]# cd/data/
[[email protected] ~]# ls
Aa.txt bb.txt cc.txt d.txt f.txt h.txt k.txt
A.txt b.txt c.txt e.txt g.txt j.txt lost+found (Note: File not synced)

Workaround (first restore the system to the pre-start state, which is eth0 down) node 1[[email protected] ~]# Umount/data
[[email protected] ~]# Drbdadm secondary r0 node 2[[email protected] ~]# drbdsetup/dev/drbd0 Primary

[Email protected] ~]# mount/dev/drbd0/data [[email protected] ~]# Cd/data
[[email protected] ~]# ls
Aaa.txt a.txt bb.txt ccc.txt c.txt e.txt g.txt j.txt lost+found
Aa.txt bbb.txt b.txt cc.txt d.txt f.txt h.txt K.txt has been restored to the start of the failure state, the following start to resolve node 1

[Email protected] ~]# Drbdadm secondary r0

[Email protected] ~]# Drbdadm disconnect All

[Email protected] ~]# drbdadm--discard-my-data connect r0

Switch back [[email protected] ~]# Drbdadm secondary r0[[email protected] ~]# drbdsetup/dev/drbd0 primary[[email protected] ~]# m Ount/dev/drbd0/data[[email protected] ~]# Cd/data
[[email protected] ~]# ls
Aaa.txt a.txt bb.txt ccc.txt c.txt e.txt g.txt j.txt lost+found
Aa.txt bbb.txt b.txt cc.txt d.txt f.txt h.txt k.txt (Note: This eth0 outage experiment, if the/data directory does not unload the words directly ifdown eth0 is not successful) complete  

Linux under Installation DRBD detailed

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.