全部博文(80)
分类: 服务器与存储
2011-11-14 17:02:14
Drbd(分布式复制块设备)安装配置
系统环境:RHEL6_X86_64 selinux and iptables disables
软件下载:
server: server.example.com (附加磁盘/de/vdb)
server2.example.com (附加磁盘/dev/vdb)
##预先配置环境安装:
yum install gcc* flex kernel-devel rpm-build libxslt -y
##在/root/目录生成rpmbuild的编译路径
rpmbuild ~
tar -zxf drbd-8.4.0.tar.gz
cd drbd-8.4.0
./configure
make rpm ##编译drbd生成的rpm包
make km-rpm ## 编译drbd的内核的模块包
##将生成的rpm包安装并拷贝到另一个server进行安装
scp ~/rpmbuild/RPMS/x86_64/*.rpm server2.example.com:/root/
ssh `rpm -ivh /root/*.rpm`
##在两台server配置如下文件
cp /usr/share/docs/drbd-utils-8.4.0/drbd.conf.example /etc/drbd.d/
vim /etc/drbd.conf
....
include “drbd.d/drbd.conf.example”; ##添加项
##编辑drbd.conf.example配置如下
vim /etc/drbd.d/drbd.conf.example
resource example {
options {
on-no-data-accessible suspend-io;
}
net {
cram-hmac-alg "sha1";
shared-secret "secret_string";
}
# The disk section is possible on resource level and in each
# volume section
disk {
# If you have a resonable RAID controller
# with non volatile write cache (BBWC, flash)
disk-flushes no;
disk-barrier no;
md-flushes no;
}
# volume sections on resource level, are inherited to all node
# sections. Place it here if the backing devices have the same
# device names on all your nodes.
volume 1 {
device minor 1;
disk /dev/vdb1; ##磁盘若已分区则写分区名称,否则写设备名称,勿格式化
meta-disk internal;
}
on server.example.com {
address 192.168.0.2:7780;
}
on server2.example.com {
address 192.168.0.8:7780;
}
}
##将配置好的文件发送到server2.example.com
scp /etc/drbd.conf server2.example.com:/etc/
scp /etc/drbd.d/drbd.conf.example server2.example.com:/etc/drbd.d/
##在两台主机分别执行如下命令
drbdadm create-md example
/etc/init.d/drbd start
##将server设置为primary节点,并同步
drbdsetup /dev/drbd1 primary --force ##/dev/drbd双击tables key根据显示的填写
##在两台主机查看同步状态
watch cat /proc/drbd
version: 8.4.0 (api:1/proto:86-100)
GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by ,
2011-08-14 09:44:01
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:126192 nr:0 dw:0 dr:126856 al:0 bm:7 lo:0 pe:145 ua:0 ap:0 ep:1 wo:d oos:922896
[=>..................] sync'ed: 12.2% (922896/1048508)K
finish: 0:02:41 speed: 5,692 (4,484) K/sec
数据同步结束后创建文件系统:
# mkfs.ext4 /dev/drbd1
挂载文件系统:
# mount /dev/drbd1 /var/www/html
存放数据:
# cp -r /etc/* /var/www/html
卸载文件系统:
# umount /dev/drbd1
将 server 设置为 secondary 节点:
# drbdadm secondary example
将 server2 设置为 primary 节点:(在 server2 主机执行一下命令)
# drbdadm primary example
挂载文件系统,查看数据是否同步:
# mount /dev/drbd1 /var/www/html
注意:两台主机上的/dev/drbd1 不能同时挂载,只有状态为 primary 时,才能被挂载
使用,而此时另一方的状态为 secondary。
....GOOD LUCK!