两台机器的环境:
data-1-1 eth0 10.0.0.7 eth1 172.16.1.7 eth2 10.0.10.7
data-1-2 eth0 10.0.0.8 eth1 172.16.1.8 eth2 10.0.10.8
[root@data-1-2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.10.7 data-1-1
10.0.10.8 data-1-2
挂两块磁盘到虚拟机上面,其中主drbd上面需要2G空间,辅drbd上面需要3G空间
对磁盘进行格式化和分区:
主:
df -Th
fdisk -l
parted /dev/sdb mklabel gpt yes
parted /dev/sdb mkpart primary ext4 0 1000 ignore
parted /dev/sdb mkpart primary ext4 1001 2000 Yes ignore
parted /dev/sdb p
mkfs.ext4 /dev/sdb1
tune2fs -c -1 /dev/sdb1
辅:
df -Th
fdisk -l
parted /dev/sdb mklabel gpt yes
parted /dev/sdb mkpart primary ext4 0 2000 ignore
parted /dev/sdb mkpart primary ext4 2001 3000 Yes ignore
parted /dev/sdb p
mkfs.ext4 /dev/sdb1
tune2fs -c -1 /dev/sdb1
两台机器上面需要同时做如下操作:
cd /usr/local/src
wget -q http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
rpm -ivh elrepo-release-6-5.el6.elrepo.noarch.rpm
安装drbd所需要的软件
yum install drbd kmod-drbd84 -y
rpm -qa|grep drbd
lsmod |grep drbd
modprobe drbd
lsmod |grep drbd
echo "modprobe drbd" > /etc/sysconfig/modules/drbd.modules
chmod 755 /etc/sysconfig/modules/drbd.modules
tail -1 /etc/sysconfig/modules/drbd.modules
drbd公用的配置文件(简化版):
[root@data-1-1 data]# cat /etc/drbd.conf
global {
usage-count no;
}
common {
syncer {
rate 100M;
verify-alg crc32c;
}
}
# primary for drbd1
resource data {
protocol C;
########################################如果需要做双主模式的drbd,则需要加如下几行############################################################
net {
allow-two-primaries;
}
startup {
become-primary-on both;
}
########################################如果需要做双主模式的drbd,则需要加如上几行############################################################
disk {
on-io-error detach;
}
on data-1-1 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.0.10.7:7788;
meta-disk /dev/sdb2[0];
}
on data-1-2 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.0.10.8:7788;
meta-disk /dev/sdb2[0];
}
}
在主节点上面:
drbdadm create-md data 创建数据节点
drbdadm up all(data) 启动数据节点
cat /proc/drbd 查看drbd状态
drbdadm -- --overwrite-data-of-peer primary data 将其中一台机器提升为主节点
然后分别启动drdb,查看状态:
[root@data-1-1 data]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Primary/Secondary ds:UpToDate/Diskless C r-----
ns:976730 nr:0 dw:184 dr:977613 al:3 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@data-1-2 /]# cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:Connected ro:Secondary/Primary ds:Diskless/UpToDate 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:b oos:0