Linux tgtadm: Setup iSCSI Target ( SAN )

Linux target framework (tgt) aims to simplify various SCSI target driver (iSCSI, Fibre Channel, SRP, etc) creation and maintenance. The key goals are the clean integration into the scsi-mid layer and implementing a great portion of tgt in user space.
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 can be useful:
a] To setup stateless server / client (used in diskless setups).
b] Share disks and tape drives with remote client over LAN, Wan or the Internet.
c] Setup SAN - Storage array.
d] To setup loadbalanced webcluser using cluster aware Linux file system etc.
In this tutorial you will learn how to have a fully functional Linux iSCSI SAN using tgt framework.
iSCSI target (server)
Storage resource located on an iSCSI server known as a "target". An iSCSI target usually represents nothing but hard disk storage. As with initiators, software to provide an iSCSI target is available for most mainstream operating systems.
iSCSI initiator (client)
An initiator functions as an iSCSI client. An initiator typically serves the same purpose to a computer as a SCSI bus adapter would, except that instead of physically cabling SCSI devices (like hard drives and tape changers), an iSCSI initiator sends SCSI commands over an IP network.
Debian / Ubuntu Linux Install tgt
Type the following command to install Linux target framework user-space tools:$ sudo apt-get install tgt
CentOS / RHEL / Red Hat Linux Install tgt
RHEL 5.2 and older version do not have tgt tools. However, RHEL 5.3 (preview version) comes with tgt tools.
tgtadm - Linux SCSI Target Administration Utility
tgtadm is used to monitor and modify everything about Linux SCSI target software: targets, volumes, etc. This tool allows a system to serve block-level SCSI storage to other systems that have a SCSI initiator. This capability is being initially deployed as a Linux iSCSI target, serving storage over a network to any iSCSI initiator.
Start tgtd
To start the tgtd, enter:# /usr/sbin/tgtd
Under RHEL 5.3 to start the tgtd service, enter:# /etc/init.d/tgtd start
Define an iscsi target name
The following example creates a target with id 1 (the iqn is 19 iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz) and adds a 20 logical unit (backed by /dev/hdc1) with lun 1.# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz
To view the current configuration, enter:# tgtadm --lld iscsi --op show --mode target
Sample output:
Target 1: iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
System information:
Driver: iscsi
Status: running
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0
Online: No
Poweron/Reset: Yes
Removable media: No
Backing store: No backing store
Account information:
ACL information:
Add a logical unit to the target (/dev/sdb1):# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
A note about home computer / test system
Most production boxes will only use iSCSI root with real iSCSI devices, but for testing purposes it can be quite useful to set up an iSCSI target on your image server. This is useful for testing and learning iSCSI target and iSCSI initiator at home, simply use filesystem for testing purpose. Use dd command to create diskbased filesystem:# dd if=/dev/zero of=/fs.iscsi.disk bs=1M count=512
Add /fs.iscsi.disk as a logical unit to the target:# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /fs.iscsi.disk
Now, you should able to view details:# tgtadm --lld iscsi --op show --mode target
Sample output:
Target 1: iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
System information:
Driver: iscsi
Status: running
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0
Online: No
Poweron/Reset: Yes
Removable media: No
Backing store: No backing store
LUN: 1
Type: disk
SCSI ID: deadbeaf1:1
SCSI SN: beaf11
Size: 512M
Online: Yes
Poweron/Reset: Yes
Removable media: No
Backing store: /fs.iscsi.disk
Account information:
ACL information:
A Note About Selinux
Renout Gerrits adds - On RHEL and friends you will run into problems if selinux is enabled if using files. While adding a logicalunit to a target you will get the error: 'tgtadm: invalid request'. A bit of a misguiding error. fixed by setting the correct context:# semanage fcontext -a -t tgtd_var_lib_t /fs.iscsi.disk
# restorecon -Rv /fs.iscsi.disk
Accept iSCSI Target
To enable the target to accept any initiators, enter:# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
This should open network port # 3260:# netstat -tulpn | grep 3260
Sample output:
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 27328/tgtd
tcp6 0 0 :::3260 :::* LISTEN 27328/tgtd
And you are done. Your system is configured as iSCSI Target. Remote client computer can access this computers hard disk over network. Your can use cluster aware filesystem to setup real shared storage for small business. Open TCP port 3260 in your firewall, if required.
How do I access iSCSI Target (server) via iSCSI initiator (client)?
See detailed os specific iSCSI initiator instuctions:
- RHEL 4 or RHEL 5 Linux iSCSI initiator tutorial.
- Debian Linux iSCSI initiator tutorial.
- FreeBSD iSCSI initiator tutorial.
- Windows iSCSI initiator tutorial.
Following is a quick way to access iSCSI target, under RHEL 5. Let us say your server iSCSI Target IP is 192.168.1.2. Type the following command to discover targets at a given IP address such as 192.168.1.2 (use 127.0.0.1 if you are testing it from same computer):# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.2
OR# iscsiadm --mode discovery --type sendtargets --portal 127.0.0.1
Sample output:
127.0.0.1:3260,1 iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz
Login to the iscsi target session:# iscsiadm --mode node --targetname iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz --portal 192.168.1.2:3260 --login
OR# iscsiadm --mode node --targetname iqn.2001-04.com.example:storage.disk1.amiens.sys1.xyz --portal 127.0.0.1:3260 --login
Verify that login was successful:# tail -f /var/log/messages
Sample output:
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.562312] scsi 6:0:0:1: Direct-Access IET VIRTUAL-DISK 0001 PQ: 0 ANSI: 5
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572268] sd 6:0:0:1: [sdc] 1048576 512-byte hardware sectors (537 MB)
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572374] sd 6:0:0:1: [sdc] Write Protect is off
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572530] sd 6:0:0:1: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572715] sd 6:0:0:1: [sdc] 1048576 512-byte hardware sectors (537 MB)
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572790] sd 6:0:0:1: [sdc] Write Protect is off
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572940] sd 6:0:0:1: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.572946] sdc: unknown partition table
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.573492] sd 6:0:0:1: [sdc] Attached SCSI disk
Nov 11 07:34:04 vivek-desktop kernel: [ 9039.573593] sd 6:0:0:1: Attached scsi generic sg4 type 0
sdc is new scsi disk. You may need to restart iSCSI to probe partition and check disks:# service iscsi restart
# partprobe
# fdisk -l
You can now create parition and mount file system using usual fdisk and mkfs.ext3 commands:# fdisk /dev/sdc
# mkfs.ext3 /dev/sdc1mkdir /iscsi
# mkdir /iscsi
# mount /dev/sdc1 /iscsi
# df -H
Sample output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 99G 30G 64G 32% /
tmpfs 1.1G 0 1.1G 0% /lib/init/rw
varrun 1.1G 361k 1.1G 1% /var/run
varlock 1.1G 0 1.1G 0% /var/lock
udev 1.1G 2.9M 1.1G 1% /dev
tmpfs 1.1G 312k 1.1G 1% /dev/shm
/dev/sda1 105G 32G 73G 31% /media/sda1
/dev/sda5 294G 275G 20G 94% /share
/dev/sdb2 247G 119G 116G 51% /disk1p2
/dev/sdc1 520M 11M 483M 3% /iscsi
References:
- man page tgtadm
- tgt project
- iSCSI article from the wikipedia
Debian / Ubuntu Linux Connect to an iSCSI Volume
Q. How do I format and connect to an iSCSI Volume under Debian / Ubuntu Linux?
A. You need to install open-iscsi package for high performance, transport independent iSCSI implementation under Debian / Ubuntu Linux. This package is also known as the Linux Open-iSCSI Initiator. You need Linux operating system with kernel version 2.6.16, or later. See REHL 5 / CentOS 5 / Fedora Linux specific instructions here.
Install Open-iSCSI Initiator
Type the following command at a shell prompt:$ sudo apt-get install open-iscsi
Open-iSCSI default configuration
You need to soft-link (path fix) few two files to autologin work i.e. fix file paths for iscsiadm, enter:ln -s /etc/{iscsid.conf,initiatorname.iscsi} /etc/iscsi/
Default configuration file could be located at /etc/iscsi/iscsid.conf or ~/.iscsid.conf. Open /etc/iscsi/iscsid.conf file:# vi /etc/iscsi/iscsid.conf
Set node.session.auth.username, node.session.auth.password and other parameter as follows:node.startup = automatic
node.session.auth.username = MY-ISCSI-USER
node.session.auth.password = MY-ISCSI-PASSWORD
discovery.sendtargets.auth.username = MY-ISCSI-USER
discovery.sendtargets.auth.password = MY-ISCSI-PASSWORD
node.session.timeo.replacement_timeout = 120
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.noop_out_interval = 10
node.conn[0].timeo.noop_out_timeout = 15
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.conn[0].iscsi.MaxRecvDataSegmentLength = 65536
Save and close the file. Restart open-iscsi service:# /etc/init.d/open-iscsi restart
Now you need to run a discovery against the iscsi target host:# iscsiadm -m discovery -t sendtargets -p ISCSI-SERVER-IP-ADDRESS
If 192.168.1.60 is iSCSI server IP address, enter:# iscsiadm -m discovery -t sendtargets -p 192.168.1.60
OR# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.60
Note down the record id (such as iqn.2001-05.com.doe:test) found by the discovery. You need the same for login. Login, must use a node record id found by the discovery:# iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.60:3260 --login
Finally restart the service again:# /etc/init.d/open-iscsi restart
Format iSCSI Volume
Now you should see an additional drive on the system such as /dev/sdc. Use /var/log/messages file to find out device name:# tail -f /var/log/messages
If your device name is /dev/sdc, enter the following command to create a partition:# fdisk /dev/sdc
Next format partition:# mkfs.ext3 /dev/sdc1
Mount file system:# mkdir /iscsi
# mount /dev/sdc1 /iscsi
Linux tgtadm: Setup iSCSI Target ( SAN )的更多相关文章
- Linux 如何通过 iscsi target name 获取 ip
by Mike Andrews # lsscsi -t [:::] disk iqn.-.com.blockbridge:t-pjxfzufjkp-illoghjk,t,0x1 /dev/sda [: ...
- 使用iSCSI Target创建集中式安全存储(一)
iSCSI 是一种块级别的协议,用于通过TCP/IP网络共享原始存储设备,可以用已经存在的IP和以太网如网卡.交换机.路由器等通过iSCSI协议共享和访问存储.iSCSI target是一种由远程iS ...
- iscsi介绍及iscsi target配置
iSCSI 主要是透过 TCP/IP 的技术,将储存设备端透过 iSCSI target (iSCSI 目标) 功能,做成可以提供磁盘的服务器端,再透过 iSCSI initiator (iSCSI ...
- CentOS7 下安装 iSCSI Target(tgt) ,使用 Ceph rbd
目录 一.iSCSI 介绍 1. iSCSI 定义 2. 几种常见的 iSCSI Target 3. 优缺点比较 二.安装步骤 1. 关闭防火墙 2. 关闭selinux 3. 通过 yum 安装 t ...
- iscsi target 之LIO配置
LIO 配置 现在主流Linux都可以设置iSCSI,如STGT/TGT.LIO Target等.Linux-IO(LIO)Target是当前Linux标准的iSCSI target的开源实现,包含在 ...
- centos 6.5环境利用iscsi搭建SAN网络存储服务及服务端target和客户端initiator配置详解
一.简介 iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够 ...
- Linux下搭建iSCSI共享存储的方法 Linux-IO Target 方式CentOS7-1810下实现
iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速 ...
- Linux下搭建iSCSI共享存储的方法 Linux-IO Target 方式 Debian9.5下实现
iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速 ...
- linux iSCSI target/initiator配置
linux iSCSI target配置全过程一:Install iSCSI target for Linux1,操作系统:[root@rac2 ~]# cat /etc/issueEnterpris ...
随机推荐
- 19-05【icloud】照片备份
icloud提供了免费的存储空间,5G,超过这个量需要单独购买空间:我用的是50G,每月6元. 如果在mac或者iphone上开启了本地的照片流,则会自动同步到icloud,同时各个设备的客户端(ip ...
- 用C语言编写一个简单的词法分析程序
问题描述: 用C或C++语言编写一个简单的词法分析程序,扫描C语言小子集的源程序,根据给定的词法规则,识别单词,填写相应的表.如果产生词法错误,则显示错误信息.位置,并试图从错误中恢复.简单的恢复方法 ...
- python 聊天程序(基于UDP)
from threading import Thread from socket import * updSocket = socket(AF_INET,SOCK_DGRAM) updSocket.b ...
- Unity3D-RayMarch-几何图元-3添加阴影
效果图: 在RayMarch渲染算法中计算阴影非常简单,当射线碰撞到物体,从碰撞点逆着光源方向再次执行射线步进算法,如果这一过程中碰撞到了其他物体,则碰撞点被其他物体遮挡,该处具有阴影. shader ...
- 利用css实现带有省略号的段落
带有省略号的段落就是你只能在一行显示一段文字,文字过长是肯定不能完全显示的,如果默认的话,超出的文字会自动换行,撑大盒子. 1.这时需要设置white-space: nowrap,禁止换行.这样的话, ...
- js 内置对象参考 (Array,String, Math, Data, Number)
var str = "helloWorld"; var strOne = "helloWorld"; // charAt() 返回在指定位置的字符. var a ...
- CSS样式内容
CSS代码规范:尽量不要在标签内使用样式代码. .css文档内部声明不换行可以节省内存. 谨记: 常犯的错误是.html文档和.css样式表都写好了,但总会忘记插入样式表. 1.字体的样式 2. ...
- eclipse创建scrapy项目
1. 您必须创建一个新的Scrapy项目. 进入您打算存储代码的目录中(比如否F:/demo),运行下列命令: scrapy startproject tutorial 2.在eclipse中创建一个 ...
- 最小化webpack项目
先把代码贴出来,以后慢慢加说明 参考资料:入门 Webpack,看这篇就够了 / webpack 搭建自动打开,刷新浏览器 一.功能代码1.index.html <!DOCTYPE html&g ...
- p2p技术之n2n源码核心简单分析一
首先在开篇之前介绍下内网打洞原理 场景:一个服务器S1在公网上有一个IP,两个私网机器C1,C2 C1,C2分别由NAT1和NAT2连接到公网,我们需要借助S1将C1,C2建立直接的TCP连接,即由C ...