web hosting

Remco Bressers' Comfort zone

Running an iSCSI SAN on CentOS 5

Running iSCSI target on a Fedora system is as easy as “yum install iscsitarget” and configure the thing. Unfortunatly, on CentOS, the iSCSI Enterprise Target (IET) daemon is not in the default Yum repositories, because CentOS usually uses TGT (Linux SCSI Target Framework).

Ok, i could dive into using TGT on a CentOS box, but that’s not what i wanted to use on a corporate SAN. So, let’s find it out the hard way and build from source.

The iSCSI Target system

First, some prerequisites :

# yum install kernel-devel openssl-devel gcc rpm-build

Download the latest IET from the Sourceforge repo and put the tgz in /usr/src

# cd /usr/src
# tar xvf iscsitarget-0.4.15.tar.gz
# cd iscsitarget-0.4.15
# make
# make install

Alright. IETD is installed and ready to use. The iscsi-target init.d script is installed and will be started at boot-time. Nice! One bad thing is, that every time you install a new kernel, you need to recompile ietd. Write this down on your forehead or somewhere you will look at every single day :-)

Configuring ietd is a piece of cake if the documentation would be easy findable, but it isn’t (or wasn’t).
First, lets decide who can connect to the IET daemon :

# vi /etc/initiators.allow
iqn.2008-07.my-sanhead:mydiskname 192.168.1.0/24

Yep, quite a strange string. It’s called an IQN (iscsi qualified name) and i use this naming convention:
iqn.<year>-<month>.<hostname>:<LVM diskname>
The IQN is an identifier for your iSCSI target. A target can consist of multiple disks and/or lun’s. The iSCSI initiator uses the IQN to connect to these disks/lun’s. The subnet 192.168.1.0/24 is allowed to use this iSCSI target.

Next, we’ll create the initiators.deny file, which is pretty straightforward :

 # vi /etc/initiators.deny
ALL:ALL

Time to create the IQN in the ietd configuration file.

# vi /etc/ietd.conf
Target iqn.2008-07.my-sanhead:mydiskname
        IncomingUser username 12345
        OutgoingUser username 123456789012
        Lun 0 Path=/dev/SAN/diskname,Type=fileio,IOMode=wb
        Alias iSCSI for diskname
        ImmediateData Yes
        MaxConnections 1
        InitialR2T Yes

I use the following conventions, as defined in the RFC :

For IncomingUser: Password always 5 characters
For OutgoingUser: Password always 12 characters

I use LVM as a disk backend. The disk can also be /dev/sdb or whatsoever.


The iSCSI Initiator

For the initiator, we’re also going to use a CentOS system, as this is my OS of choice. In Ubuntu/Debian/Fedora/Whatever-linux-u-may-have there usually is an open-iscsi in the repository. If not, you can always compile it from source at http://www.open-iscsi.org.

Let’s install the prerequisites :

# yum install iscsi-initiator-utils
# yum install open-iscsi

Next, define the initiatorname. This is in the exact same form as the targetname, but it should not be the same. This initiatorname is the name (in IQN) of your computer.

# vi /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2008-07.mydesktoppc:someuniquename

Next, we’re going to configure the authentication and some specials in the iscsid config.

# vi /etc/iscsi/iscsid.conf

node.startup = automatic
node.session.auth.authmethod = CHAP
node.session.auth.username = username
node.session.auth.password = 12345
node.session.auth.username_in = username
node.session.auth.password_in = 123456789012
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.initial_login_retry_max = 10
node.session.cmds_max = 128
node.session.queue_depth = 32
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 = 131072
discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
node.session.iscsi.FastAbort = No

For more information about these setting, please refer to the open-iscsi page.
Next up, start the thing :

# service iscsi start

Bingo! You just started the iSCSI daemon (all cheer). Now, we’re going to discover our targets on the target iSCSI host. I assume 192.168.1.1 is the target host in this example.

# iscsiadm -m discovery -t st -p 192.168.1.1
192.168.1.1:3260,1 iqn.2008-7.my-sanhead:mydiskname

As you can see, it found the target we created before. Now, let’s login to it:

# iscsiadm -m node -p 192.168.1.1  -T iqn.2008-7.my-sanhead:mydiskname --login

Et voila! If you do a ‘dmesg’ on your box, you will find a new disk inserted (/dev/sdc or whatever).

Have fun!

Category: SysAdmin

6 Responses to Running an iSCSI SAN on CentOS 5

  1. zahid haseeb

    its a nice help above. i have few questions.

    1.) where will we define the drive/luns space(like i want to define 4GB of luns) ?
    2.) is it possible that i can get the rpm of iscsitarget-0.4.15 for centos5?

    you any reply will be appriciated………

    Thanks
    Zahid Haseeb

    @Remco Bressers

  2. WC Epperson

    “The iscsi-target init.d script is installed and will be started at boot-time.”

    Not necessarily. On Centos 5.5, /etc/init.d/iscsi-target was created, but not linked to any runlevel.

    chkconfig –add iscsi-target
    chkconfig iscsi-target on

  3. Podolak

    I would just like to point out that in release 1.4.20.2 the configuration files are in /etc/iet

    If you create configuration files in /etc they will not be recognized by IET. So the paths would be:

    /etc/iet/initiators.allow
    /etc/iet/ietd.conf

    I do not know which release this started with, the last time I built an IET SAN was a few years ago.

  4. el-kozik

    Hi,
    I would like to ask how can I add this ISCSI target to Windows 2008 R2?? I don’t known what I need write in CHAP Username and Secret in ISCSI Initiator on Windows 2008

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>