Svolence

How to install DRBD & config on ubuntu

Installation

CentOS

1
yum install drbd kmod-drbd

Ubuntu

1
2
3
4
sudo add-apt-repository ppa:linbit/linbit-drbd9-stack
sudo apt-get update
sudo apt-get install drbd-utils python-drbdmanage drbd-dkms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
root@drbd01:~# lvdisplay
--- Logical volume ---
LV Path /dev/drbdpool/.drbdctrl_0
LV Name .drbdctrl_0
VG Name drbdpool
LV UUID Zl0wLm-MYXP-8NBJ-V079-nrP4-1gOZ-BWexED
LV Write Access read/write
LV Creation host, time test-VirtualBox, 2016-10-10 10:46:51 +0800
LV Status available
# open 0
LV Size 4.00 MiB
Current LE 1
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/drbdpool/.drbdctrl_1
LV Name .drbdctrl_1
VG Name drbdpool
LV UUID kp2NGj-NF77-R7xj-Zzcw-iGFM-Kean-J5ipwm
LV Write Access read/write
LV Creation host, time test-VirtualBox, 2016-10-10 10:46:51 +0800
LV Status available
# open 0
LV Size 4.00 MiB
Current LE 1
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
root@drbd01:~# lvmdiskscan
/dev/ram0 [ 64.00 MiB]
/dev/drbd0 [ 18.00 GiB] LVM physical volume
/dev/drbdpool/.drbdctrl_0 [ 4.00 MiB]
/dev/ram1 [ 64.00 MiB]
/dev/sda1 [ 13.97 GiB]
/dev/drbdpool/.drbdctrl_1 [ 4.00 MiB]
/dev/ram2 [ 64.00 MiB]
/dev/ram3 [ 64.00 MiB]
/dev/ram4 [ 64.00 MiB]
/dev/ram5 [ 64.00 MiB]
/dev/sda5 [ 10.00 GiB]
/dev/ram6 [ 64.00 MiB]
/dev/sda6 [ 8.00 GiB] LVM physical volume
/dev/ram7 [ 64.00 MiB]
Found duplicate PV U3YUwIvbb9Jbmcg0E297gMnUd8E6HANF: using /dev/drbd0 not /dev/sda7
Using duplicate PV /dev/drbd0 from subsystem DRBD, ignoring /dev/sda7
/dev/sda7 [ 18.00 GiB]
/dev/ram8 [ 64.00 MiB]
/dev/sda8 [ 10.00 GiB]
/dev/ram9 [ 64.00 MiB]
/dev/ram10 [ 64.00 MiB]
/dev/ram11 [ 64.00 MiB]
/dev/ram12 [ 64.00 MiB]
/dev/ram13 [ 64.00 MiB]
/dev/ram14 [ 64.00 MiB]
/dev/ram15 [ 64.00 MiB]
0 disks
22 partitions
0 LVM physical volume whole disks
2 LVM physical volumes

如未激活,需要激活逻辑卷:vgchange -ay /dev/drbdpool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 29296639 29294592 14G 83 Linux
/dev/sda2 29296640 125829119 96532480 46G 5 Extended
/dev/sda5 29298688 50270207 20971520 10G 83 Linux
/dev/sda6 50272256 67049471 16777216 8G 8e Linux LVM
/dev/sda7 67051520 104800255 37748736 18G 8e Linux LVM
/dev/sda8 104802304 125773823 20971520 10G 83 Linux
root@test-VirtualBox:/home/test# pvscan
No matching physical volumes found
root@test-VirtualBox:/home/test# pvcreate /dev/sda6 /dev/sda7
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
root@test-VirtualBox:/home/test# pvscan
PV /dev/sda6 lvm2 [8.00 GiB]
PV /dev/sda7 lvm2 [18.00 GiB]
Total: 2 [26.00 GiB] / in use: 0 [0 ] / in no VG: 2 [26.00 GiB]
root@test-VirtualBox:/home/test#
sudo partprobe
root@test-VirtualBox:/home/test# drbdmanage add-node bravo 10.96.23.121
Operation completed successfully
Operation completed successfully
ssh: connect to host 10.96.23.121 port 22: Connection timed out
Join command for node bravo:
drbdmanage join -p 6999 10.96.23.121 1 test-VirtualBox 10.96.23.120 0 0vzY5okIlM4HYqLUZ6jr
root@test-VirtualBox:/home/test#
# 指定单个node
root@test-VirtualBox:/home/test# drbdmanage modify-config --node test-VirtualBox
'r0' not defined in your config
Make sure the node name (node1 and node2) match the output of 'uname -n'
on the two nodes.
root@drbd01:/home/test# drbdadm create-md r0
open(/dev/sda) failed: Device or resource busy
Exclusive open failed. Do it anyways?
[need to type 'yes' to confirm] no
open(/dev/sda) failed: Device or resource busy
Exclusive open failed. Do it anyways?
[need to type 'yes' to confirm] ^C
root@drbd01:/etc/drbd.d# drbdadm create-md r0
--== Thank you for participating in the global usage survey ==--
The server's response is:
md_offset 19327348736
al_offset 19327315968
bm_offset 19326726144
Found LVM2 physical volume signature
18870272 kB data area apparently used
18873756 kB left usable by current configuration
Even though it looks like this would place the new meta data into
unused space, you still need to confirm, as this is only a guess.
Do you want to proceed?
[need to type 'yes' to confirm]

