实验环境:
系统:centos-6.6
kernel:2.6.32
target端:scsi-target-utils-1.0.24-16.el6.x86_64
IP:192.168.150.138
initiator端:iscsi-initiator-utils-6.2.0.873-13.el6.x86_64
IP:192.168.150.139
一.target端构建存储环境
添加七块硬盘,四块做raid5,三块做LVM
动态加载硬盘:
linux5加载方式
echo "scsi add-single-device 0 0 1 0" > /proc/scsi/scsi
linux6加载方式
echo "- - -" > /sys/class/scsi_host/host2/scan
[[email protected] ~]# cat /proc/partitions #查看硬盘被加载
major minor #blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
253 0 18391040 dm-0
253 1 2064384 dm-1
8 16 1048576 sdb
8 32 1048576 sdc
8 48 1048576 sdd
8 64 1048576 sde
8 80 1048576 sdf
8 96 1048576 sdg
8 112 1048576 sdh
- 做raid5:
[[email protected] ~]# mdadm -Cv /dev/md0 -a yes -n3 -l5 -x1 /dev/sd[b-e]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 1047552K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[[email protected] ~]# mdadm -Q /dev/md0
/dev/md0: 2046.34MiB raid5 3 devices, 1 spare. Use mdadm --detail for more detail.
2.做lvm:
[[email protected] ~]# pvcreate /dev/sd[f-h]
Physical volume "/dev/sdf" successfully created
Physical volume "/dev/sdg" successfully created
Physical volume "/dev/sdh" successfully created
[[email protected] ~]# vgcreate dragonvg /dev/sd[f-h]
Volume group "dragonvg" successfully created
[[email protected] ~]# lvcreate -L 2.8G -n dragonlv dragonvg
Rounding up size to full physical extent 2.80 GiB
Logical volume "peipeilv" created
二.target端发布iscsi:
[[email protected] ~]# yum install scsi-target-utils
[[email protected] ~]# service tgtd start
正在启动 SCSI target daemon: [确定]
制作raid的对象
[[email protected] ~]# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2015-1.dragon.com:raid
分配存储空间
[[email protected] ~]# tgtadm --lld iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/md0
指定可以访问的客户机
[[email protected] ~]# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.150.139
[[email protected] ~]# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.150.130 #可以指定多个访问IP
查看创建的iscsi target
[[email protected] ~]# tgtadm -L iscsi -o show -m target
Target 1: iqn.2015-1.dragon.com:raid
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 2145 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/md0
Backing store flags:
Account information:
ACL information:
192.168.150.139
192.168.150.130
发布LVM的target
[[email protected] ~]# tgtadm -L iscsi -o new -m target -t 2 -T iqn.2015-1.dragon.com:lvm
[[email protected] ~]# tgtadm --lld iscsi -o new -m lu -t 2 -l 1 -b /dev/dragonvg/dragonlv
[[email protected] ~]# tgtadm --lld iscsi -o bind -m target -t 2 -I 192.168.150.139
也可以通过配置/etc/tgt/targets.conf发布target
<target iqn.2015-1.dragon.com:raid>
backing-store /dev/md0
initiator-address 192.168.150.139
</target>
<target iqn.2015-1.dragon.com:lvm>
backing-store /dev/dragonvg/dragonlv
initiator-address 192.168.150.139
</target>
三.客户端发布和挂载iscsi:
[[email protected] ~]# yum install iscsi-initiator-utils lsscsi #安装iscsi-initiator
[[email protected] ~]# service iscsi start #启动服务
[[email protected] ~]# iscsiadm -m discovery -t sendtargets -p 192.168.150.138 #查找192.168.150.138发布的iscsi发布的可用对象
正在启动 iscsid: [确定]
192.168.150.138:3260,1 iqn.2015-1.dragon.com:raid
192.168.150.138:3260,1 iqn.2015-1.dragon.com:lvm
[[email protected] ~]# iscsiadm -m node -T iqn.2015-1.dragon.com:raid --login #连接存储对象iqn.2015-1.dragon.com:raid
Logging in to [iface: default, target: iqn.2015-1.dragon.com:raid, portal: 192.168.150.138,3260] (multiple)
Login to [iface: default, target: iqn.2015-1.dragon.com:raid, portal: 192.168.150.138,3260] successful.
[[email protected] ~]# iscsiadm -m node -T iqn.2015-1.dragon.com:lvm --login #连接存储对象iqn.2015-1.dragon.com:LVM
Logging in to [iface: default, target: iqn.2015-1.dragon.com:lvm, portal: 192.168.150.138,3260] (multiple)
Login to [iface: default, target: iqn.2015-1.dragon.com:lvm, portal: 192.168.150.138,3260] successful.
[[email protected] ~]# lsscsi #可以看到本机多了两块虚拟硬盘sdb和sdc
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
[3:0:0:0] storage IET Controller 0001 -
[3:0:0:1] disk IET VIRTUAL-DISK 0001 /dev/sdb
[4:0:0:0] storage IET Controller 0001 -
[4:0:0:1] disk IET VIRTUAL-DISK 0001 /dev/sdc
分区及格式化
[[email protected] ~]# fdisk /dev/sdb
n
p
1
[enter]
[enter]
w
[[email protected] ~]# fdisk /dev/sdc
n
p
1
[enter]
[enter]
w
[[email protected] ~]# mkfs -t ext3 /dev/sdb1
[[email protected] ~]# mkfs -t ext3 /dev/sdc1
挂载成功
[[email protected] ~]# mkdir /test1
[[email protected] ~]# mkdir /test2
[[email protected] ~]# mount /dev/sdb1 /test1
[[email protected] ~]# mount /dev/sdc1 /test2