ISCSI Target (简体中文)

From ArchWiki
Jump to navigation Jump to search
翻译状态: 本文是英文页面 ISCSI_Target翻译,最后翻译时间:2015-05-09,点击这里可以查看翻译后英文页面的改动。

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

使用 iSCSI 可以通过 IP 网络访问磁盘.

提供受访的实体是 目标(target),发起访问的实体称为 发起者(initiator)。有多种设置目标的方式:

启用 LIO Target

LIO target 包含在2.6.38及以后版本的内核中。但从3.1版才开始包含 iSCSI target fabric。

关键的内核模块是 target_core_modiscsi_target_mod,它们应该已内置并自动加载。

强烈建议使用 LIO 的免费分支版本:targetcli-fbAURpython-rtslib-fbAURpython-configshell-fbAUR。原生包targetcliAUR虽也有效,但其使用另外的方法保存配置,该方法使用不再推荐的 lio-utils 及依赖 epydoc

如果使用免费分支版本,则 python-rtslib-fbAUR 中包含一个 systemd target.service 文件。如果直接使用原生的 targetclilio-utils,则在 lio-utilsAUR 中包含一个 /etc/rc.d/target文件。

# systemctl start target

命令启动 LIO target 。

这样会加载必要的模块,挂载 configfs 并加载之前保存的 iscsi target 配置。

# targetcli status

命令可以显示运行中的配置信息(仅免费分支版有效)。 若要 lio target 随系统引导时启动,可用

# systemctl enable target

命令。

可以用 targetcli 创建全部配置。也可以代之以直接使用 lio utils 中的 tcm_* 和 lio_* (不推荐)。

使用 targetcli

外部使用手册仅对免费分支版有效。targetd 尚未进入 AUR ,这取决于该免费分支。

用命令行式的配置工具可以自动生成绝大部分的名称和数值,但也支持自定义。 在配置工具中随时可以输入 help 命令查看当前状态可用的命令。

提示: 配置工具命令行支持 TAB 键命令补全
提示: 配置工具命令行支持 cd 命令查看和选择路径

target 启动以后,用下列命令进入配置工具:

# targetcli

在配置工具中,用下列命令启用一个块设备(此例为:/dev/disk/by-id/md-name-nas:iscsi)作为 target:

/> cd backstores/block
/backstores/block> create md_block0 /dev/disk/by-id/md-name-nas:iscsi
注意: 任何块设备都可以用做 target,包括 RAID 和 LVM 设备。如果用 fileio 替换了 block,也可以将文件用作 target。

然后,用下列命令创建一个“iSCSI 合格名称“(即 iSCSI Qualified Name,亦即所谓 iqn)和一个 target 入口组(target portal group,tpg)

...> cd /iscsi
/iscsi> create
注意: With appending an iqn of your choice to create you can keep targetcli from automatically creating an iqn

In order to tell LIO that your block device should get used as backstore for the target you issue

Note: Remember that you can type cd to select the path of your <iqn>/tpg1
.../tpg1> cd luns
.../tpg1/luns> create /backstores/block/md_block0

Then you need to create a portal, making a daemon listen for incoming connections:

.../luns/lun0> cd ../../portals
.../portals> create

Targetcli will tell you the IP and port where LIO is listening for incoming connections (defaults to 0.0.0.0 (all)). You will need at least the IP for the clients. The port should be the standard port 3260.

In order for a client/initiator to connect you need to include the iqn of the initiator in the target configuration:

...> cd ../../acls
.../acls> create iqn.2005-03.org.open-iscsi:SERIAL

Instead of iqn.2005-03.org.open-iscsi:SERIAL you use the iqn of an initiator. It can normally be found in /etc/iscsi/initiatorname.iscsi. You have to do this for every initiator that needs to connect. Targetcli will automatically map the created lun to the newly created acl.

Note: You can change the mapped luns and whether the access should be rw or ro. See help create at this point in the targetcli shell.

The last thing you have to do in targetcli when everything works is saving the configuration with:

...> cd /
/> saveconfig

The will the configuration in /etc/target/saveconfig.json. You can now safely start and stop target.service without losing your configuration.

Tip: You can give a filename as a parameter to saveconfig and also clear a configuration with clearconfig

认证

Authentication per CHAP is enabled per default for your targets. You can either setup passwords or disable this authentication.

禁用认证

Navigate targetcli to your target (i.e. /iscsi/iqn.../tpg1) and

.../tpg1> set attribute authentication=0
Warning: With this setting everybody that knows the iqn of one of your clients (initiators) can access the target. This is for testing or home purposes only.
设置证书

Navigate to a certain acl of your target (i.e. /iscsi/iqn.../tpg1/acls/iqn.../) and

...> get auth

will show you the current authentication credentials.

...> set auth userid=foo
...> set auth password=bar

Would enable authentication with foo:bar.

使用原生 LIO 工具

You have to install lio-utilsAUR from AUR and the dependencies (python2).

提示与技巧

  • With targetcli sessions you can list the current open sessions. This command is included in the targetcli-fbAUR package, but not in lio-utils or the original targetcli.

上游文档

使用 SCSI Target Framework (STGT/TGT)

You will need the Package tgtAUR from AUR.

See: TGT iSCSI Target

使用 iSCSI Enterprise Target (IET)

You will need iscsitarget-kernelAUR and iscsitarget-usrAUR from AUR.

创建 Target

Modify /etc/iet/ietd.conf accordingly

基于硬盘的 Target

Target iqn.2010-06.ServerName:desc
Lun 0 Path=/dev/sdX,Type=blockio

基于文件的 Target

Use "dd" to create a file of the required size, this example is 10GB.

dd if=/dev/zero of=/root/os.img bs=1G count=10
Target iqn.2010-06.ServerName:desc
Lun 0 Path=/root/os.img,Type=fileio

启动服务

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Mentions rc.d scripts and rc.conf. (Discuss in Talk:ISCSI Target (简体中文)#)
rc.d start iscsi-target

Also you can "iscsi-target" to DAEMONS in /etc/rc.conf so that it starts up during boot.

参阅