歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下應用tgtadm構建iSCSI Target(SAN)

Linux下應用tgtadm構建iSCSI Target(SAN)

日期:2017/2/28 16:18:40   编辑:Linux教程

Linux target framework(tgt)是為創建、維護SCSI target 驅動(包括iSCSI、FC、SRP等)提供支持。它的關鍵目標是簡潔地集成到scsi-mid層,並且實現大部分應用層空間的tgt(The key goals are the clean integration into the scsi-mid layer and implementing a great portion of tgt in user space)。

IET(iSCSI Enterprise Target )的開發者幫助開發了Linux SCSI target framework(stgt),

The developer of IET is also helping to develop Linux SCSI target framework (stgt) which looks like it might lead to an iSCSI target implementation with an upstream kernel component.

iSCSI Target可以用來:

a]用來安裝stateless server/client (用於無盤安裝)

b]通過局域網、無線網絡或者因特網共享磁盤或者磁帶設備

c]安裝SAN——存儲陣列

d]通過Linux下的分布式文件系統實現負載均衡的web服務器集群

在這個教程中,將要學到如何通過tgt框架構建一個全功能的Linux iSCSI SAN。

iSCSI target(server)


存儲資源所在的iSCSI服務器被稱為“target”。iSCSI target通常是一個硬盤存儲設備。當前大部分的主流操作系統都提供了配合iSCSI target使用的客戶端軟件initiator。

iSCSI initiator(client)

initiator就是iSCSI傳輸的服務端。典型的initiator都有共同的目的,就是作為一個SCSI總線的適配器,代替物理上的SCSI設備(類似硬盤或者磁帶)。iSCSI initiator通過IP網絡傳輸SCSI命令。

CentOS / RHEL / Fedora 安裝tgt

$yum install scsi-target-utils

Debian / Ubuntu Linux 安裝tgt

$ sudo apt-get install tgt

tgtadm——Linux SCSI Target管理工具

tgtadm是用來監控、修改Linux SCSI target 的工具,包括target設置、卷設置,等等。這個工具允許提供為裝有SCSI initiator的其它操作系統提供塊級(block-level)的SCSI存儲。這個功能最初被部署為Linux iSCSI target,通過網絡向裝有iSCSI initiator的系統提供存儲服務。

啟動tgtd

啟動tgtd程序,可以輸入:

$/usr/sbin/tgtd

RHEL / CentOS 系統下可以啟動tgtd的服務程序,輸入:

$/etc/init.d/tgtd start

定義iSCSI target名

以下的例子中,創建了一個id為1的target,它的iqn為:iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz,並且添加了一個lun( logical unit)號為1的邏輯單元(由/dev/hdc1提供)

$ tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz

iqn號是局域網內iSCSI target的唯一標識,用來區分不同的target,所以在一個網絡內,iqn號一定不能相同

要顯示當前的iqn號,輸入:

$ tgtadm --lld iscsi --op show --mode target

通常輸出如下:

Target 1: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz
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
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
Account information:
ACL information:

為target增加一個lun(/dev/sdb1)

$ tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1

對於家用電腦或測試系統的注意事項:

大部分產品只是通過真正的iSCSI設備使用iSCSI root。但是對於測試目的,這將很有變得很有用,比如在你的圖片服務器上安裝一個iSCSI target。這樣,簡單的使用文件系系統,www.linuxidc.com在家中就可以測試、學習iSCSI target、initiator。使用dd 命令創建一個磁盤文件系統:

# dd if=/dev/zero of=/fs.iscsi.disk bs=1M count=512

創建了一個512M大小的文件/fs.iscsi.disk

把/fs.iscsi.disk當做一個lun加入到target中:

# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /fs.iscsi.disk

再查看lun信息:

# tgtadm --lld iscsi --op show --mode target

可以看到如下結果:

Target 1: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz
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
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 537 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /fs.iscsi.disk
Account information:
ACL information:

接受iSCSI initiator的訪問:

要使target接受initiator的訪問,需要輸入:

# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL

這樣將打開了3260端口

#netstat -tulpn | grep 3260

結果如下:

t
c
p 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 27328/tgtd
tcp6 0 0 :::3260 :::* LISTEN 27328/tgtd

當你做完這些操作,你的系統就被設置成一個iSCSI Target了。遠程的客戶端計算機就可以通過網絡訪問這台計算機上的硬盤了。你可以使用分布式的集群文件系統來安裝真正的共享存儲。如果需要的話,打開防火牆上的3260端口。

Copyright © Linux教程網 All Rights Reserved