Linux tgtadm:setup ISCSI Target (SAN)

Source: Internet
Author: User

Linux Target Framework (TGT) aims to simplify various SCSI target driver (ISCSI, Fibre Channel, SRP, etc) creation and Mai Ntenance. The key goals is the clean integration to 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 leads to an CSI 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'll learn how to has a fully functional Linux ISCSI SAN using the 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 a 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 Physicall Y Cabling SCSI devices (like hard drives and tape changers), a 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 tgtcentos/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 has a SCSI initiator. This capability was 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 startDefine an iSCSI target name

The following example creates a target with ID 1 (the IQN is iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz) and Adds a 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/sdb1A Note about Home computer/test system

Most production boxes would only have use of iSCSI root with real iSCSI devices, but for testing purposes it can quite useful to Set up a 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 Purpos E. 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, your 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'll run into problems if SELinux is enabled if using files. While adding a logicalunit to a target you'll 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/tgtdtcp6       0      0::: 3260                 :::*                    LISTEN      27328/TGTD      

And you were 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 GKFX storage for small business. Open TCP Port 3260 in your firewall, if required. How does I access iSCSI Target (server) via iSCSI initiator (client)?

See detailed OS specific ISCSI initiator instuctions:

    1. Rhel 4 or Rhel 5 Linux iSCSI Initiator tutorial.
    2. Debian Linux ISCSI Initiator tutorial.
    3. FreeBSD ISCSI Initiator Tutorial.
    4. Windows ISCSI Initiator Tutorial.

Following is a quick-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 @ 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. Login was successful:
# tail -f /var/log/messages
Sample output:

Nov 07:34:04 vivek-desktop kernel: [9039.562312] scsi 6:0:0:1: direct-access IET virtual-disk 0001 pq:0 Ansi:5nov 07:34:04 vivek-desktop kernel: [9039.572268] SD 6:0:0:1: [SDC] 1048576 512-byte Hardware sectors (537 MB) No V One 07:34:04 vivek-desktop kernel: [9039.572374] SD 6:0:0:1: [SDC] Write Protect is Offnov one 07:34:04 vivek-desktop ker  Nel: [9039.572530] SD 6:0:0:1: [SDC] Write cache:enabled, read cache:enabled, doesn ' t support DPO or Fuanov 11 07:34:04 Vivek-desktop kernel: [9039.572715] SD 6:0:0:1: [SDC] 1048576 512-byte Hardware sectors (537 MB) Nov 07:34:04 vivek-de  Sktop kernel: [9039.572790] SD 6:0:0:1: [SDC] Write Protect is Offnov one 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 Fuanov one 07:34:04 vivek-desktop kernel: [9039.572946] Sdc:unknown partition Tablenov one 07:34:04 vivek-desktop kernel: [9039.573492] SD 6:0:0:1: [SDC] Attach Ed SCSI Disknov 11 07:34: Vivek-desktop kernel: [9039.573593] SD 6:0:0:1: attached SCSI generic SG4 type 0 

SDC is new SCSI disk. Need to restart iSCSI to probe partition and check disks:
# service ISCSI Restart
# partprobe
# FDI Sk-l

You can now create parition and mount file system using usual Fdisk and MKFS.EXT3 commands:
# FDI SK/DEV/SDC
# MKFS.EXT3/DEV/SDC1MKDIR/ISCSI
# MKDIR/ISCSI
# MOUNT/DEV/SDC1/ISCSI
# df-h

Sampl E Output:

Filesystem             Size   used  Avail use% mounted on/dev/sda2               99G    30G    64G  32%/tmpfs                  1.1G      0   1.1G   0%/lib/init/rwvarrun                 1.1G   361k   1.1G   1%/var/runvarlock                1.1G      0   1.1G   0%/var/lockudev                   1.1G   2.9M   1.1G   1%/devtmpfs                  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:
    • Mans Page Tgtadm
    • TGT Project
    • ISCSI article from the Wikipedia
Debian/ubuntu Linux Connect to an ISCSI Volume

Q. How does I format and connect to an ISCSI Volume under Debian/ubuntu Linux?

A. You need to the install OPEN-ISCSI package for the high performance, transport independent iSCSI implementation under Debian/ Ubuntu Linux. This is also known as the Linux OPEN-ISCSI initiator. You need the 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-iscsiOPEN-ISCSI default configuration

You need to Soft-link (path fix) Few the 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 the 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 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 restartFormat ISCSI Volume

Now you should see a 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.