DRBD creation implementation, steps, and precautions

Source: Internet
Author: User
Tags flushes

DRBD creation implementation, steps, and precautions
DRBD implements real-time image of block device data through the network
You don't need it anymore.
Http://blog.csdn.net/liuyunfengheda/article/details/6460814
Problems occurred during creation:
First, use this command during creation.
Drbdadm-c/usr/local/drbd/etc/drbd. d/drbd. res create-md drbd needs to use-c to specify the path of a valid configuration file. The final parameter must be the same as the name of the configuration file.
Prompt message for successful creation.

In short, this-c seems to be very embarrassing, isn't it? You can't solve it, as long as you add-c <path of the specified file>, it's OK. It's hard to try again and again <------~ _~ ----->

The M1 end is configured as the master port Primary.

M2 is the Auxiliary port used to synchronize the content at M1.


This error occurs when all files are created:

The reason is: the M2 end is Secondary, and the read-only format is used for read/write. So, only the M1 end of Primary does not have this situation, or it is also possible to change it to Primary.


Overall framework:
M1 and M2 are different disks first, that is, they use not the same disk for data processing. Besides, if you use a disk, it will not succeed, therefore, different disks are used, and the sizes should be the same.
Another problem is that the second time, the Secondary of M2 is not allowed to be initialized in advance, and the file system is initialized after the creation is complete.
Remember:
The two computers use different Block devices, and the names of the created drbd are the same.
After drbd is created, you can use drbd-overview or cat/proc/drbd to view the content of the created drbd.
If no resource error occurs, you must use-c to specify the path of the configuration file during the command line creation process, the default value is from/usr/local/drbd /*. *. If this device exists, you do not need to use-c to specify
You can run the whereis command to view the installation path of drbd.
Whereis drbd




Cat/usr/local/etc/drbd. d/drbd. res # The name of this configuration file is consistent with that of resource.
Resource drbd {# define the resource Name of a drbd
On M1.mod _ 1 {# host description starts with on, followed by host name
Device/dev/drbd0; # name of the drbd device. Note that the names of the other devices are the same. In this case, the two hosts must use two devices of the same size but different sizes, the name must be consistent, and the naming rule is drbdN. N indicates the next device number, and the master device number is always 147, because this is two different devices, the same name is correct.
Disk/dev/mapper/VolGroup-lv_drbd; # drbd0 is created using logical volumes/dev/mapper/VolGroup-lv_drbd
Address 172.16.100.210: 7789; # Set the DRBD listening address and port
Meta-disk internal; # Set the metadata disk to the internal Mode
}
On M2.mod _ 2 {
Device/dev/drbd0;
Disk/dev/mapper/VolGroup-lv_drbd; # Two are different devices
Address 172.16.100.211: 7789;
Meta-disk internal;
}
}
There is a question in this place. Do you say that the disk of M1 and M2 is written in one? --------> The names to be resolved are the same, which has no effect because different devices use different buckets. If the disk names of the two devices are different, an incorrect synchronization error occurs.

Configure command line -- http://blog.csdn.net/deansrk/article/details/6780650 configure ------------------------------------------------------------------------------------------------------------
First, drbd is a storage and replication solution for the content of Image Block devices between two servers <I use X86>.
First, two devices and available disk space are required. <logical volumes, disks, and arrays can be used.>
Drbd8.4.3 is used, and two X86 machines are used.
DRBD is a real-time image of block device data through TCP/IP protocol.
Installation Configuration:
Run configure:./configure
Make
Make install
Ldconfig // load the dynamic library
Insmod lru_cache.ko
Insmod drbd. ko
| ***** You also need to configure the local hosts file: * ****** >>>>>>>> not sure whether to configure <
|
| Vi/etc/hosts
| 127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4
|: 1 localhost. localdomain localhost6 localhost6.localdomain6
| [Mon]
| 10.10.101.102 mon_0
| 10.10.101.103 mon_1
| // Determine the correspondence between the local IP address and the Host Name
| [Osd]
| 10.10.66.150 node_0
| 10.10.66.151 node_1
| 10.10.66.152 node_2
--------------------------------------------------
Two modules are required to install lrc_cache.ko drbd. ko in sequence. First install the first one.
The command line mainly uses drbdadm


Start configuration file: There are two main configuration files: global_comman.conf and drbd. res.
The path of the two documents is/usr/local/etc/drbd. d /*.*
First, the configuration document content is as follows:
Cat/usr/local/etc/drbd. d/global_common.conf
Global {
Usage-count no; # This configuration is "yes" or "no" does not affect the performance, but only transmits information.
}
Common {
Protocol C; # protocol C --> synchronous replication protocol
Disk {
On-io-error detach; # configure the I/O error handling policy to separate
No-disk-flushes;
No-md-flushes;
}
Net {
# Allow-two-primaries yes; # in dual-master mode, you need to add the option to it, that is, the two devices are both active devices.
Cram-hmac-alg "sha1"; # Set the encryption algorithm
Shared-secret "allendrbd"; # Set the encryption key
Sndbuf-size 512 k;
Max-buffers 8000;
Unplug-watermark 1024;
Max-epoch-size 8000;

}
Syncer {
Rate 24 M; # Set the network rate for master-slave node synchronization
Al-extents 517 ;#
}
}


Cat/usr/local/drbd/etc/drbd. d/drbd. res # the configuration file does not exist at the beginning, so you can directly create vi and add the content directly. Also, copy the configuration file to/etc, and then change the suffix to. conf to save
# The Troubles of specifying the-c directory in subsequent operations
/***
-C, -- config-filefile
Specifies the configuration file drbdadm will use. If this
Parameter is not specified, drbdadm will look
/Etc/drbd-83.conf,/etc/drbd-08.conf and/etc/drbd. conf.
***/
Cat/usr/local/etc/drbd. d/drbd. res # The name of this configuration file is consistent with that of resource.
Resource drbd {# define the resource Name of a drbd
On M1.mod _ 1 {# host description starts with on, followed by host name
Device/dev/drbd0; # name of the drbd device. Note that the names of the other devices are the same. In this case, the two hosts must use two devices of the same size but different sizes, the name must be consistent, and the naming rule is drbdN. N indicates the next device number, and the master device number is always 147, because this is two different devices, the same name is correct.
Disk/dev/mapper/VolGroup-lv_drbd; # drbd0 is created using logical volumes/dev/mapper/VolGroup-lv_drbd
Address 172.16.100.210: 7789; # Set the DRBD listening address and port
Meta-disk internal; # Set the metadata disk to the internal Mode
}
On M2.mod _ 2 {
Device/dev/drbd0;
Disk/dev/mapper/VolGroup-lv_drbd; # Two are different devices, the names can be inconsistent, no problem
Address 172.16.100.211: 7789;
Meta-disk internal;
}
}
------------------------------------------- The configuration file indicates that the configuration can be performed when the names of devices in the two hosts are the same. Generally, the configuration documents above are used, the corresponding configuration file is r0.res --------------------------------------
Resource r0 {
Device/dev/drbd1;
Disk/dev/sda7;
Meta-disk internal;
On alice {
Address 10.1.1.31: 7789;
}
On bob {
Address 10.1.1.32: 7789;
}
}


