DRBD
Создаем раздел на диске, но не форматируем его
[root@server1 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
[root@server1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xfc03d3bb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221):
Using default value 5221
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@server1 ~]# ssh server2
Last login: Sat Feb 1 15:04:07 2014 from 192.168.1.5
[root@server2 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf1c9110b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221):
Using default value 5221
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
CTRL + D
================
Инсталлируем DRBD
[root@server1 ~]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@server1 ~]# ssh server2 rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[root@server1 ~]# chkconfig --level 345 drbd on && ssh server2 chkconfig --level 345 drbd on
-- Без следующего модуля были сообщения:
-- На консоли: Starting DRBD resources: Can not load the drbd module.
-- В логах: modprobe: FATAL: Module drbd not found
[root@server1 ~]# yum install -y kmod-drbd84 && ssh server2 yum install -y kmod-drbd84
[root@server1 ~]# sudo rpm -qa --qf "%{name}-%{version}-%{release}.%{arch}\n" | grep drbd
drbd84-utils-8.4.4-2.el6.elrepo.x86_64
[root@server1 ~]# vi /etc/drbd.d/global_common.conf
startup {
wfc-timeout 60;
}
syncer {
rate 100M;
}
[root@server1 ~]# scp /etc/drbd.d/global_common.conf server2:/etc/drbd.d/global_common.conf
[root@server1 ~]# vi /etc/drbd.d/r0.res
resource r0 {
on server1.localdomain {
device /dev/drbd0;
disk /dev/sdb;
# disk /dev/sdb1;
address 10.0.0.1:7788;
meta-disk internal;
}
on server2.localdomain {
device /dev/drbd0;
disk /dev/sdb;
# disk /dev/sdb1;
address 10.0.0.2:7788;
meta-disk internal;
}
}
[root@server1 ~]# scp /etc/drbd.d/r0.res server2:/etc/drbd.d/r0.res
[root@server1 ~]# drbdadm create-md r0
[root@server1 ~]# ssh server2
[root@server2 ~]# drbdadm create-md r0
CTRL + D
Создаем еще одну SSH сессию к серверу.
И однеовременно на обоих узлах.
[root@server1 ~]# service drbd start
[root@server2 ~]# service drbd start
[root@server1 ~]# ps ax | grep drbd
12229 ? S 0:00 [drbd-reissue]
12234 ? S 0:00 [drbd_submit]
12242 ? S 0:00 [drbd_w_r0]
12248 ? S 0:00 [drbd_r_r0]
12255 ? S 0:00 [drbd_a_r0]
12259 pts/0 S+ 0:00 grep drbd
[root@server1 ~]# ssh server2 ps ax | grep drbd
11871 ? S 0:00 [drbd-reissue]
11877 ? S 0:00 [drbd_submit]
11883 ? S 0:00 [drbd_w_r0]
11890 ? S 0:00 [drbd_r_r0]
11897 ? S 0:00 [drbd_a_r0]
-- Эта команда делает server1 primary
[root@server1 ~]# drbdadm -- --overwrite-data-of-peer primary r0
[root@server1 ~]# cat /proc/drbd
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by phil@Build64R6, 2013-10-14 15:33:06
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:45728 nr:0 dw:0 dr:46744 al:0 bm:2 lo:1 pe:3 ua:4 ap:0 ep:1 wo:f oos:41896020
[>....................] sync'ed: 0.2% (40912/40956)M
finish: 2:46:58 speed: 4,152 (4,152) K/sec
[root@server1 ~]# mkfs.ext3 /dev/drbd0
Дожидаемся синхронизации:
[root@server1 ~]# cat /proc/drbd
version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 599f286440bd633d15d5ff985204aff4bccffadd build by phil@Build64R6, 2013-10-14 15:33:06
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:42862552 nr:0 dw:1701964 dr:41162360 al:350 bm:2560 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
В режиме active/passive можно монтировать только в один раздел и на одном хосту.
[root@server1 ~]# mkdir /disk2
[root@server1 ~]# mount /dev/drbd0 /disk2
Смена ролей узлов (после окончания синхронизации)
[root@server1 ~]# umount /disk2
[root@server1 ~]# drbdadm secondary r0
[root@server1 ~]# ssh server2
[root@server2 ~]# mkdir /disk2
[root@server2 ~]# drbdadm primary r0
[root@server2 ~]# mount /dev/drbd0 /disk2
HEARTBEAT plus DRBD
Останавливаем heartbeat
Отмонтируем /disk2 на мастер (node2) узле
[root@server1 ~]# vi /etc/ha.d/haresources
server2.localdomain drbddisk Filesystem::/dev/drbd0::/disk2::ext3
[root@server1 ~]# scp /etc/ha.d/haresources server2:/etc/ha.d/haresources
[root@server1 ~]# service heartbeat restart && ssh server2 service heartbeat restart
Почитать:
http://wiki.val.bmstu.ru/doku.php?id=%D1%80%D0%B5%D1%88%D0%B5%D0%BD%D0%B8%D0%B5_drbd
http://wiki.val.bmstu.ru/doku.php?id=heartbeat_plus_drbd