服务器端安装软件:
[root@localhost ~]# yum -y install scsi-target-utils
服务器启动服务
[root@localhost ~]# service tgtd start
Starting SCSI target daemon: [ OK ]
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# netstat -anpt |grep "tgtd"
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 2310/tgtd
tcp 0 0 :::3260 :::* LISTEN 2310/tgtd
-------------------------------------------------------------------------
服务器端创建逻辑卷、软raid做为iscsi服务存储设备分配给客户机。
创建lv:
[root@localhost ~]# pvcreate /dev/sdb1
[root@localhost ~]# vgcreate vg1 /dev/sdb1
[root@localhost ~]# lvcreate -L +10G -n lv-host vg1
Logical volume "lv-host" created
创建软raid:
[root@localhost ~]# mdadm -Cv /dev/md0 -a yes -n3 -l5 /dev/sd[cde]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: size set to 20969984K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# mdadm -Q /dev/md0
/dev/md0: 39.100GiB raid5 3 devices, 1 spare. Use mdadm --detail for more detail.
[root@localhost ~]# mdadm -D /dev/md0 |grep "UUID"
UUID : edd15514:2fb49a4e:53004930:a87e7a45
[root@localhost ~]# vim /etc/mdadm.conf
DEVICE /dev/sdc /dev/sdd /dev/sde
ARRAY /dev/md0 UUID=edd15514:2fb49a4e:53004930:a87e7a45
--------------------------------------------------------------------------------------------------
创建iscsi对象,lvm对象id为1,软raid对象id为2.
-L:指定驱动类型,-L iscsi 表示为iscsi存储
-o:指定操作类型,-o new 表示创建, -o d 表示删除 , -o show表示查看
-t:指定对象id
-T:指定对象名称,格式为:iqn.YYYY-mm.反向域名:识别标记
[root@localhost ~]# tgtadm -L iscsi -m target -o new -t 1 -T iqn.2014-03.test.store:lvm
[root@localhost ~]# tgtadm -L iscsi -m target -o new -t 2 -T iqn.2014-03.test.store:raid
--------------------------------------------------------------------------------
分配存储空间(LUN),iscsi对象会自动分配id为0的LUN用于,类型为contrller.
-l:指定LUNid
-b:指定块设备文件
[root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 1 -l 1 -b /dev/vg1/lv-host
[root@localhost ~]# tgtadm -L iscsi -o new -m logicalunit -t 2 -l 1 -b /dev/md0
--------------------------------------------------------------------------------
将LUN分配给客户机使用
-I:指定客户机ip
[root@localhost ~]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.10.132
[root@localhost ~]# tgtadm -L iscsi -o bind -m target -t 2 -I 192.168.10.133
------------------------------------------------------------------------------------------
查看对象信息
[root@localhost ~]# tgtadm -L iscsi -o show -m target
Target 1: iqn.2014-03.test.store:lvm
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
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: 10737 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/vg1/lv-host
Backing store flags:
Account information:
ACL information:
192.168.10.132
Target 2: iqn.2014-03.test.store:raid
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00020000
SCSI SN: beaf20
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00020001
SCSI SN: beaf21
Size: 42947 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/md0
Backing store flags:
Account information:
ACL information:
192.168.10.133
--------------------------------------------------------------------------------------------------
保存对象和LUN配置信息到配置文件内,保证在重启tgtd服务后配置仍然有效
[root@localhost ~]# vim /etc/tgt/targets.conf
default-driver iscsi
<target iqn.2014-03.test.store:lvm>
backing-store /dev/vg1/lv-host
initiator-address 192.168.10.132
</target>
<target iqn.2014-03.test.store:raid>
backing-store /dev/md0
initiator-address 192.168.10.133
</target>
----------------------------------------------------------------------------------------------------
客户端安装软件,启动服务,搜索可用设备,连接可用设备
[root@localhost ~]# yum -y install iscsi-initiator-utils lsscsi //安装软件
[root@localhost yum.repos.d]# iscsiadm -m discovery -t sendtargets -p 192.168.10.131 //指定服务器查看可用设备
Starting iscsid: [ OK ]
192.168.10.131:3260,1 iqn.2014-03.test.store:lvm //可用设备
--login:连接
--logout:取消连接
[root@localhost yum.repos.d]# iscsiadm -m node -T iqn.2014-03.test.store:lvm --login
Logging in to [iface: default, target: iqn.2014-03.test.store:lvm, portal: 192.168.10.131,3260]
Login to [iface: default, target: iqn.2014-03.test.store:lvm, portal: 192.168.10.131,3260] successful.
[root@localhost ~]# lsscsi //查看连接信息
[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 //IET表示是iscsi网络存储设备, 而Controller表示LUN
-----------------------------------------------------------------------------------------------------------
将设备分区格式化,挂载. 并修改/etc/fstab文件设置开机自动挂载连接.
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x74781043.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10240, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10240, default 10240):
Using default value 10240
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x74781043
Device Boot Start End Blocks Id System
/dev/sdb1 1 10240 10485744 83 Linux
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#
[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621436 blocks
131071 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /iscsi
[root@localhost ~]# mount /dev/sdb1 /iscsi/
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="a379fa60-b13e-41dc-b97d-e91c311516da" TYPE="ext3"
[root@localhost ~]# vim /etc/fstab
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=a3fc8beb-5a27-4683-a13b-29f38fff4a4d /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
UUID=a379fa60-b13e-41dc-b97d-e91c311516da /iscsi ext3 defaults,_netdev 0 0
设置完成,重启后这个网络设备依然会挂载在/iscsi目录下. 软raid设置按照上述方法进行挂载.
客户机连接了iscsi设备后会在/var/lib/iscsi/node目录下生成设备的相关信息.