-------------------------------------------------------------------------------- The configuration file is a one-time preparation of two drbd devices to prepare ----------------------------------------------------------------------------------------------------------------------------------------------------


Resource drbd {# define the resource Name of a drbd instance. The configuration method is the same when two devices are configured at the same time, except that the configuration file drbd is used. res changed. The rest are the same.


Volume 0 {# host description starts with on, followed by host name
Device/dev/drbd1; # name of the drbd device
Disk/dev/mapper/VolGroup00-lv_01; # The drbd0 uses the logical volume/dev/mapper/VolGroup-lv_drbd
Meta-disk internal; # Set the metadata disk to the internal Mode
}
Volume 1 {
Device/dev/drbd2;
Disk/dev/mapper/VolGroup00-lv_02; // In this case, the size of the mirrored device is the same as that of the previous logical volume to make the volume group larger.
Meta-disk internal;
}
On mon_0 {# host description starts with on, followed by host name
Address 10.10.101.102: 7789; # Set the DRBD listening address and port
}
On mon_1 {
Address 10.101.103: 7789;
}
}




Note: The above M1.mod _ 1 and M2.mod _ 2 are the names of your own virtual machines. They vary with host names.
All the operations above, including the following operations, must be performed on both virtual machines.
Now, after all the preparations are completed, we will start configuring the command line:
1> initialize the meta Partition
Drbdadm create-md drbd
Cat/proc/drbd // view the synchronization status
2> Start the drbd Service
/Etc/init. d/drbd start // start both hosts. 3> initialize device synchronization and establish the master node. Assume that the M1 side is set to the master node. This operation is required for both hosts, otherwise, the device cannot be found, or the device is unknown.
Drbdadm -- overwrite-data-of-peer primary drbd or drbdadm primary -- force drbd

Note: by default, the device only has one master and one operation, so you can perform only one operation.
Cat/proc/drbd // check the status of drbd again
In this case, the drbd0 device file will appear in the/dev/directory, and you can use it normally.
4> mount a drbd Device
Mkfs. ext4/dev/drbd0
Sync // synchronize some metadata and data block data
Mount/dev/drbd0/mnt
Df-h
----------------------- View the data synchronization process-<only detect synchronization> -------------------------------------------------------
Copy some data from one side and view it from the other.
Umount/mnt
Drbdadm secondary drbd <-- preferred ----> or drbdadm dowm drbd
At this time, the M1 end is already the same, and then converted to another M2 machine, M2 for Master Settings
The command is the same as the previous one.
Drbdadm -- overwrite-data-of-peer primary drbd
Mount/dev/drbd0/mnt
Df-h
The content of the two should be consistent.


