DRBD Official tar Package: http://oss.linbit.com/drbd/
Environment Introduction:
System version: CentOS 6.4 (64-bit)
Kernel version 2.6.32-358.el6.x86_64
Software version: drbd-8.4.3.tar.gz
Main: 10.0.0.1 from: 10.0.0.2
The hosts on both machines need to be modified:
[Email protected] ~]# vim/etc/hosts
10.0.0.1 Node1
10.0.0.2 Node2
Two dual-server network cards, where 10.0.0.x network card for the transmission of DRBD data, two servers directly connected to the network, used for transmission of the heartbeat line.
In order to facilitate the experiment, the two machines each add a 15G hard disk, used to do the DRBD storage disk (two machines need this operation)
To partition a newly added hard disk:
#fdisk/DEV/SDB//prepare to create a partition for SDB
The number of cylinders for this disk was set to 20805.
There is nothing wrong with the, 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 the other OSs
(e.g., DOS fdisk, OS/2 fdisk)
Command (M for help): N//Type n indicates the partition to be established
Command Action
E Extended
P primary partition (1-4)
P//Type p to establish primary partition
Partition number (1-4): 1//Type 1 for this main partition designator
First cylinder (1-20805, default 1)://Start magnetic column value, press ENTER
Using Default value 1
Last cylinder or +size or +sizem or +sizek (1-20805, default 20805)://End Magnetic column value, press ENTER
Using Default Value 20805
Command (M for help): w//Type W for OK to perform just the setting
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks.
[[email protected] ~]# partprobe//Make the partition table change take effect
Partition to format:
[Email protected] ~]# MKFS.EXT4/DEV/SDB1
Compile and install drbd-8.4.3:
[Email protected] soft]# tar zxf drbd-8.4.3.tar.gz
[Email protected] soft]# CD drbd-8.4.3
[Email protected] soft]# mkdir/usr/local/drbd/
[[email protected] drbd-8.4.3]#./configure--PREFIX=/USR/LOCAL/DRBD--with-km Note:--with-km is enabling kernel modules
[[email protected] ~]# make kdir=/usr/src/kernels/2.6.32-358.el6.x86_64/note the path of Kdir (this kernel source path needs to be modified according to its own system)
[[email protected] drbd-8.4.3]# make install
[Email protected] ~]# mkdir-p/USR/LOCAL/DRBD/VAR/RUN/DRBD
Configuring startup scripts and booting from
[Email protected] ~]# cp/usr/local/drbd/etc/rc.d/init.d/drbd/etc/rc.d/init.d/
[Email protected] ~]# chkconfig--add DRBD
[[email protected] ~]# chkconfig DRBD on
Copy the DRBD module to the kernel and load the DRBD module.
[email protected] drbd]# CP drbd.ko/lib/modules/2.6.32-358.el6.x86_64/kernel/lib/
[Email protected] drbd]# modprobe DRBD
To see if the module was loaded successfully
[[email protected] DRBD] #lsmod |grep DRBD
DRBD 325626 3
LIBCRC32C 1246 1 DRBD
Don't forget to also do the above steps on the Node2 ****************
Configure drbd************************************
[Email protected] ~]# cd/usr/local/drbd/etc/
[email protected] etc]# cat drbd.conf
# can find an example in/usr/share/doc/drbd.../drbd.conf.example
Include "drbd.d/global_common.conf";
Include "Drbd.d/*.res";
This shows that the master configuration file already contains the global configuration file and the file ending with. Res in the DRBD directory
Modify the global configuration file: * * * * The following is the configuration used by the author, in order to efficiently prepare the success, please ensure that the file configuration consistent ********
[Email protected] etc]# CD drbd.d/
[email protected] drbd.d]# cat global_common.conf
Global {
Usage-count No; #是否参加DRBD使用者统计, the default is Yes
}
Common {
syncer {rate 200M;} Maximum network rate, in bytes, for #设置主, standby node synchronization
Protocol C; #使用DRBD的第三种同步协议, indicates that the write is complete after receiving a write acknowledgement from the remote host
Handlers {
Pri-on-incon-degr "echo o >/proc/sysrq-trigger; Halt-f ";
PRI-LOST-AFTER-SB "echo o >/proc/sysrq-trigger; Halt-f ";
Local-io-error "echo o >/proc/sysrq-trigger; Halt-f ";
#fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
}
NET {
Cram-hmac-alg "SHA1";
Shared-secret "Mysql-ha"; #DRBD the authentication method and password information used when synchronizing
}
Disk {
On-io-error detach; #配置I/O error handling policy is detached
# fencing resource-only;
}
startup {
# Wfc-timeout 120;
# Degr-wfc-timeout 120;
}
}
Modify the resource profile, the default does not have this file, need to create manually: * * * * * * The following is the configuration used by the author, in order to efficiently prepare the success, please ensure that the file configuration consistent ********
[Email protected] ~]# Vim/usr/local/drbd/etc/drbd.d/drbd.res
Resource R0 { #这个r0是定义资源的名字
On Node1 { #每个主机的说明以on开头, the following name needs to be consistent with hostname, UNAME-N, and subsequent configuration in {} is the configuration of this host
Device /dev/drbd0; #drbd设备名称
DISK/DEV/SDB1; #/dev/drbd0 uses a disk partition of SDB1
Address 10.0.0.1:7788; #设置drbd监听地址与端口
Meta-disk internal; #DRBD的元数据存放方式
}
On Node2 {
device/dev/drbd0;
DISK/DEV/SDB1;
Address 10.0.0.2:7788;
Meta-disk internal;
}
}
At this point, the configuration file for DRBD is complete! ***************************
To ensure that the configuration items are consistent, copy the two configuration files to the Node2:
[[email protected] DRBD] #scp etc/drbd.d/global_common.conf etc/drbd.d/drbd.res [email protected]:/root/
Switch to Node2 to place the configuration file in the DRBD directory:
[[Email protected] ~] #mv drbd.res global_common.conf/usr/local/drbd/etc/drbd.d/
Initializing resources on Node1
[Email protected] ~]# Drbdadm CREATE-MD r0
You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
Already in place on/dev/sdb1 at byte offset 16105058304
Does really want to overwrite the existing v08 meta-data?
[Need to type ' yes ' to confirm] Yes
Writing Meta Data ...
Initializing activity log
Not initializing bitmap
New DRBD Meta data block successfully created.
Similarly, initializing resources on Node2
[Email protected] ~]# Drbdadm CREATE-MD r0
Note: If you initialize the resource error:
Command ' Drbdmeta 0 v08/dev/sdb1 internal CREATE-MD ' terminated with exit code 40
This is because SDB1 already has the file system, already has the data to exist (before doing the following operation, please ensure that the data in the/DEV/SDB1 is backed up)
Workaround:
[[email protected] ~]# dd If=/dev/zero bs=1m count=1 OF=/DEV/SDB1 * * * Note that this is/DEV/SDB1 this hard drive, not his mount directory
Be sure to start the service at the same time on both servers:
[[Email protected] ~]# service DRBD start
Starting DRBD Resources: [
Create Res:r0
Prepare Disk:r0
Adjust Disk:r0
Adjust Net:r0
]
......
[[Email protected] ~]# service DRBD start
To view the DRBD listener port:
[Email protected] ~]# Netstat-anptul |grep 7788
TCP 0 0 10.0.0.2:50569 10.0.0.1:7788 established-
TCP 0 0 10.0.0.2:7788 10.0.0.1:39663 established-
Set the DRBD master, standby node ***************************************
Note: When you start DRBD for the first time, the two DRBD nodes are in the secondary state by default:
[[email protected] ~]# drbdadm role r0 #查看r0主, standby node command
Secondary/secondary
Since there is no primary and standby node, it is necessary to set up a master and standby node for two hosts, select the host that needs to be set as the primary node, and then execute the following command:
[Email protected] ~]# Drbdadm----Overwrite-data-of-peer primary all
After executing this command for the first time, you can use another command if you need to set which is the master node later:
Drbdadm Primary All
To view the connection status of a resource:
[Email protected] ~]# Drbdadm cstate R1
Syncsource
The resource connection state may have one of the following states:
StandAlone Independent: Network configuration is not available, resources have not been connected or managed to disconnect (using Drbdadm disconnect command), or because of authentication failure or brain crack
Disconnecting disconnect: Disconnect is only temporary and the next state is standalone independent
Unconnected floating: is the temporary state before attempting to connect, possibly the next state is wfconnection and Wfreportparams
Timeout timeout: The connection to the peer node timed out, is also a temporary state, the next state is unconected dangling
Brokerpipe: The connection to the peer node is lost, is also a temporary state, the next state is unconected floating
Networkfailure: The temporary state after the connection is pushed with the peer node, and the next state is unconected floating
ProtocolError: The temporary state after the connection is pushed with the peer node, and the next state is unconected floating
TearDown Disassembly: Temporary state, peer node closed, next state is unconected floating
Wfconnection: Waiting for network connection with peer node
Wfreportparams: A TCP connection has been established and this node waits for the first network packet from the peer node
Connected Connection: DRBD has established a connection, data mirroring is now available, node is in a normal state
Startingsyncs: Full sync, with administrator initiated just starting sync, future possible status is Syncsource or Pausedsyncs
Startingsynct: Full sync, with administrator initiated just start sync, next state is Wfsyncuuid
Wfbitmaps: Partial synchronization has just begun and the next possible status is Syncsource or Pausedsyncs
WFBITMAPT: Partial synchronization has just begun and the next possible status is Wfsyncuuid
Wfsyncuuid: Synchronization is about to start and the next possible status is Synctarget or pausedsynct
Syncsource: Synchronization is in progress with this node as the synchronization source
Synctarget: Synchronization is in progress with this node as the synchronization target
Pausedsyncs: The local node is a source of continuous synchronization, but the synchronization is currently paused, possibly because another synchronization is in progress or the synchronization is paused with the command (Drbdadm pause-sync)
PAUSEDSYNCT: The local node is the target for continuous synchronization, but the synchronization is currently paused, either because another synchronization is in progress or the synchronization is paused with the command (Drbdadm pause-sync)
Verifys: On-line device verification with local node as authentication source is executing
VERIFYT: Online device verification with local node as the target is executing
To view the command for a resource role:
[Email protected] ~]# drbdadm role R1
Primary/secondary (in front of the current node)
Parimary Master: Resources are currently dominated and may be being read or written, if not dual-master only appears on one of the two nodes
Secondary: Resources are currently ready, normal receive peer node update
Unknown Unknown: Resource roles are currently unknown, local resources do not appear in this state
To view the drive status:
[Email protected] ~]# Drbdadm dstate R1
Uptodate/uptodate
The hard disk for local and peer nodes may be one of the following states:
diskless diskless: No local block devices are assigned to DRBD for use, which means no devices are available, or manual separation using the Drbdadm command or the underlying I/O errors cause automatic separation
Attaching: Instantaneous state of reading without data
Failed failure: The local block device reports the next state of the I/O error with the next state of diskless diskless
Negotiating: Attach the instantaneous state before reading without data in the already connected DRBD settings
Inconsistent: The data is inconsistent, and a new resource is created immediately after this state occurs on two nodes (before the initial full synchronization). In addition, this state occurs on one node during synchronization (the synchronization target)
Outdated: Data resources are consistent, but obsolete
Dunknown: This state occurs when a peer node network connection is not available
Consistent: A non-connected node data is consistent, when the connection is established, it determines whether the data is uptodate or outdated
UpToDate: Consistent, up-to-date data state, which is a normal state
To view synchronization progress:
[Email protected] ~]# CAT/PROC/DRBD
version:8.4.3 (api:1/proto:86-101)
git-hash:89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-06-09 15:12:58
0:cs:connected ro:primary/secondary ds:uptodate/uptodate C r-----
ns:24 nr:16108076 dw:16108100 dr:1017 al:2 bm:960 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
"Note":
From the output of the "DS" information, the disk status is "UpToDate", indicating that data synchronization has been completed
RO is the role information, primary/secondary that the current host is the Primary master node, and the other is a secondary standby node
DS is the disk status, showing whether the data is consistent (if the display uptodate/uptodate indicates that synchronization has no latency)
NS is the packet sent by the network, calculated in K-byte
DW is disk write information
Dr is disk read information
The last step, mount the DRBD0 device **************************
Attention:
Before mounting the DRBD partition, you first need to confirm that the DRBD partition of the current host is the primary state and can be queried from the "/CAT/PROC/DRBD" command
[Email protected] ~]# CAT/PROC/DRBD |grep ro
version:8.4.3 (api:1/proto:86-101)
git-hash:89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2014-06-09 15:12:58
0:cs:connected ro:primary/secondary ds:uptodate/uptodate C r-----
Host in the master state to be mounted * * * *
Format file system (file format selected according to your system environment)
[Email protected] ~]# mkfs.ext4/dev/drbd0
Mount this file system
[Email protected] ~]# Mkdir/data
[Email protected] ~]# mount/dev/drbd0/data/
[Email protected] ~]# df-th
File system type capacity has been used with available percent mount points
/dev/sda3 ext4 11G 3.5G 6.9G 34%/
Tmpfs tmpfs 499M 0 499M 0%/dev/shm
/DEV/SDA1 ext4 2.0G 68M 1.9G 4%/tmp
/dev/drbd0 ext4 15G 166M 14G 2%/data
At this point, the configuration of DRBD is complete! ***************************
Test Validation ***********************************************
Proposition: Create a test file in the mounted data directory, then unload the Mount directory, and then switch the primary and standby node to see if the test file you just created is still present on the alternate node
[Email protected] ~]# touch/data/test
[Email protected] ~]# umount/data/
Then turn Node1 into an alternate node:
[Email protected] ~]# Drbdadm secondary r0
[Email protected] ~]# drbdadm role R1
Secondary/secondary
Before DRBD performs a role switch, it needs to execute the umount command on the master node, remove the mount to the DRBD device, and then modify the role of DRBD to "Primary" on another host, and then mount
Then operate on the Node2:
[Email protected] ~]# Drbdadm Primary All
[Email protected] ~]# Mount/dev/drbd0/data
To see if a file exists:
[Email protected] ~]# ls/data/
Lost+found Test
This indicates that the DRBD configuration was successful!!! **************************
This article is from the "Fate" blog, make sure to keep this source http://czybl.blog.51cto.com/4283444/1426055