DRBD简介
DRBD实际上是一种块设备的实现,主要被用于Linux平台下的高可用(HA)方案之中。他是有内核模块和相关程序而组成,通过网络通信 来同步镜像整个设备,有点类似于一个网络RAID的功能。也就是说当你将数据写入本地的DRBD设备上的文件系统时,数据会同时被发送到网络中的另外一台 主机之上,并以完全相同的形式记录在一个文件系统中(实际上文件系统的创建也是由DRBD的同步来实现的)。本地节点(主机)与远程节点(主机)的数据可 以保证实时的同步,并保证IO的一致性。所以当本地节点的主机出现故障时,远程节点的主机上还会保留有一份完全相同的数据,可以继续使用,以达到高可用的 目的。
实验环境
测试节点2个分别为:
node1.3glong.com 172.16.8.156
node2.3glong.com 172.16.8.157
系统环境为rhel6.4 64位
准备工作
配置SSH双机互信
修改hosts互相解析
关闭selinux
安装配置
[[email protected] ~]# tar xf drbd-9.0.1-1.tar.gz [[email protected] ~]# cd drbd-9.0.1-1 [[email protected] drbd-9.0.1-1]# ls ChangeLog COPYING drbd drbd-headers drbd-kernel.spec filelist-redhat filelist-suse Makefile misc README README.drbd-utils rpm-macro-fixes [[email protected] drbd-9.0.1-1]# cd [[email protected] drbd-9.0.1-1]# make KDIR=/usr/src/kernels/2.6.32-358.el6.x86_64/ [[email protected] drbd-9.0.1-1]# make install
[[email protected] drbd-9.0.1-1]# modprobe drbd #加载drbd模块[[email protected] ~]# tar xf drbd-utils-8.9.6.tar.gz [[email protected] ~]# cd drbd-utils-8.9.6 [[email protected] drbd-utils-8.9.6]# ./configure --prefix=/usr/local/drbd-utils-8.9.6 --without-83support [[email protected] drbd-utils-8.9.6]# make [[email protected] drbd-utils-8.9.6]# make install [[email protected] drbd-utils-8.9.6]# cp /usr/local/drbd-utils-8.9.6/etc/rc.d/init.d/drbd /etc/rc.d/init.d/ [[email protected] drbd-utils-8.9.6]# chkconfig --add drbd [[email protected] drbd-utils-8.9.6]# chkconfig drbd on
修改配置文件
[[email protected] ~]# cat /usr/local/drbd-utils-8.9.6/etc/drbd.d/r0.res resource r0{ on node1.3glong.com{ device /dev/drbd1; #逻辑设备的路径 disk /dev/sdb; #物理设备 address 172.16.8.156:7788; meta-disk internal; } on node2.3glong.com{ device /dev/drbd1; disk /dev/sdb; address 172.16.8.157:7788; meta-disk internal; } } [[email protected] ~]# cat /usr/local/drbd-utils-8.9.6/etc/drbd.d/global_common.conf # DRBD is the result of over a decade of development by LINBIT. # In case you need professional services for DRBD or have # feature requests visit http://www.linbit.com global { usage-count yes; # minor-count dialog-refresh disable-ip-verification # cmd-timeout-short 5; cmd-timeout-medium 121; cmd-timeout-long 600; } common { 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 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 shared-secret after-sb-0pri # after-sb-1pri after-sb-2pri always-asbp rr-conflict protocol C; # ping-timeout data-integrity-alg tcp-cork on-congestion # congestion-fill congestion-extents csums-alg verify-alg # use-rle } }
格式化分区 mke2fs -t ext4 /dev/sdb 用dd写入点数据,不然可能会出错 dd if=/dev/zero of=/dev/sdb bs=1M count=1
-------------------------------以上步骤分别在两台机上操作---------------------------------
[[email protected] drbd-utils-8.9.6]# drbdadm create-md r0 #建立 drbd resource [[email protected] drbd-utils-8.9.6]# drbdadm up r0
[[email protected] drbd-utils-8.9.6]# drbdadm primary --force r0 #设为主服务器两个节点分别执行service drbd start
测试
[[email protected] drbd-utils-8.9.6]# mount /dev/drbd1 /mnt [[email protected] drbd-utils-8.9.6]# cd /mnt [[email protected] mnt]# ls lost+found [[email protected] mnt]# touch 123.txt [[email protected] ~]# umount /dev/drbd1 [[email protected] ~]# drbdadm secondary r0 [[email protected] drbd-utils-8.9.6]# cd /mnt [[email protected] mnt]# ls 123.txt lost+found [[email protected] mnt]# touch 111.txt [[email protected] mnt]# cd [[email protected] ~]# umount /dev/drbd1 [[email protected] ~]# drbdadm secondary r0 #降级为备用服务器 [[email protected]1 ~]# drbdadm primary r0 [[email protected] ~]# mount /dev/drbd1 /mnt [[email protected] ~]# ls /mnt 111.txt 123.txt lost+found
时间: 2024-10-26 12:44:02