使用DRBD在Ubuntu 11.10上设置网络RAID1
本教程将介绍如何在两台Ubuntu 11.10系统上借助DRBD设置网络RAID1。 DRBD代表D授权的B锁定设备,允许您通过网络镜像块设备。 这对于高可用性设置(如HA NFS服务器 )很有用,因为如果一个节点出现故障,则所有数据仍可从另一个节点获得。
我不会保证这将为您工作!
1初步说明
我将在这里使用两台服务器(都运行Ubuntu 11.10):
-
server1.example.com
(IP地址192.168.0.100
) -
server2.example.com
(IP地址:192.168.0.101
)
两个节点都有一个未分区的第二个驱动器( / dev / sdb
),具有相同的大小(在这个例子中为30GB),我想借助DRBD在网络上镜像(网络RAID1)。
重要的是,两个节点可以通过DNS或通过/ etc / hosts
来相互解决。 如果您没有为server1.example.com
和server2.example.com
创建DNS记录,则可以按如下方式在两个节点上修改/ etc / hosts
:
server1 / server2:
vi /etc/hosts
127.0.0.1 localhost.localdomain localhost 192.168.0.100 server1.example.com server1 192.168.0.101 server2.example.com server2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters |
我使用root权限运行本教程中的所有步骤,因此请确保以root用户身份登录:
sudo su
2同步时间
server1 / server2:
两个节点具有相同的时间非常重要。 因此我们安装ntp软件包:
apt-get install ntp ntpdate
3分区/ dev / sdb
server1 / server2:
现在我们的分区看起来如下:
fdisk -l
root@server1:~# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000712c1
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 62912511 31205377 5 Extended
/dev/sda5 501760 62912511 31205376 8e Linux LVM
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/mapper/server1-root: 31.4 GB, 31415336960 bytes
255 heads, 63 sectors/track, 3819 cylinders, total 61358080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/server1-root doesn't contain a valid partition table
Disk /dev/mapper/server1-swap_1: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/server1-swap_1 doesn't contain a valid partition table
root@server1:~#
如您所见, / dev / sdb
未分区。 我们改变现在,并在其上创建一个大分区, / dev / sdb1
:
fdisk /dev/sdb
root @ server1:〜#fdisk / dev / sdb
设备既不包含有效的DOS分区表,也不包含Sun,SGI或OSF disklabel
构建新的DOS磁盘标签,磁盘标识符为0xf7ab5969。
更改将仅保留在内存中,直到您决定编写它们。
之后,当然,以前的内容将无法恢复。
警告:分区表4的无效标志0x0000将被w(rite)修正
命令(m帮助):
< - n
命令行动
e扩展
p主分区(1-4)
< - p
分区号(1-4,默认为1):
< - 1
第一个扇区(2048-62914559,默认为2048):
< - ENTER
使用默认值2048
最后扇区+扇区或+大小{K,M,G}(2048-62914559,默认为62914559):
< - ENTER
使用默认值62914559
命令(m为帮助):
< - t
所选分区1
十六进制代码(类型L列出代码):
< - 83
命令(m为帮助):
< - w
分区表已被更改!
调用ioctl()重新读取分区表。
同步磁盘
root @ server1:〜#
现在跑
fdisk -l
再次,您应该在输出中找到/ dev / sdb1
:
root@server1:~# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000712c1
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 62912511 31205377 5 Extended
/dev/sda5 501760 62912511 31205376 8e Linux LVM
Disk /dev/sdb: 32.2 GB, 32212254720 bytes
64 heads, 51 sectors/track, 19275 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf7ab5969
Device Boot Start End Blocks Id System
/dev/sdb1 2048 62914559 31456256 83 Linux
Disk /dev/mapper/server1-root: 31.4 GB, 31415336960 bytes
255 heads, 63 sectors/track, 3819 cylinders, total 61358080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/server1-root doesn't contain a valid partition table
Disk /dev/mapper/server1-swap_1: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/server1-swap_1 doesn't contain a valid partition table
root@server1:~#