Before configuring drbd, let's take a look at the basic knowledge of drbd. DistributedReplicatedBlockDevice (DRBD) is a software-implemented, non-shared, and storage replication solution for image block device content between servers. Data Image: real-time, transparent, and synchronized (all servers...
Before configuring drbd, let's take a look at the basic knowledge of drbd.
Distributed Replicated Block Device (DRBD) is a software-implemented, non-shared, storage and replication solution for image Block Device content between servers. Data Image: real-time, transparent, synchronous (returned after all servers are successful), asynchronous (returned after the local server is successful)
The core function of DBRD is implemented through the Linux kernel, which is closest to the system's IO stack. However, it cannot add upper-layer functions like detecting the crash of the EXT3 file system.
DBRD is located below the file system, which is closer to the operating system kernel and IO stack than the file system.
Tools used by drbd:
Drbdadm: an advanced management tool that manages/etc/drbd. conf and sends commands to drbdsetup and drbdmeta,
Drbdsetup: configure the DRBD module loaded into the kernel, which is rarely used directly at ordinary times.
Drbdmeta: manages the META data structure, which is rarely used directly at ordinary times.
In DRBD, resources are all aspects of a replicated storage device. Including the resource name, DRBD device (/dev/drbdm, Here m is the minimum device number, the maximum size can be 147), disk configuration (so that local data can be used for DRBD), network configuration (communication with the other party)
Each resource has a role, which is Primary or Secondary"
DRBD devices of the primary role can read and write data without restrictions, such as creating and ing file systems, raw or direct IO access to block devices.
The DRBD device of the standby role accepts all modifications from the other party, but cannot be read or written by the application, or even read-only. The role can be changed.
Okay, I don't want to introduce drbd. now we have a drbd cluster experiment.
1) There are two test nodes, node1.a.org and node2.a.org, with IP addresses 192.168.0.110 and 192.168.0.120 respectively.
Node1 ip: 192.168.0.110 node2: 192.168.0.120
1. preparations
Set host names and corresponding IP address resolution services for two nodes
Vim/etc/hosts
192.168.0.5 node1.a.org node1
192.168.0.6 node2.a.org node2
To keep the host name as above after the system is restarted, you must execute the following commands on each node:
Node1:
# Check hostname
# Hostname node1.a.org
Node2:
# Hostname node2.a.org
2. install the software package
Download the software package: http://mirrors.sohu.com/centos/5.6/extras/ I #/rpms /.
After the download is complete, install it directly:
# Yum-y -- nogpgcheck localinstall *. rpm
3. configure drbd
1) copy the sample configuration file as the configuration file to be used:
# Cp/usr/share/doc/drbd83-8.3.8/drbd. conf/etc
2) configure/etc/drbd. d/global-common.conf to open the content in the edit
Global {
Usage-count no;
}
Common {
Protocol C;
Handlers {
}
Startup {
Wfc-timeout 120;
Degr-wfc-timeout 120;
}
Disk {
On-io-error detach;
Fencing resource-only;
}
Net {
Cram-hmac-alg "sha1 ";
Shared-secret "mydrbdlab ";
}
Syncer {
Rate 100 M;
}
3. define a resource/etc/drbd. d/web. res. the content is as follows:
[Root @ node1 ~] # Vim/etc/drbd/web. res
Resource web {
On node1.a.org {
Device/dev/drbd0;
Disk/dev/sda5;
Address 192.168.0.5: 7789;
Meta-disk internal;
}
On node2.a.org {
Device/dev/drbd0;
Disk/dev/sda5;
Address 192.168.0.6: 7789;
Meta-disk internal;
}
}
4. initialize the defined resources on the two nodes and start the service:
[Root @ node1 ~] # Scp-r/etc/drbd. conf/etc/drbd. d node2:/etc/
1) initialize the resource and run the following commands on Node1 and node2:
[Root @ node1 ~] # Drbdadm create-md web
[Root @ node2 ~] # Drbdadm create-md web
2) start the service and run the following commands on Node1 and node2:
[Root @ node1 ~] #/Etc/init. d/drbd start
[Root @ node2 ~] #/Etc/init. d/drbd start
3) view the startup status:
[Root @ node1 ~] # Cat/proc/drbd
Version: 8.3.8 (api: 88/proto: 86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
0: cs: Connected ro: Secondary/Secondary ds: 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: B oos: 505964
You can also run the drbd-overview command to view the details:
[Root @ node1 ~] # Drbd-overview
0: web Connected Secondary/Secondary Inconsistent/Inconsistent C r ----
Set one node to Primary. Run the following command on the node to be set as Primary:
# Drbdadm -- overwrite-data-of-peer primary web
Check the status again and you will find that the data synchronization process has started:
[Root @ node1 ~] # Drbd-overview
0: web SyncSource Primary/Secondary UpToDate/Inconsistent C r ----
[============>...] Sync 'Ed: 66.2% (172140/505964) K delay_probe: 35
After the data synchronization is complete, check the status again. you can find that the node has the real-time status card and the node has the primary and secondary nodes:
[Root @ node1 ~] # Drbd-overview
0: web Connected Primary/Secondary UpToDate/UpToDate C r ----
After the data synchronization is complete, check the status again. you can find that the node has the real-time status card and the node has the primary and secondary nodes:
[Root @ node1 ~] # Drbd-overview
0: web Connected Primary/Secondary UpToDate/UpToDate C r ----
Dynamic Investigation and Handling of synchronization between the two parties
# Watch-nl 'cat/proc/drbd'
5. create a file system
The file system can only be mounted on the Primary node. Therefore, the drbd device can be formatted only after the master node is set:
The master node does not need to format the disk times.
[Root @ node1 ~] # Mkfs-t ext3-l drdbweb/dev/drbd0 or # mke2fs-j-l drbd/dev/drbd0
# Mkdir/web create a directory to put web pages
# Mount/dev/drbd0/web mount the disk to the directory we created above
# Echo "welcome"> index.html
6. switch between Primary and Secondary nodes.
...................
Node1: view the specified resource
I love linux
Master-slave switchover
To uninstall the master, you must first set the master as the slave in the master
# Umount/web
# Set drbdadm secondary web to slave on the current node
# Drbdadm role web view master/slave status
Switch to node2
Create a mounted Directory
# Mkdir/web
Create a master node
# Drbdadm primary web
View the status of the node you created
# Drbd-overview
Attach disk
# Mount/dev/drbd0/web
# Ls
View an index.html document
Author: "Birds of the Earth"