首先是安装,在配置好yum源的情况下直接安装scsi-target-utils即可yum -y install scsi-target-utils
然后查看下scsi-target-utils的信息
[root@monitor ~]# yum info scsi-target-utils
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name : scsi-target-utils
Arch : x86_64
Version : 1.0.24
Release : 10.el6
Size : 457 k
Repo : installed
From repo : c6-media
Summary : The SCSI target daemon and utility programs
URL :
License : GPLv2
Description : The SCSI target package contains the daemon and tools to setup a SCSI targets.
: Currently, software iSCSI targets are supported.
[root@monitor ~]#
启动iscsi服务
[root@monitor ~]# service tgtd start
tgtadm --lld <driver> --op new --mode target --tid <id> --targetname <name>
<driver> 表示要加载的驱动类型(一般为iscsi)
<id> 指定target的id号
<name> 指定iqn名称一般是iqn.日期.翻转域名.磁盘名称
创建一个target
[root@monitor ~]# tgtadm --lld iscsi --op new --mode target --tid=1 --targetname iqn.20150808.com.52itw:disk1
[root@monitor ~]#
查看当前建好的target
[root@monitor ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.20150808.com.52itw:disk1
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:
Account information:
ACL information:
[root@monitor ~]#
给target创建lun并且添加硬盘(可以多次执行添加多块,不过注意lun不可以重复出现)
[root@monitor ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 --backing-store /dev/sdb
[root@monitor ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 --backing-store /dev/sdc
创建ACL访问控制
[root@monitor ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 --initiator-address ALL
将tid绑定到特定的客户端IP,仅绑定的主机可以访问本iscsi,这里我们使用的all表示所有主机均可以访问
查看当target信息
[root@monitor ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.20150808.com.52itw:disk1
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: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb
Backing store flags:
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 21475 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdc
Backing store flags:
Account information:
ACL information:
ALL
[root@monitor ~]#
客户端挂载
安装iscsi客户端程序yum -y install iscsi-initiator-utils
[root@monitor ~]# iscsiadm --mode discoverydb --type sendtargets --portal 172.30.1.14 --discover
正在启动 iscsid: [确定]
172.30.1.14:3260,1 iqn.20150808.com.52itw:disk1 //检测到的iqn名称
[root@monitor ~]#
挂载iscsi磁盘
[root@monitor ~]# iscsiadm --mode node --targetname iqn.20150808.com.52itw:disk1 --portal 172.30.1.14:3260 --login
卸载iscsi磁盘
[root@monitor ~]# iscsiadm --mode node --targetname iqn.20150808.com.52itw:disk1 --portal 172.30.1.14:3260 --logoutLogging out of session [sid: 1, target: iqn.20150808.com.52itw:disk1, portal: 172.30.1.14,3260]Logout of [sid: 1, target: iqn.20150808.com.52itw:disk1, portal: 172.30.1.14,3260] successful.[root@monitor ~]#