------------------------------ Delete operation --------------------------
Drbdadm down drbd
Drbdadm wipe-md drbd // Delete drbd
---------------------------- Auto start process -------------------------
The two modules lru_cache.ko drbd. ko will be loaded first.
Run/etc/init. d/drbd start ------------------------------------- both hosts simultaneously execute the preceding command






You can use drbdadm connect all to view the status of the device connection, such as the transmission rate. This command is the solution when a connection problem occurs: PS: the connection command between nodes drbdadm connect | disconnect all

----------------------------------------- Errors occurred during use and its solution: http://blog.chinaunix.net/uid-24020646-id-2942207.html http://bbs.linuxtone.org/thread-24207-1-1.html
1> when an error occurs during the creation of drbdadm create-md drbd-name, the cause is that the original device may not have been initialized, and there are some metadata related to the previous
Solution: dd if =/dev/zero of =/dev/sda bs = 1 M count = 1024 for liquidation
2> an error occurs during the mount operation because the master device is not specified or the device is not initialized.
Solution: drbdadm -- overwrite-data-of-peer primary drbd // synchronization occurs at this location when two devices are created, wait until the synchronization is complete before mounting and using



If you set the primary device for one device, all devices will become the primary device.
Mkfs. ext4/dev/drbd-name
3> an error occurs when drbdadm create-md all is re-created. This is similar to the above. We should perform liquidation and then create the file system mkfs. ext4/dev/sda
4> when split-brain occurs, the primary-secondary relationship between the two devices is reversed. After split-brain occurs, the data between the two nodes is not synchronized and the master-slave relationship is invalid. You need to follow the steps below to fix the problem.
Solution: 1. Run the following command on the slave node:
[Root @ www ~] # Drbdadm secondary drbd-name
[Root @ www ~] # Drbdadm--discard-my-data connect drbd-name
2. on the master node, check the status through cat/proc/drbd. If it is not in the WFConnection status, you need to manually connect:
[Root @ www ~] # Drbdadm connect drbd-name
5> when a connection similar to a connection failure occurs on one side, In this case, we can use drbdadm connect r0 Or drbdadm disconnect | connect r0
---------------------------------------- Precautions ----------------------------------------------------------------------------------------------------------
1. It is recommended that the two partitions synchronized by the master and slave servers be of the same size (there is no definite statement on whether the partition size must be the same on the Internet)


2. It takes some time to start disk synchronization between the two nodes. Do not restart the disk before the synchronization is complete. Otherwise, the disk will be synchronized again.


3. You must switch the current node to the master node before mounting.


4. Only one of the two nodes is in primary state at the same time, and the other is in secondary state.


5. a server in the slave node status cannot load drbd Block devices.


6. Uninstall the master node before switching from the slave node.


7. Before switching one server to the master node, make sure that the other server has been switched to the slave node.


--------------------------------------------- Additional command ------------------------------------------------------------------------------------
Temporary synchronization rate Configuration:
Drbdadm disk-options-resync-rate = 100 M drbd You only need to issue commands on one node.
To start the synchronization rate in the configuration file again, run the following command:
Drbdadm adjust drbd

--------------------------------------------- Link Status Success ------------------------------------------------------------------------------------
Cat/proc/drbd

Note: The ns nr dw dr module numbers are the module numbers for network transmission, network receiving, disk writing, and disk reading.
It is helpful to see the status of cs: connected indicates that everything is normal.



------------------------------------------ Precautions and additional extensions --------------------------------------------------------------------------------------
The path of global_common.conf and drbd. res is/usr/local/etc/init. d /.
Create drbd first, and start it with/etc/init. d/drbd start


1} the disk name configured by disk can be different and stored with the smallest device size, that is, if one is 10 GB and the other is 2 GB, the size of the created device is only 2 GB.
2} in dual-master mode, synchronization does not occur on the other side of the device during one-side replication (in the case of simultaneous mounting), provided that the background is actually in sync, data Synchronization may occur when mounting again.


1> Installation Method
This implementation of the drbd installation is carried out in drbd.8.4.3 <this version has a problem, that is, to create a drbd and watch it on the other side, the logical volume previously created on the master device does not exist. So improved to drbd-8.4.5>
There is an executable configure file under this path. If it cannot be executed, add an executable permission chmod + x configure
Run configure./configure
Make
Make install
Ldconfig // load the dynamic library
Insmod lru_cache.ko // This module is used to monitor the synchronization progress of the device.
Insmod drbd. ko


10.10.66.72
10.10.67.74


Code 11 indicates that the device is being used.


Code17 indicates that the primary device is set incorrectly.


When a device is in use, let's first check whether there are logical volumes and physical volumes using this device. If so, we want to change its properties, as shown in figure
Lvchange, vgchange-**


Ls/dev/class/block/drbd */dev/view device property options
Mdadm-As indicates restarting the disk array.


Lsscsi

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.