1.配置系统环境
node1的配置:
1)配置ip:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
修改两行
BOOTPROTO static
IPADDR 192.168.0.20
:wq
2)重启网络服务:
service network restart
3)将主机名改为node1.a.org:
vim /etc/sysconfig/network
hostname=node1.a.org
:wq
hostname node1.a.org
uname -n
4)编辑/etc/hosts实现node1和node2的解析:
vim /etc/hosts
192.168.0.20 node1.a.org node1(node1是别名)
192.168.0.30 node2.a.org node2
:wq
5)生成密钥并将公钥传给node2:
ssh-keygen -t rsa
ssh-copy-id -i .ssh/id_rsa.pub
ssh node1 'ifconfig'
6)提供一个分区做为drbd设备(此实验用的是/dev/sda3):
fdisk /dev/sda
n
p
3
+512M
w
partprobe /dev/sda(重新读一下设备,切记此时不要进行格式化)
node2的配置:
步骤同node1,只需要将1)中的ip改为192.168.0.30,将3),5)中的node1改为node2即可。
-------------------------------------------------------------------------
2.下载软件包并安装
网址:
所需要的软件包:
drbd83-8.3.8-1.el5.centos.i386.rpm
kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
yum --nogpgcheck -y localinstall drbd83-8.3.8-1.el5.centos.i386.rpm kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
3.配置drbd
1)复制样例配置文件为即将使用的配置文件:
cp /usr/share/doc/drbd83-8.3.8/drbd.conf /etc
2)配置/etc/drbd.d/global_common.conf
global {
usage-count no;
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C;
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
wfc-timeout 120;
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
fencing resource-only;
}
net {
cram-hmac-alg "sha1";
shared-secret "mydrbdlab";
}
syncer {
rate 100M;
}
}
3)定义一个资源/etc/drbd.d/web.res,内容如下:
resource web {
on node1.a.org {
device /dev/drbd0;
disk /dev/sda5;
address 192.168.0.5:7789;
meta-disk internal;
}
on node2.a.org {
device /dev/drbd0;
disk /dev/sda5;
address 192.168.0.6:7789;
meta-disk internal;
}
}
4)在两个节点上初始化已定义的资源并开启服务
node1,node2上分别执行:
初始化资源:
#drbdadm create-md web
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
开启服务:
#/etc/init.d/drbd start
Starting DRBD resources: [ ].
查看启动状态:
#cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by , 2010-06-04 08:04:16
0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:505964
从上面的信息中可以看出此时两个节点均处于Secondary状态。于是,我们接下来需要将其中一个节点设置为Primary。在要设置为Primary的节点上执行如下命令:
在想作为primary的节点上设置主节点:
# drbdadm -- --overwrite-data-of-peer primary web
查看状态(数据同步已经开始)
# drbd-overview
0:web SyncSource Primary/Secondary UpToDate/Inconsistent C r----
[============>.......] sync'ed: 66.2% (172140/505964)K delay_probe: 35
查看状态(数据同步完成,以有了Primary和secondly之分)
# drbd-overview
0:web Connected Primary/Secondary UpToDate/UpToDate C r----
4.创建文件系统
在主节点上配置:
# mke2fs -j -L DRBD /dev/drbd0
# mkdir /mnt/drbd
# mount /dev/drbd0 /mnt/drbd
5.切换主从节点Node1:
# cp -r /etc/drbd.* /mnt/drbd
# umount /mnt/drbd
# drbdadm secondary web
查看状态:
# drbd-overview
0:web Connected Secondary/Secondary UpToDate/UpToDate C r----
Node2:
# drbdadm primary web
# drbd-overview
0:web Connected Primary/Secondary UpToDate/UpToDate C r----
# mkdir /mnt/drbd
# mount /dev/drbd0 /mnt/drbd
使用下面的命令查看在此前在主节点上复制至此设备的文件是否存在:
# ls /mnt/drbd
----------------------------------------------------------------------------------------------
老师啊,你掐我吧。。。。后面写的我自己都心虚。。。
阅读(2602) | 评论(0) | 转发(0) |