Difference between revisions of "ISCSI Target (简体中文)"

From ArchWiki
Jump to navigation Jump to search
m
Line 7: Line 7:
 
{{Related|iSCSI Boot}}
 
{{Related|iSCSI Boot}}
 
{{Related articles end}}
 
{{Related articles end}}
{{TranslationStatus (简体中文)|ISCSI_Target|2014-08-01|327795}}
+
{{TranslationStatus (简体中文)|ISCSI_Target|2015-05-09|373078}}
 
{{Translateme (简体中文)}}
 
{{Translateme (简体中文)}}
 +
 
使用 [[Wikipedia:iSCSI|iSCSI]] 可以通过 IP 网络访问磁盘.  
 
使用 [[Wikipedia:iSCSI|iSCSI]] 可以通过 IP 网络访问磁盘.  
  
开放访问的存储是 '''目标(target)''',进行访问的机器称为 '''[[iSCSI Initiator|发起者(initiator)]]'''.有多种设置目标的方式:
+
提供受访的实体是 '''目标(target)''',发起访问的实体称为 '''[[iSCSI Initiator|发起者(initiator)]]'''。有多种设置目标的方式:
* [http://stgt.berlios.de/ SCSI Target Framework (STGT/TGT)] 是 2.6.38 之前的标准.
+
* [http://stgt.berlios.de/ SCSI Target Framework (STGT/TGT)] 是 Linux 2.6.38 之前的标准。
* [http://linux-iscsi.org/ LIO target] 是现在的标准.
+
* [http://linux-iscsi.org/ LIO target] 是现在的标准。
* [http://iscsitarget.sourceforge.net/ iSCSI Enterprise Target (IET)] 是旧的实现,[http://scst.sourceforge.net/ SCSI Target Subsystem (SCST)] 是 IET 的升级版本,后面有可能会加入内核。
+
* [http://iscsitarget.sourceforge.net/ iSCSI Enterprise Target (IET)] 是旧版本的实现,[http://scst.sourceforge.net/ SCSI Target Subsystem (SCST)] 是 IET 的升级版本,曾是 LIO 最终入选内核之前的候选方案之一。
  
== Setup with LIO Target ==
+
== 启用 LIO Target ==
LIO target is included in the kernel since 2.6.38. However, the iSCSI target fabric is included since linux 3.1.
+
LIO target 包含在2.6.38及以后版本的内核中。但从3.1版才开始包含 iSCSI target fabric。
  
The important kernel modules are ''target_core_mod'' and ''iscsi_target_mod'', which should be in the kernel and loaded automatically.
+
关键的内核模块是 ''target_core_mod'' ''iscsi_target_mod'',它们应该已内置并自动加载。
  
It is highly recommended to use the free branch versions of the packages: {{AUR|targetcli-fb}}, {{AUR|python-rtslib-fb}} and {{AUR|python-configshell-fb}}. The original {{AUR|targetcli}} is also available but has a different way of saving the configuration using the deprecated ''lio-utils'' and depends on ''epydoc''.
+
强烈建议使用 LIO 的免费分支版本:{{AUR|targetcli-fb}}{{AUR|python-rtslib-fb}} {{AUR|python-configshell-fb}}。原生包{{AUR|targetcli}}虽也有效,但其使用另外的方法保存配置,该方法使用不再推荐的 ''lio-utils'' 及依赖  ''epydoc''
  
A systemd {{ic|target.service}} is included in {{AUR|python-rtslib-fb}} when you use the free branch and a {{ic|/etc/rc.d/target}} in {{AUR|lio-utils}} when you use the original ''targetcli'' or ''lio-utils'' directly.
+
如果使用免费分支版本,则 {{AUR|python-rtslib-fb}} 中包含一个 systemd {{ic|target.service}} 文件。如果直接使用原生的 ''targetcli'' 或 ''lio-utils'',则在 {{AUR|lio-utils}} 中包含一个 {{ic|/etc/rc.d/target}}文件。
  
You start LIO target with {{bc|# systemctl start target}}
+
{{bc|# systemctl start target}} 命令启动 LIO target 。
This will load necessary modules, mount the configfs and load previously saved iscsi target configuration.
+
这样会加载必要的模块,挂载 configfs 并加载之前保存的 iscsi target 配置。
  
With {{bc|# targetcli status}} you can show some information about the running configuration (only with the free branch).
+
{{bc|# targetcli status}} 命令可以显示运行中的配置信息(仅免费分支版有效)。
  
You might want to enable the lio target on boot with {{bc|# systemctl enable target}}
+
若要 lio target 随系统引导时启动,可用 {{bc|# systemctl enable target}} 命令。
  
You can use '''targetcli''' to create the whole configuration or you can alternatively use the '''lio utils''' tcm_* and lio_* directly (deprecated).
+
可以用 '''targetcli''' 创建全部配置。也可以代之以直接使用 '''lio utils''' 中的 tcm_* lio_* (不推荐)。
  
=== Using targetcli ===
+
=== 使用 targetcli ===
The external manual is only available in the ''free branch''. [https://github.com/agrover/targetd targetd] is not in AUR yet, but this depends on the free branch.
+
外部使用手册仅对免费分支版有效。[https://github.com/agrover/targetd targetd] 尚未进入 AUR ,这取决于该免费分支。
  
The config shell creates most names and numbers for you automatically, but you can also provide your own settings.
+
用命令行式的配置工具可以自动生成绝大部分的名称和数值,但也支持自定义。
At any point in the shell you can type {{ic|help}} in order to see what commands you can issue here.
+
在配置工具中随时可以输入 {{ic|help}} 命令查看当前状态可用的命令。
{{Tip|You can use tab-completion in this shell}}
+
{{提示|配置工具命令行支持 TAB 键命令补全}}
{{Tip|You can type {{ic|cd}} in this shell to view & select paths}}
+
{{提示|配置工具命令行支持 {{ic|cd}} 命令查看和选择路径}}
  
After starting the target (see above) you enter the configuration shell with {{bc|# targetcli}}
+
target 启动以后,用下列命令进入配置工具:{{bc|# targetcli}}
In this shell you include a block device (here: {{ic|/dev/disk/by-id/md-name-nas:iscsi}}) to use with
+
在配置工具中,用下列命令启用一个块设备作为 target(此例为:{{ic|/dev/disk/by-id/md-name-nas:iscsi}}):
 
{{bc|/> cd backstores/block<br>/backstores/block> create md_block0 /dev/disk/by-id/md-name-nas:iscsi}}
 
{{bc|/> cd backstores/block<br>/backstores/block> create md_block0 /dev/disk/by-id/md-name-nas:iscsi}}
{{Note|You can use any block device, also raid and lvm devices. You can also use files when you go to fileio instead of block.}}
+
{{注意|任何块设备都可以用做 target,包括 RAID 和 LVM 设备。如果用 fileio 替换了 block,也可以将文件用作 target。}}
  
You then create an iSCSI Qualified Name (iqn) and a target portal group (tpg) with {{bc|...> cd /iscsi<br>/iscsi> create}}
+
然后,用下列命令创建一个“iSCSI 合格名称“(即 iSCSI Qualified Name,亦即所谓 iqn)和一个 target 入口组(target portal group,tpg)
{{Note|With appending an iqn of your choice to {{ic|create}} you can keep targetcli from automatically creating an iqn}}
+
{{bc|...> cd /iscsi<br>/iscsi> create}}
 +
{{注意|{{ic|create}}命令带 iqn 参数可自动创建 iqn}}
  
 
In order to tell LIO that your block device should get used as ''backstore'' for the target you issue
 
In order to tell LIO that your block device should get used as ''backstore'' for the target you issue
Line 74: Line 76:
 
{{Tip|You can give a filename as a parameter to {{ic|saveconfig}} and also clear a configuration with {{ic|clearconfig}}}}
 
{{Tip|You can give a filename as a parameter to {{ic|saveconfig}} and also clear a configuration with {{ic|clearconfig}}}}
  
==== Authentication ====
+
==== 认证 ====
 
Authentication per CHAP is enabled per default for your targets.
 
Authentication per CHAP is enabled per default for your targets.
 
You can either setup passwords or disable this authentication.
 
You can either setup passwords or disable this authentication.
  
===== Disable Authentication =====
+
===== 禁用认证 =====
 
Navigate targetcli to your target (i.e. /iscsi/iqn.../tpg1) and
 
Navigate targetcli to your target (i.e. /iscsi/iqn.../tpg1) and
 
  .../tpg1> set attribute authentication=0
 
  .../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.}}
 
{{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.}}
===== Set Credentials =====
+
===== 设置证书 =====
 
Navigate to a certain acl of your target (i.e. /iscsi/iqn.../tpg1/acls/iqn.../) and
 
Navigate to a certain acl of your target (i.e. /iscsi/iqn.../tpg1/acls/iqn.../) and
 
  ...> get auth
 
  ...> get auth
Line 90: Line 92:
 
Would enable authentication with foo:bar.
 
Would enable authentication with foo:bar.
  
=== Using (plain) LIO utils ===
+
=== 使用原生 LIO 工具 ===
 
You have to install {{AUR|lio-utils}} from [[AUR]] and the dependencies (python2).
 
You have to install {{AUR|lio-utils}} from [[AUR]] and the dependencies (python2).
  
=== Tips & Tricks ===
+
=== 提示与技巧 ===
 
* With {{ic|targetcli sessions}} you can list the current open sessions. This command is included in the {{AUR|targetcli-fb}} package, but not in ''lio-utils'' or the original ''targetcli''.
 
* With {{ic|targetcli sessions}} you can list the current open sessions. This command is included in the {{AUR|targetcli-fb}} package, but not in ''lio-utils'' or the original ''targetcli''.
  
=== Upstream Documentation ===
+
=== 上游文档 ===
 
* [http://www.linux-iscsi.org/wiki/Targetcli targetcli]
 
* [http://www.linux-iscsi.org/wiki/Targetcli targetcli]
 
* [http://www.linux-iscsi.org/wiki/Lio-utils_HOWTO LIO utils]
 
* [http://www.linux-iscsi.org/wiki/Lio-utils_HOWTO LIO utils]
 
* You can also use {{ic|man targetcli}} when you installed the ''free branch'' version {{AUR|targetcli-fb}}.
 
* You can also use {{ic|man targetcli}} when you installed the ''free branch'' version {{AUR|targetcli-fb}}.
  
== Setup with SCSI Target Framework (STGT/TGT) ==
+
== 使用 SCSI Target Framework (STGT/TGT) ==
 
You will need the Package {{AUR|tgt}} from [[AUR]].
 
You will need the Package {{AUR|tgt}} from [[AUR]].
  
 
See: [[TGT iSCSI Target]]
 
See: [[TGT iSCSI Target]]
  
== Setup with iSCSI Enterprise Target (IET) ==
+
== 使用 iSCSI Enterprise Target (IET) ==
 
You will need {{AUR|iscsitarget-kernel}} and {{AUR|iscsitarget-usr}} from [[AUR]].
 
You will need {{AUR|iscsitarget-kernel}} and {{AUR|iscsitarget-usr}} from [[AUR]].
  
=== Create the Target ===  
+
=== 创建 Target ===  
 
Modify /etc/iet/ietd.conf accordingly
 
Modify /etc/iet/ietd.conf accordingly
  
==== Hard Drive Target ====
+
==== 基于硬盘的 Target ====
 
  Target iqn.2010-06.ServerName:desc
 
  Target iqn.2010-06.ServerName:desc
 
  Lun 0 Path=/dev/sdX,Type=blockio
 
  Lun 0 Path=/dev/sdX,Type=blockio
  
==== File based Target ====
+
==== 基于文件的 Target ====
 
Use "dd" to create a file of the required size, this example is 10GB.
 
Use "dd" to create a file of the required size, this example is 10GB.
  
Line 124: Line 126:
 
  Lun 0 Path=/root/os.img,Type=fileio
 
  Lun 0 Path=/root/os.img,Type=fileio
  
=== Start server services ===
+
=== 启动服务 ===
 
{{Out of date|Mentions rc.d scripts and rc.conf.}}
 
{{Out of date|Mentions rc.d scripts and rc.conf.}}
 
  rc.d start iscsi-target
 
  rc.d start iscsi-target
Line 130: Line 132:
 
Also you can "iscsi-target" to DAEMONS in /etc/rc.conf so that it starts up during boot.
 
Also you can "iscsi-target" to DAEMONS in /etc/rc.conf so that it starts up during boot.
  
== See also ==
+
== 参阅 ==
 
* [[iSCSI Boot]] Booting Arch Linux with / on an iSCSI target.
 
* [[iSCSI Boot]] Booting Arch Linux with / on an iSCSI target.
 
* [[Persistent block device naming]] in order to use the correct block device for a target
 
* [[Persistent block device naming]] in order to use the correct block device for a target

Revision as of 13:21, 9 May 2015

翻译状态: 本文是英文页面 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

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

/> 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
注意: create命令带 iqn 参数可自动创建 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.

参阅