一、资源
两台主机IP地址和计算机名分别为:
192.168.20.178 iscsi-1
192.168.20.179 iscsi-2
二、存储设备分区
用GTP分区,需安装parted,怎么分区请自己百度
yum -y install parted
/dev/sdb1 分2T
/dev/sdb2 分1T
三、安装DRBD
#添加yum源
rpm -Uvh
yum -y install drbd84-utils kmod-drbd84
双方的ip地址和计算机名添加到 /etc/hosts
cat > /etc/drbd.d/global_common.conf << EOF
DRBD is the result of over a decade of development by LINBIT.
# In case you need professional services for DRBD or have
# feature requests visit
global {
usage-count yes;
# minor-count dialog-refresh disable-ip-verification
}
common {
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 {
degr-wfc-timeout 120; #连接超时时间
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
}
options {
on-no-data-accessible suspend-io;
# cpu-mask on-no-data-accessible
}
disk {
on-io-error detach; #磁盘错误停止同步
# size 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 C; #确认方式 A:数据一旦写入磁盘并发送到网络中就认为完成了写入操;作B:收到接收确认就认为完成了写入操作;C:收到写入确认就认为完成了写入操作。
# 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
}
syncer {
rate 1000M; #传输速度
}
}
EOF
cat > /etc/drbd.d/share.res << EOF
resource cs1 {
volume 1 {
device /dev/drbd1;
disk /dev/sdb1;
meta-disk internal;
}
on iscsi-1 {
address $iscsi_1_ip:7781;
}
on iscsi-2 {
address $iscsi_2_ip:7781;
}
}
resource cs2 {
volume 2 {
device /dev/drbd2;
disk /dev/sdb2;
meta-disk internal;
}
on iscsi-1 {
address $iscsi_1_ip:7782;
}
on iscsi-2 {
address $iscsi_2_ip:7782;
}
}
EOF
由于安装drbd过程中会更新kernel,所有最好重启系统再初始资源
#Initialize resource
dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
drbdadm create-md cs1
drbdadm create-md cs2
drbdadm up cs1
drbdadm up cs2
保持两台机器设置一样,到此DRBD安装完成,随便设置一台为primary
这里设置192.168.20.178为primary
drbdadm primary all --force
分别启动两台机器的drbd服务
/etc/init.d/drbd start 需要关闭IPtables
查看状态,/etc/init.d/drbd status 会开始同步数据,完成后如下
[root@iscsi-1 ~]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
m:res cs ro ds p mounted fstype
1:cs1 Connected Primary/Secondary
UpToDate/UpToDate C
2:cs2 Connected Primary/Secondary
UpToDate/UpToDate C
红色表示数据是同步的
四、安装ISCSI
yum install scsi-target-utils
在主上启动ISCSI,客户端即可连接,我们用的是windows 2008R自带的有ISCSI连接工具
/etc/init.d/tgtd start
以下是安装脚本