r0: State change failed: (-2) Need access to UpToDate data

unknown filesystem type ‘LVM2_member’

No matching physical volumes found

vgcreate Can’t open /dev/sda5 exclusively. Mounted filesystem?

/dev/sda5: device contains a valid ‘ext4’ signature; it is strongly recommended to wipe the device

mount: /dev/drbd0 is write-protected, mounting read-only


在硬盘分区,创建LVM的时候,花费了将近我一天的时候,才解决各种奇怪问题,事后发现我遇到的问题

和这个很相似,配置之前一定要先看一遍这篇文章

1
2
3
4
5
6
7
8
9
Oct 12 17:54:35 drbd2 kernel: [17169.969578] drbd r0: Auto-promote failed: Multiple primaries not allowed by config
Oct 12 17:55:03 drbd2 kernel: [17197.465542] drbd r0 drbd1: PingAck did not arrive in time.
Oct 12 17:55:03 drbd2 kernel: [17197.465560] drbd r0 drbd1: conn( Connected -> NetworkFailure ) peer( Primary -> Unknown )
Oct 12 17:55:03 drbd2 kernel: [17197.465563] drbd r0/0 drbd0: disk( UpToDate -> Consistent )
Oct 12 17:55:03 drbd2 kernel: [17197.465565] drbd r0/0 drbd0 drbd1: pdsk( UpToDate -> DUnknown ) repl( Established -> Off )
Oct 12 17:55:03 drbd2 kernel: [17197.465590] drbd r0 drbd1: ack_receiver terminated
Oct 12 17:55:03 drbd2 kernel: [17197.465592] drbd r0 drbd1: Terminating ack_recv thread
Oct 12 17:55:03 drbd2 kernel: [17197.676657] drbd r0: Preparing cluster-wide state change 1814948363 (1->-1 0/0)
Oct 12 17:55:03 drbd2 kernel: [17197.676661] drbd r0: Committing cluster-wide state change 1814948363 (0ms)

出现上述错误是因为:mount 之前需要将分区格式化一下

1
sudo mkfs.ext4 /dev/drbd0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@drbd2:/etc/drbd.d# drbdadm create-md r0
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
root@drbd2:/etc/drbd.d#
[ 7438.167130] drbd r0/0 drbd0: Split-Brain detected but unresolved, dropping connection!
[ 7438.167139] drbd r0/0 drbd0 drbd1: helper command: /sbin/drbdadm split-brain
[ 7438.168233] drbd r0/0 drbd0 drbd1: helper command: /sbin/drbdadm split-brain exit code 0 (0x0)
[ 7438.168356] drbd r0 drbd1: conn( Connected -> Disconnecting ) peer( Primary -> Unknown )
[ 7438.168373] drbd r0 drbd1: error receiving P_STATE, e: -5 l: 0!
[ 7438.168392] drbd r0 drbd1: ack_receiver terminated
[ 7438.168393] drbd r0 drbd1: Terminating ack_recv thread
[ 7438.187019] drbd r0 drbd1: Connection closed
[ 7438.187053] drbd r0 drbd1: conn( Disconnecting -> StandAlone )
[ 7438.187067] drbd r0 drbd1: Terminating receiver thread

脑裂故障修复:
脑裂故障修复

修复日志:
修复日志

参考链接: