Drbd 安装配置

drbd为网络的磁盘镜像

防火墙

chkconfig iptables off
service iptables stop
service iptables status
setenforce 0
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config

存储分区

1)使用fdisk或者parted分区
 fdisk -l
 fdisk /dev/sdb
 partprobe        ##分区信息写入磁盘
 ##或者采用parted分区,超过2T必须用partprobe分区
 parted /dev/sdb mklabel gpt
 parted /dev/sdb mkpart primary 0 4800000 #4.9T
 parted /dev/sdb mkpart primary 4800001 5800001
 parted /dev/sdb mkpart primary 5800002 5804098
 parted /dev/sdb p

(2)数据文件盘格式化
 mkfs.ext4 /dev/sdb1
 #mkfs.ext4  ##备节点不需要格式化
 #状态分区不要格式化(大小范围:1-2G)
 [root@data-2 ~]# mount /dev/sdb2 /mnt
 mount: you must specify the filesystem type

drbd安装

1)设置环境变量
 export LC_ALL=C2)编译安装drbd软件
 wget http://oss.linbit.com/drbd/8.4/drbd-8.4.4.tar.gz
 tar xf drbd-8.4.4.tar.gz
 cd drbd-8.4.4

 ./configure --prefix=/application/drbd8.4.4 --with-km --with-heartbeat --sysconfdir=/etc/
 make KDIR=/usr/src/kernels/$(uname -r)/
 make install

 lsmod |grep drbd
 modprobe drbd  ##重启失效,加载到内核中
 lsmod |grep drbd
 echo "modprobe drbd" >>/etc/rc.local ##开机自动加载
 #yum install kernel-devel -y3)yum安装drbd软件
 [root@data-1 /]# rpm -ivh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
 [root@data-2 /]# yum install drbd kmod-drbd84

drbd配置

--模板路径
[root@data-1 drbd8.4.4]# ll /etc/drbd.d/
total 4
-rw-r--r-- 1 root root 1836 Dec  1 10:52 global_common.conf

--配置文件(两节点)
[root@data-1 etc]# vi /etc/drbd.conf 
global {
        usage-count no;
}
common {
       syncer {
             rate 1000M;
             verify-alg crc32c;  
       }
}
resource data {
   protocol C;

   disk {
     on-io-error detach;
   }
   on data-1 {
     device    /dev/drbd0;
     disk      /dev/sdb1;
     address    192.168.0.51:7788;
     meta-disk /dev/sdb2[0];   
   }
   on data-2 {
     device    /dev/drbd0;
     disk      /dev/sdb1;
     address    192.168.0.52:7788;
     meta-disk /dev/sdb2[0];  
  }
}

drbd初始化与启动

drbdadm --help
drbdadmin create-md data1)初始化
    [root@data-1 ~]# drbdadm create-md data
     Writing meta data...
     initializing activity log
     NOT initializing bitmap
     New drbd meta data block successfully created.2)创建目录
    mkdir -p /application/drbd8.4.4/var/run/drbd

(3)启动资源data
    drbdadm up data
    --查看同步状态
    [root@data-1 ~]# cat /proc/drbd 
    version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1, 2015-12-01 10:52:04
 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:f oos:62974524)将第一个节点置为primary
    drbdadm -- --overwrite-data-of-peer primary data5)查看同步完成状态
    [root@data-1 data]# cat /proc/drbd 
    version: 8.4.4 (api:1/proto:86-101)
GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1, 2015-12-01 10:52:04
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:6297520 nr:0 dw:72 dr:6298459 al:3 bm:385 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:06)磁盘挂载(仅primary节点),Secondary挂载需要先drbdadm down data -->mount /dev/sdb1 /data
    mount /dev/drbd0 /data

出现Unknown解决办法

##先查看防火墙
--slave节点
drbdadm secondary data
drbdadm up date
drbdadm disconnect data
drbdadm -- --discard-my-data connect data
--primary节点
cat /proc/drbd 查看状态。
drbdadm connect data
cat /proc/drbd 
mount /dev/drbd0 /data

注释:用途大数据迁移,注意空间丢失问题

你可能感兴趣的:(Linux)