- 论坛徽章:
- 0
|
drbd安装过程
wenuy----20060610
DRBD 是由内核模块和相关脚本而构成,用以构建高可用性的集群。其实现方式是通过网络来镜像整个设备。
您可以把它看作是一种网络RAID。
Drbd 负责接收数据,把数据写到本地磁盘,然后发送给另一个主机。另一个主机再将数据存到自己的磁盘中。
源码下载http://oss.linbit.com/drbd/0.7/drbd-0.7.19.tar.gz
核心参考文档:http://www.drbd.org/drbd-howto.html
============
1、主要实现
假设有两台机器nannan:192.168.0.136 需要镜像的硬盘:/dev/hdc3
root:192.168.0.139 需要镜像的硬盘:/dev/hdc2
主服务器为192.168.0.136 简称为136
备份服务器为192.168.0.139 简称为139
平常对数据读写都在136上实现,当136 down掉后可以启动139,实现数据的热备份。
真正的热切换需要才用HA 来实现。
2、下载安装
安装环境:fc2,内核版本:2.6.12.4
确认内核源码存在。
下载源码注意:当前最新的drbd-8.0pre3,配置文件无法正常配置,出现一大堆错误,所以下载以前的稳定版本。
tar开源码包后
运行:
A、make KDIR=/usr/src/linux /*内核所在的位置*/
/*如果你没有更改内核可以直接运行make,软件会直接到/lib/module里边去寻找系统环境,如果是新的内核需要对内核进行编译安装,
否则make时候会错误中断掉*/
B、make install
安装完主要生成命令:drbdsetup ,drbdadmin
和配置文件:/etc/drbd.conf ,启动文件,/etc/init.d/drbd
模块文件:drbd.ko(在编译好的安装包目录下的drbd下可以找到)
所有命令和配置文件都可以在源码包编译成功的目录下面找到。
./scripts/drbd.conf是最原始的配置文件,当/etc/drbd.conf被破坏,可以直接拷贝覆盖掉。
C、创建硬件设备drbd
mknod /dev/drbd0 b 147 0
mknod /dev/drbd1 b 147 1
mknod /dev/drbd2 b 147 2
或者用shell来建立多个:
#for i in $(seq 0 15) ; do mknod /dev/drbd$i b 147 $i ; done
3、配置drbd
修改/etc/drbd.conf
主要修改了:机器名和设备名ip地址
======================================================
on nannan{
device /dev/drbd0;
disk /dev/hdc3;
address 192.168.0.136:7788;
meta-disk internal;
# meta-disk is either 'internal' or '/dev/ice/name [idx]'
#
# You can use a single block device to store meta-data
# of multiple DRBD's.
# E.g. use meta-disk /dev/hde6[0]; and meta-disk /dev/hde6[1];
# for two different resources. In this case the meta-disk
# would need to be at least 256 MB in size.
#
# 'internal' means, that the last 128 MB of the lower device
# are used to store the meta-data.
# You must not give an index with 'internal'.
}
on root {
device /dev/drbd0;
disk /dev/hdc2;
address 192.168.0.139:7788;
meta-disk internal;
}
======================================================
下面是整个drbd.conf的配置文件
注意:配置的版本是drbd-0.7.19.tar.gz
不同版本无法兼容。
修改的地方就以上几个地方和注释
还有把除了resource r0 外的其他配置块如resource r1等。
也就是说/**** on root {
device /dev/drbd0;
disk /dev/hdc2;
address 192.168.0.139:7788;
meta-disk internal;
}
}
****/后面的所有内容
#
# drbd.conf example
#
skip {
As you can see, you can also comment chunks of text
with a 'skip[optional nonsense]{ skipped text }' section.
This comes in handy, if you just want to comment out
some 'resource <some name> {...}' section:
just precede it with 'skip'.
The basic format of option assignment is
<option name><linear whitespace><value>;
It should be obvious from the examples below,
but if you really care to know the details:
<option name> :=
valid options in the respective scope
<value> := <num>|<string>|<choice>|...
depending on the set of allowed values
for the respective option.
<num> := [0-9]+, sometimes with an optional suffix of K,M,G
<string> := (<name>|\"([^\"\\\n]*|\\.)*\")+
<name> := [/_.A-Za-z0-9-]+
}
# global {
# use this if you want to define more resources later
# without reloading the module.
# by default we load the module with exactly as many devices
# as configured mentioned in this file.
#
# minor-count 5;
# The user dialog counts and displays the seconds it waited so
# far. You might want to disable this if you have the console
# of your server connected to a serial terminal server with
# limited logging capacity.
# The Dialog will print the count each 'dialog-refresh' seconds,
# set it to 0 to disable redrawing completely. [ default = 1 ]
#
# dialog-refresh 5; # 5 seconds
# You might disable one of drbdadm's sanity check.
# disable-ip-verification;
# }
#
# this need not be r#, you may use phony resource names,
# like "resource web" or "resource mail", too
#
resource r0 {
protocol C;
# what should be done in case the cluster starts up in
# degraded mode, but knows it has inconsistent data.
incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
startup {
degr-wfc-timeout 120; # 2 minutes.
}
disk {
}
net {
}
syncer {
rate 10M;
group 1;
al-extents 257;
}
on nannan{
device /dev/drbd0;
disk /dev/hdc3;
address 192.168.0.136:7788;
meta-disk internal;
}
on root {
device /dev/drbd0;
disk /dev/hdc2;
address 192.168.0.139:7788;
meta-disk internal;
}
}
=================================================
4、启动drbd
先确认两台要镜像的机器是否正常,之间的网络是否通畅,需要加载的硬盘是否处于umount状态。
确认好后就可以开始启动drbd
先后在136和139机器上面
运行
A、drbd采用的是模块控制的方式
所以先要加载drbd.ko 模块
insmod drbd.ko
drbd.ko可以在编译好的源码包里找到。
判断是否加载成功可以使用lsmod来查看:
Module size Used by
drbd 143088 -
有的话表示加载模块成功
B、drbdadm up all
启动drbd服务,使他挂在后台状态下运行
可以使用命令netstat -an查看
有启动端口7788,同时也监听对方的7788端口,来实现数据交换。
5、drbd的基本服务都起来了,现在需要对主的服务器也就使192.168.0.136这台服务器进行配置,
让他能够对drbd0设备进行读写。
在136机器上运行
drbdadm -- --do-what-I-say primary all
注意命令格式需要一样
没有任何提示的话表示基本上成功了
sfdisk -s
可以看见有一个硬件设备:/dev/drbd0
如果原来硬盘没有文件系统的话,现在您可以在设备/dev/drbd0上创建一个文件系统,然后把它加载到136上。
现在/dev/drbd0就等于你服务器上面的一个硬件设备,你可以对他进行任何的读写操作。 |
|