安装依赖软件包
yum install kernel-devel kernel-headers flex wget make gcc glibc perl -y
下载最新drbd源码包,并解压
cd /tmp
wget http://oss.linbit.com/drbd/drbd-latest.tar.gz
tar -zxvf drbd-latest.tar.gz -C /usr/local/src/
编译安装drbd
cd /usr/local/src/drbd-8.4.4
./configure --prefix=/opt/drbd --localstatedir=/var --sysconfdir=/etc --with-km --with-rgmanager
make && make install
安装drbd模块
cd /usr/local/src/drbd-8.4.4/drbd
make clean
make
make install
cp drbd.ko /lib/modules/`uname -r`/kernel/lib/
modprobe drbd
lsmod | grep drbd #如果看到以下信息,说明内核加载drbd模块成功。
drbd 340679 8
libcrc32c 1246 1 drbd
配置drbd
cd /etc/drbd.d
全局配置
vi global_common.conf
global {
usage-count yes;
# minor-count dialog-refresh disable-ip-verification
}
common {
syncer { rate 100M; }
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
degr-wfc-timeout 120; # 2 minutes.
}
options {
# cpu-mask on-no-data-accessible
}
disk {
# size max-bio-bvecs 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
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
cram-hmac-alg "sha1";
shared-secret "FooFunFactory";
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
}
}
资源配置
vi drbd.res
resource r0 {
protocol C;
device /dev/drbd0;
disk /dev/xvdb1;
meta-disk internal;
on pg1-rg {
address 172.26.184.38:7788;
}
on pg2-rg {
address 172.26.184.39:7788;
}
}
resource r1 {
protocol C;
device /dev/drbd1;
disk /dev/xvdc1;
meta-disk internal;
on pg1-rg {
address 172.26.184.38:7789;
}
on pg2-rg {
address 172.26.184.39:7789;
}
}
创建节点启动drbd服务
drbdadm create-md r0
chkconfig --add drbd
service drbd start
drbd默认 2个都是secondary,所以在主节点设置为primary
drbdadm -- --overwrite-data-of-peer primary all (第一次设置主节点)
drbdadm primary all (以后设置节点为主节点)
drbd常用命令
查看资源的连接状态
drbdadm cstate all
查看节点状态
drbdadm role all
查看同步进度
cat /proc/drbd 或者 /opt/drbd/sbin/drbd-overview
#############报错信息#############
报错1:
configure: error: Cannot build utils without flex,either install flex or pass the --without-utils option.
解决办法:
yum -y intalls flex
报错2:
make: [check-kdir] error 1
解决办法:yum install -y kernel-devel
报错3:
SORRY,kernel makefile not found.
You need to tell me a correct KDIR,
Or install the neccessary kernel source packages.
报错4:'drbd' not defined in your config (for this host).
这个因为没有加载到drbd模块
启动报错:
Command 'drbdmeta 0 v08 /dev/sdb1 internal create-md' terminated with exit code 40
这是因为sdb1已经有文件系统了,已经有数据存在了
解决方法:
[root@node1 ~]# dd if=/dev/zero bs=1M count=1 of=/dev/sdb1
请检查这个KDIR目录指的路径是否正确
##########################