知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

快速安装及部署DRBD

发布时间:2015-11-06 16:47:30作者:知识屋

DRBD以其开源,简单,高效,性能不俗为广大运维者们所青睐。主要功能是在不同节点上两个相同大小的设备块级别之间的数据同步镜像。drbd是由内核模块和相关脚本而构成,用以构建高可用性的集群。本文主要描述其安装方式,供大家参考。

有关DRBD的特性,功能及其相关基础知识,大家可以参考: DRBD原理及特性概述

一、演示环境

OS版本:CentOS release 6.5 (Final)orasrv1: 192.168.21.10 orasrv2: 192.168.21.13 DRBD版本Version: 8.3.15 (api:88)

二、yum方式安装drbd(两节点)

1、以下通过yum方式安装

配置epel源,可以从这里下载,或者直接用wget方式获取http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm # rpm -Uvh epel-release-6-8.noarch.rpm# yum -y install drbd83 kmod-drbd83# modprobe drbd# lsmod |grep drbddrbd                  345363  0 

2、配置部分,请参考第三点编译方式安装drbd之第4小点后续部分

###注,通过yum方式安装时,drbd配置文件目录有所不同###drbd.conf文件放置到/etc目录下,其余的2个配置文件存放到/etc/drbd.d目录下

三、编译方式安装drbd

1、安装用户空间工具(两节点)

# yum -y install kernel-devel kernel-headers flex gcc# pwdusr/local/src     ###drbd压缩文件存放位置# tar -xvf drbd-8.3.15.tar.gz # cd drbd-8.3.15# ./configure --prefix=/usr/local/drbd --with-km# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64/# make install# ls /usr/local/drbd/   ##查看安装后的文件etc  lib  sbin  share  var# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/init.d/drbd# chkconfig --add drbd# chkconfig drbd on

2、安装drbd模块(两节点)

# cd /usr/local/src/drbd-8.3.15/drbd# make clean# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64/# cp drbd.ko /lib/modules/`uname -r`/kernel/lib/# depmod# modprobe drbd    ###加载drbd模块到Linux内核注:/usr/src/kernels/2.6.18-274.18.1.el5-i686/这个内核源码树路径需要根据自己的系统修改。

3、验证drbd内核加载(两节点)

# lsmod |grep drbddrbd                  345363  0 

4、配置系统磁盘(两节点)

### Author : Leshami### Blog   : http://blog.csdn.net/leshami###本示例种为当前2节点单独分配了/dev/sdb磁盘,以下操作在2节点完成# fdisk /dev/sdb    ###依次输入n,p,1,回车(enter),回车(enter),w# partprobe         ###如果依旧无法看到分区,请reboot以及查找原因# fdisk -l /dev/sdb

5、配置drbd.conf及global_common.conf(两节点)

# mv /usr/local/drbd/etc/drbd.conf /usr/local/drbd/etc/drbd.conf.bk# cp /usr/local/src/drbd-8.3.15/scripts/drbd.conf /usr/local/drbd/etc/drbd.conf# more /usr/local/drbd/etc/drbd.conf   ###查看drbd.conf应包含下列include内容# You can find an example in  /usr/share/doc/drbd.../drbd.conf.exampleinclude "drbd.d/global_common.conf";include "drbd.d/*.res";# mv /usr/local/drbd/etc/drbd.d/global_common.conf /usr/local/drbd/etc/drbd.d/global_common.conf.bk# vi /usr/local/drbd/etc/drbd.d/global_common.conf   ###global_common.conf可以参考drbd.conf.exampleglobal {        usage-count yes;        # minor-count dialog-refresh disable-ip-verification}common {        protocol C;        handlers {        }        startup {                wfc-timeout 0; degr-wfc-timeout 120;        }        disk {                on-io-error detach;        }        net {                # sndbuf-size rcvbuf-size timeout connect-int ping-int ping-timeout max-buffers                # max-epoch-size ko-count allow-two-primaries cram-hmac-alg shared-secret                # after-sb-0pri after-sb-1pri after-sb-2pri data-integrity-alg no-tcp-cork                cram-hmac-alg sha1;                shared-secret "MySQL-HA";              }        syncer {                # rate after al-extents use-rle cpu-mask verify-alg csums-alg                rate 35M;        }}###配置资源文件redisk.res# vi /usr/local/drbd/etc/drbd.d/redisk.res              resource redisk {  on orasrv1.xlk.com {    device    /dev/drbd0;    disk      /dev/sdb1;    address   192.168.21.10:7789;    meta-disk internal;  }  on orasrv2.xlk.com {    device    /dev/drbd0;    disk      /dev/sdb1;    address   192.168.21.13:7789;    meta-disk internal;  }}###也可以通过copy方式直接将配置文件copy到节点2,则无需单独配置2个配置文件,如下:# scp /usr/local/drbd/etc/drbd.d/* 192.168.21.13:/usr/local/drbd/etc/drbd.d/# scp /usr/local/drbd/etc/drbd.conf 192.168.21.13:/usr/local/drbd/etc/

6、创建device metadata(两节点执行)

# drbdadm create-md rediskWriting meta data...initializing activity logNOT initialized bitmapNew drbd meta data block successfully created.[root@orasrv1 drbd.d]# drbdadm up redisk[root@orasrv1 drbd.d]# /etc/init.d/drbd statusdrbd driver loaded OK; device status:version: 8.3.15 (api:88/proto:86-97)GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 09:16:05m:res     cs            ro                 ds                     p  mounted  fstype0:redisk  WFConnection  Secondary/Unknown  Inconsistent/DUnknown  C

5、设置Primary节点(主节点)

以下操作仅在节点1(orasrv1)执行# drbdadm primary --force redisk0: State change failed: (-2) Need access to UpToDate dataCommand 'drbdsetup 0 primary' terminated with exit code 17# drbdadm -- --overwrite-data-of-peer primary redisk# mkfs.ext3 /dev/drbd0# mkdir /data# mount /dev/drbd0 /data# df -h |grep data/dev/drbd0      2.0G   36M  1.9G   2% /data###在第二个节点上创建/data目录# mkdir /data###查看drbd状态信息:#cat /proc/drbd

四、DRBD数据镜像功能测试

###首先在主节点完成如下操作# cp -R /usr/local/drbd /data# ls /data/drbdetc  lib  sbin  share  var# du -sh /data/drbd324K    /data/drbd# umount /data# drbdadm secondary redisk# cat /proc/drbdversion: 8.3.15 (api:88/proto:86-97)GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 10:58:13 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----    ns:1044700 nr:0 dw:33780 dr:1045517 al:3 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0###在备用节点完成如下操作  # drbdadm primary redisk# cat /proc/drbdversion: 8.3.15 (api:88/proto:86-97)GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by [email protected], 2015-10-31 10:59:26 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----    ns:0 nr:1044700 dw:1044700 dr:672 al:0 bm:64 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0# mount /dev/drbd0 /data# du -sh /data/drbd    ###两节点数据目录及大小完全一致324K    /data/drbd
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