The introduction of three Linux SCSI target of STGT

 

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/scaleqiao/article/details/46706953

Recently doing a project and scsi target related, I take this opportunity to study a bit linux existing scsi target program, and put together a series of articles and share with you. Which has now introduced three commonly used scsi target include tgt (stgt), LIO and SCST, there is one pair they make a comparison, given the advantages and disadvantages. Start tgt started.

Linux target framework (tgt) is to provide support for the creation, maintenance SCSI target drivers (including iSCSI, FC, SRP, etc.). Its key objective is simple to integrate into scsi-mid layer, and application layer to achieve most tgt space. With Linux 2.6.38 as the dividing line, after the default Linux SCSI target is STGT, after the standard is Linux-IO Target.

1 architecture 

 

 


tgt kernel architecture has two modules: target driver and tgt core, after linux 2.6.38, the two modules have been removed linux kernel.
target driver function is a connection between the management device and the initiator, remove the SCSI command from the transport layer and to tgt core.
tgt core driver is the link tgt daemon and the target.
tgt daemon process to achieve a functional part of the SCSI protocol commands.
Target driver libraries are implemented in user mode access backend storage drive.
Transport libraries is implemented in user-mode transmission module.

 

2 Supported protocols and back-end storage

Stgt currently only supports iSCSI and iSER, FC and SRP's support is still in the state in progress.
Support and back-end storage FILEIO BLOCKIO, and also support the provision of library functions to access the stored ceph and GLFS

3 to configure and use

Configuration About tgt, including the establishment of target, add lun as target, set access control policy target and so on. Establish target includes two methods, based on command mode and file-based configuration mode, where the configuration file is /etc/tgt/targets.conf. First, based on the way the command, the command used here is tgtadm. tgtadm used to monitor and modify the Linux SCSI target software.

3.1 tgtadm

1a) 建立一个target
tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2012-01.cn.nayun:test-01
建立target需要提供target ID和名称,在一个网络内,target名称必须是唯一的,主要采用iqn-type格式和eui-type 格式表示,在Linux中主要用iqn-type格式,iqn是Internet限定名(Internet Qualified Name)的简称。iSCSI target命名采用“iqn.yyyy-mm.<反向的域名>:标识名”的形式,在上例中,所建立的target名称为iqn.2012-01.cn.nayun:test-01,其中cn.nayun为nayun.cn的反向,采用域名反向的方法主要是为了防止重名。

1b)查看所建立的target信息
$ tgtadm --lld iscsi --op show --mode target

1c)向target中添加LUN
$ tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb
关于使用tgt搭建一个基于rbd的SCSI target,请参见我的另一篇博文使用tgt搭建一个基于rbd的SCSI target

1d)设置target的访问控制策略
$ tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL  --网内所有Initiator均可访问
$ tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.210      --允许某个IP地址访问
$ tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.0/24     --允许某个网络访问 

1e)访问账号操作

建立新帐号
$tgtadm --lld iscsi --op new --mode account --user scott --password tiger

显示帐号信息
$tgtadm --lld iscsi --op show --mode account

将一个帐号与一个Target绑定(bind)
$tgtadm --lld iscsi --op bind --mode account --tid 1 --user scott

3.2 使用配置文件

通过tgtadm命令建立的target相关配置,在关闭机器后将不保存(也可以使用tgt-admin来持久化配置),通过配置文件的方式则可以保存Target相关信息,在系统重启时,tgtd守护进程从配置文件中提取配置信息,根据配置信息建立相应的Target。

Linux SCSI target framework (tgt)使用的配置文件为/etc/tgt/targets.conf,此配置文件采用XML格式保存Target配置信息,将上述通过tgtadm命令建立的Target在配置文件中的表示形式如下:        

<target iqn.2012-01.cn.nayun:test-01>
                backing-store /dev/sdb
                incominguser scott tiger
                initiator-address 192.168.1.0/24
                initiator-address 192.168.1.210
</target>

Guess you like

Origin www.cnblogs.com/pipci/p/11618650.html