Setup iSCSI Target & Initiator on CentOS 6


 

Ivan Mora Pérez | GNU/Linux, Storage | 5

 

iSCSI is a network protocol defined to allow scsi commands over TCP/IP stack, allowing to hosts I/O block operations like a device storage attached locally. With iSCSI we’ve to difference to basic concepts:

  • iSCSI initiator: is called the scsi client, and can be connected to the server of two ways:
    – Software initiator: Normally is implemented as a module that will used by the network interface and emulate scsi devices. Is the most implementation.
    – Hardware initiator: It use a dedicated hardware to implement iSCSI. The work load of the iSCSI process is handled by this hardware.
  • iSCSI target: references a storage resource located in a iSCSI server.

The servers (targets) have logical units or LUN, that is a number to identify a logical unit storage in the server and the client (initiator) negotiates the connection of a specified LUN with the target. In a iSCSI network each iSCSI element has a unique and permanent iSCSI name and is assigned and address for access. Normally to name an iSCSI element, is followed the IQN (iSCSI qualified name) format:

  • literal iqn
  • date (yyyy-mm) year and month
  • reversed domain name of the authority (org.alpinelinux, com.example, to.yp.cr)
  • “:” prefixing a storage target name specified by the naming authority.

iSCSI is the most commonly protocol used for the SAN (storage area network) because is cheaper than other protocols for network storage like FCoE (Fibre channel over ethernet). The problem of FCoE is that its traffic doesn’t travels above the IP layer of the protocol stack and its necessary special hardware to support FCoE to routed traffic.

SAN’s are very used to make storage devices accessible to the servers so that the devices appear like locally attached devices to the OS.

In this scenario I’ll configure on CentOS 6 an iSCSI target sharing an array disk device and other server as an iSCSI initiator that will map this device as local storage.

Configuring the iSCSI target

  • Install the software package:

# yum -y install scsi-target-utils

  • Edit target iSCSI configuration:

# vi /etc/tgt/targets.conf

<target iqn.2012-10.net.cpd:san.target01>

backing-store /dev/md0

initiator-address 172.16.201.201

incominguser iscsiadm iscsiadm123

</target>

  • Start the iSCSI target daemon and configure to startup at boot system:

# /etc/init.d/tgtd start

# chkconfig --levels 235 tgtd on

  • Add iptables rule to allow iSCSI traffic:

# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3260 -j ACCEPT

# service iptables restart

  • check the iSCSI target configuration:

# tgtadm --mode target --op show

Target 1: iqn.2012-10.net.cpd:san.target01

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, Block size: 1

Online: Yes

Removable media: No

Prevent removal: No

Readonly: No

Backing store type: null

Backing store path: None

Backing store flags:

Account information:

iSCSIadm

ACL information:

172.16.201.201

Configuring the iSCSI Initiator

  • Install the software package:

# yum -y install iscsi-initiator-utils

  • Configure the iqn name for the initiator:

# vi /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.2012-10.net.cpd:san.initiator01

InitiatorAlias=initiator01

  • Edit the iSCSI initiator configuration:

# vi /etc/iscsi/iscsid.conf

# To manually startup the session set to "manual". The default is automatic.

node.startup = automatic

# To enable CHAP authentication

node.session.auth.authmethod = CHAP

# To set a CHAP username and password for initiator

node.session.auth.username = iscsiadm

node.session.auth.password = iscsiadm123

  • Start iSCSI initiator daemon:

# /etc/init.d/iscsid start

# chkconfig --levels 235 iscsid on

  • Discovering targets in our iSCSI server:

# iscsiadm --mode discovery -t sendtargets --portal 172.16.201.200

172.16.201.200:3260,1 iqn.2012-10.net.cpd:san.target01

  • Trying to login with the iSCSI LUN:

# iscsiadm --mode node --targetname iqn.2012-10.net.cpd:san.target01 --portal 172.16.201.200 --login

Logging in to [iface: default, target: iqn.2012-10.net.cpd:san.target01, portal: 172.16.201.200,3260] (multiple)

Login to [iface: default, target: iqn.2012-10.net.cpd:san.target01, portal: 172.16.201.200,3260] successful.

With this command is reponsible of the update of  iSCSI targets database for the files located in /var/lib/iscsi/ :

# cat /var/lib/iscsi/send_targets/172.16.201.200,3260/st_config

discovery.startup = manual

discovery.type = sendtargets

discovery.sendtargets.address = 172.16.201.200

discovery.sendtargets.port = 3260

discovery.sendtargets.auth.authmethod = None

discovery.sendtargets.timeo.login_timeout = 15

discovery.sendtargets.use_discoveryd = No

discovery.sendtargets.discoveryd_poll_inval = 30

discovery.sendtargets.reopen_max = 5

discovery.sendtargets.timeo.auth_timeout = 45

discovery.sendtargets.timeo.active_timeout = 30

discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768

  • Checking the status session with the target:

# iscsiadm --mode session --op show

tcp: [2] 172.16.201.200:3260,1 iqn.2012-10.net.cpd:san.target01

Mounting automatically the iSCSI partitions at system boot

  • Create a new partition to our iSCSI disk and format it:

# fdisk -l

Disk /dev/sdb: 17.2 GB, 17171480576 bytes

64 heads, 32 sectors/track, 16376 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

# fdisk /dev/sdb

# mkfs.ext4 /dev/sdb1

  • Checking the UUID for disk:

# blkid /dev/sdb1

/dev/sdb1: UUID="71e86162-011d-49f1-9b4a-9f95a277e6b5" TYPE="ext4"

  • Add the next entry in /etc/fstab file:

UUID=71e86162-011d-49f1-9b4a-9f95a277e6b5 /mnt/data ext4 _netdev,rw 0 0

With the mount option _netdev the script netfs is responsible of the mount to this device. Without this option, Linux will try to mount this device before load the network support. We have to check that netfs is enabled to run in the default runlevels:

# chkconfig --list netfs

netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off

  • Mounting the new file system:

# mount -a -O _netdev

Initiator parameters configuration: http://www.open-iSCSI.org/docs/README

Thank for your comments

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s