实验环境:
192.168.0.202 主机名S202
192.168.0.203 主机名S203
分区使用逻辑卷lvdrbd
操作系统为centos6.6
概念理解:
DRBD:分布式块设备复制(Distributed Replicated Block Device)
DRBD:主从
primary:可执行读、写操作
secondary:文件系统不能挂在
DRBD:dual primary 双主
磁盘调度器:合并读请求,合并写请求
procotol(协议类型):
A:Async ,异步
B:semi sync,半同步
C:sync,同步
DRBD Source :DRBD 资源
Resource name : 资源名称,可以是除了空白字符外的任意ACSII码字符
DRBD device : DRBD设备,在双方节点上,此DRBD设备的文件,一般为/dev/drbdN,其主设备号为147
实验开始:
安装:
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
yum install drbd84 kmod-drbd84
加载drbd模块
modprobe drbd
查看是否加载drbd模块
lsmod |grep -i drbd
drbd的配置文件主要有:
/etc/drbd.conf
/etc/drbd.d/*
其中在drbd.d目录中已有一个全局配置文件global_common.conf,直接修改其中的参数如下:
global {
usage-count no;
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C; #使用DRBD的三种协议之中的第三种C
handlers {
# These are EXAMPLE handlers only.
# They may have severe implications,
# like hard resetting the node under certain circumstances.
# Be careful when chosing your poison.
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 degr-wfc-timeout outdated-wfc-timeout wait-after-sb
}
options {
# cpu-mask on-no-data-accessible
}
disk {
# size
on-io-error detach; #使用DRBD功能(drbd outdata-peer daemon)保证数据不同步时不进行切换
fencing disk-barrier disk-flushes
# disk-drain md-flushes resync-rate resync-after al-extents
# c-plan-ahead c-delay-target c-fill-target c-max-rate
# c-min-rate disk-timeout
}
net {
# protocol timeout max-epoch-size max-buffers unplug-watermark
# connect-int ping-int sndbuf-size rcvbuf-size ko-count
# allow-two-primaries
cram-hmac-alg "sha1" ; #DRBD使用加密方式进行传输
shared-secret "vgdrbd";
#after-sb-0pri
# after-sb-1pri after-sb-2pri always-asbp rr-conflict
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
}
syncer { rate 200M; } #主节点和备用节点同步时使用的带宽
}
定义资源使用:
vim vgdrbd.res
resource vgdrbd { #rescource 资源名称(自己定义)
device /dev/drbd0; #节点上的设备名称
disk /dev/mapper/VolGroup-lvdrbd; #节点上使用的磁盘分区
meta-disk internal; #DRBD原数据放置的位置(设备的内部:internal)
on S202 { #每个主机的说明以on开头 ,后面是hostname(uname -n),{}中的是主机的配置
address 192.168.0.202:7789; #定义主机的地址 和端口
}
on S203 {
address 192.168.0.203:7789;
}
}
以上的资源定义可以分开写成:
resource vgdrbd {
on S202 {
device /dev/drbd0;
disk /dev/mapper/VolGroup-lvdrbd;
meta-disk internal;
address 192.168.0.202:7789;
}
on S203 {
device /dev/drbd0;
disk /dev/mapper/VolGroup-lvdrbd;
meta-disk internal;
address 192.168.0.203:7789;
}
}
将配置好的配置文件复制到另外一台主机上:
scp global_common.conf vgdrbd.res S203:/etc/drbd.d/
然后再每主机上执行以下命令创建DRBD信息(初始化资源):
drbdadm create-md vgdrbd #drbdadm create-md 资源名称
ssh S203 "drbdadm create-md vgdrbd"
启动:
/etc/init.d/drbd start
ssh S203 "/etc/init.d/drbd start
查看节点信息:
cat /proc/drbd
[[email protected] ~]# cat /proc/drbd version: 8.4.5 (api:1/proto:86-101) GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96 build by [email protected] , 2014-10-28 10:32:53 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r----- ns:7769 nr:10 dw:7779 dr:2729 al:2 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0 [[email protected] ~]#
其中ro表示角色,ds表示磁盘状态;ns:表示网络发送的数据包;dw:表示磁盘的写信息;dr:表示磁盘的读信息
drbd-overview
[[email protected] ~]# drbd-overview 0:vgdrbd/0 Connected Secondary/Secondary UpToDate/UpToDate
将DRBD设置为主从模式:
在想要成为主节点上执行命令:
drbdadm -- --overwrite-data-of-peer primary all
cat /proc/drbd
[[email protected] drbd.d]# cat /proc/drbd version: 8.4.5 (api:1/proto:86-101) GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96 build by [email protected] , 2014-10-28 10:32:53 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:7769 nr:10 dw:7779 dr:3417 al:2 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
挂载:
mkfs.ext4 /dev/drbd0 #格式化资源
mount -t /dev/VolGroup/lvdrbd /vgdrbd #挂载到/lvdrbd目录下
主从切换命令:
drbdadmin secondary vgdrbd #将自己降级为从
drbdadmin primary vgdrdb #将自己升级为主