Centos7.0 install and configure DRBD

Source: Internet
Author: User
Tags echo b
First, ensure the time synchronization between the two machines and configure ssh. Method 1 install yum source: the default installation path of yum is/etc/drbd. d/# rpm -- importhttp: // Others

First, ensure the time synchronization between the two machines and configure ssh.

Method 1: install yum from The yum source. the default installation path is/etc/drbd. d /.

# Rpm -- import http://elrepo.org/RPM-GPG-KEY-elrepo.org
# Rpm-Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# Yum-y install drbd84-utils kmod-drbd84

 

Method 2 compile and install: the default path is/usr/local/drbd/etc.

# Yum install docbook-style-xsl # used to compile drbd
# Mkdir-p/tmp/drbdinst
# Wget -- directory-prefix =/tmp/drbdinst/http://oss.linbit.com/drbd/8.4/drbd-8.4.6.tar.gz
# Cd/tmp/drbdinst
# Tar-zxfp drbd-8.4.6.tar.gz
# Cd drbd-8.4.6
# Yum-y install flex gcc make
# Make KDIR =/usr/src/kernels/3.10.0-229.11.1.el7.x86 _ 64

# Make install
Mkdir-pv/usr/local/drbd/var/run/drbd

Cp/usr/local/drbd/etc/rc. d/init. d/drbd/etc/rc. d/init. d

Systemctl enable drbd

 

Cd drbd

Make clean

Make KDIR =/usr/src/kernels/3.10.0-229.11.1.el7.x86 _ 64

Switch to your own kernel version

Cp drbd. ko/lib/modules/'uname-r'/kernel/lib5

Depmod

Modprobe drbd loading module

Lsmod | grpe drbd check whether the load is successful

 

I installed it through the yum source, but the configuration is similar.

Vim/etc/drbd. d/global_common.conf

 

Global {
Usage-count no;
}
Common {
Protocol C;
Handlers {
Pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo B>/proc/sysrq-trigger; reboot-f ";
Pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo B>/proc/sysrq-trigger; reboot-f ";
Local-io-error "/usr/lib/drbd/notify-io-error.sh;/usr/lib/drbd/notify-emergency-shutdown.sh; echo o>/proc/sysrq-trigger; halt-f ";
}
Startup {
Wfc-timeout 30;
Degr-wfc-timeout 30;
}
Options {
}
Disk {
On-io-error detach;
Fencing resource-only;
}
Net {
Cram-hmac-alg "sha1 ";
Shared-secret "mydrbd ";
}

Syncer {
Rate 100 M;
}
}
5. define a resource. r0 is the resource name and can be changed by yourself:

Vim/etc/drbd. d/r0.res

Resource r0 {
Device/dev/drbd0;
Disk/dev/sda1;
Meta-disk internal;
On drbdAA {
Address 9.111.222.59: 7789;
}
On drbdBB {
Address 9.111.222.60: 7789;
}
}

6. the above files must be the same on the two nodes. Therefore, you can synchronize all the files just configured to the drbdBB node based on ssh:

7. scp-r/etc/drbd. d/r0.res global_common.conf root @ drbdBB:/etc/drbd. d/

8. initialize the defined resources on the two nodes and start the service:

Drbdadm create-md r0

Systemctl start drbd

[Root @ drbdBB drbd. d] # cat/proc/drbd
Version: 8.4.6 (api: 1/proto: 86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil @ Build64R7, 05:13:52
0: cs: Connected ro: Secondary/Secondary ds: UpToDate/UpToDate C r -----
Ns: 1600728 nr: 2048 dw: 1600636 dr: 3325 al: 37 bm: 0 lo: 0 pe: 0 ua: 0 ap: 0 ep: 1 wo: f oos: 0

9. Next we need to set one of the nodes as Primary, and execute the following command on the node to be set as Primary. here we operate on drbdAA

Drbdadm primary -- force r0

[Root @ drbdAA yum. repos. d] # cat/proc/drbd
Version: 8.4.6 (api: 1/proto: 86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil @ Build64R7, 05:13:52
0: cs: Connected ro: Primary/Secondary ds: UpToDate/UpToDate C r -----
Ns: 2048 nr: 1600728 dw: 1606877 dr: 3714 al: 2 bm: 0 lo: 0 pe: 0 ua: 0 ap: 0 ep: 1 wo: f oos: 0

10. create a file system and mount it:

The file system can only be mounted on the Primary node. Therefore, you can format the drbd device only after the master node is set. here, you can operate on drbdAA.

Mkfs. ext4/dev/drbd0 format block storage

Mkdir/mydata // Create a mount point

Mount/dev/drbd0/mydata/

11. switch between Primary and Secondary nodes:

For the drbd service of the Primary/Secondary model, only one node can be set to Primary at a time point. Therefore, you must switch the roles of the two nodes, only after the original Primary node is set to Secondary can the original Secondary node be set to Primary.

On coro1:

1 umount/mydata/2 drbdadm secondary web // changed to secondary node

On coro2:

1 drbdadm primary web // change to primary node 2 cat/proc/drbd3 mkdir/mydata // Create mount point 4 mount/dev/drbd0/mydata/5 ls/mydata/

As you can see, coro2 has become a Primary, and the directories created on coro1 can also be accessed. After the test is completed, coro1 is changed to Primary and mounted again.

 
Related Article

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.