DRBD就是网络RAID1,可以通过网络同步两个主机上的硬盘,drbd每次只允许对一个节点进行读写访问。
一、安装DRBD
CentOS 6.x
rpm -ivh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm yum -y install drbd83-utils kmod-drbd83
CentOS 7.x
rpm -ivh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm yum install -y drbd84-utils kmod-drbd84
Ubuntu16.x
apt-get install drbd-utils
#同步时间
ntpdate -u asia.pool.ntp.org
#加载drbd到内核
modprobe drbd
#查看内核是否加载drbd
lsmod |grep drbd
#更改两台主机的主机名
在test1上执行
echo "test1" > /etc/hostname echo "test1 172.16.80.25" >> /etc/hosts echo "test2 172.16.80.26" >> /etc/hosts
hostname test1
在test2上执行
echo "test2" > /etc/hostname
echo "test1 172.16.80.25" >> /etc/hosts
echo "test2 172.16.80.26" >> /etc/hosts
hostname test2
二、准备硬盘
cd /etc/drbd.d/
vim global_common.conf
global { usage-count no; } common { protocol C; handlers { } startup { } options { } disk { on-io-error detach; } net { cram-hmac-alg "sha1"; shared-secret "mydrbdtjiyu"; } syncer { rate 1024M; } }
vim mydrbd.res
resource mydrbd { on test1 { device /dev/drbd0; disk /dev/sdb1; address 172.16.80.25:7789; meta-disk internal; } on test2 { device /dev/drbd0; disk /dev/sdb1; address 172.16.80.26:7789; meta-disk internal; } }
复制这两份配置文件到test1、test2
service drbd start
三、创建DRBD设备并激活
dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
fdisk /dev/sdb
n-p-1-回车-回车-w
#激活资源mydrbd
drbdadm create-md mydrbd
#创建挂载点
mkdir /mnt/drbd
#在主上格式磁盘,挂载并写入文件
drbdsetup /dev/drbd0 primary
mkfs.ext4 /dev/drbd0
mount /dev/drbd0 /mnt/drbd
主备切换查看同步情况
cat /proc/drbd
主备手动切换方法:
1.先将主上面的磁盘卸载掉并降级 umount /dev/drbd0 drbdadm secondary r0 2.在备机上升级为主机 drbdadm primary r0 3.挂载磁盘 mount /dev/drbd0 /media/mnt
参考
https://www.dwhd.org/20150523_150831.html
https://www.cnblogs.com/wsl222000/p/5777382.html
https://www.linuxprobe.去掉com/centos6-drdb-setup-instal.html?jimmo2370