Menu
InformatiWeb Pro
  • Index
  • System admin
  • Virtualization

Login

Registration Password lost ?
FR
  • Windows Server
    • WMS 2012
    • WS2012 R2
    • WS2016
  • Citrix
    • Citrix NetScaler Gateway
    • Citrix XenApp / XenDesktop
    • Citrix XenServer
  • VMware
    • VMware ESXi
    • VMware vSphere
    • VMware Workstation
  • Microsoft
    • Hyper-V
  • RAID
    • Adaptec SmartRAID
  • UPS
    • APC Back-UPS Pro
  • InformatiWeb Pro
  • System admin
  • Linux
  • Install and configure an iSCSI server and an iSCSI client on Debian / Ubuntu
  • Linux
  • 11 October 2016 at 13:43 UTC
  • InformatiWeb

Install and configure an iSCSI server and an iSCSI client on Debian / Ubuntu

The SCSI connector is used to connect SCSI hard drives in a server.
For the iSCSI is a SCSI emulation over TCP/IP network. So, the iSCSI allows you to use a hard drive over the network as if it were a real hard drive.

  1. iSCSI server installation (Target)
  2. Configure iSCSI shares
  3. Installation and configuration of the iSCSI client (Initiator)

1. iSCSI server installation (Target)

Before you begin, you must set a statuc IP address on the machine where you will install the iSCSI server.
For this, refer to one of these tutorials : Debian - Define a private static IP address ou Ubuntu - Define a private static IP address

To install an iSCSI server, you must install these packages :
- iscsitarget : tools to manage the iSCSI server
- iscsitarget-dkms : the kernel

Bash

apt-get install iscsitarget iscsitarget-dkms

During the installation, you will see this line :

Plain Text

[....] iscsitarget not enabled in "/etc/default/iscsitarget", not starting... ..[ (warning).

Once installation is complete, enable the iSCSI server by setting the "ISCSITARGET_ENABLE" variable to true.

Bash

vim /etc/default/iscsitarget

Plain Text

ISCSITARGET_ENABLE=true

2. Configure iSCSI shares

With iscsitarget, you can share :
- hard disks : /dev/sd*
- partitions : /dev/sd**
- LVM volumes : /dev/vg*/my_lv
- RAID volumes : /dev/md*

In our case, we will share a LVM volume.
If you don't know how to create a logical volume in LVM, follow our tutorial "Install and use the LVM on Linux" until the end of step 2.4 of the tutorial.

The configuration of iSCSI shares must be indicated in the file : /etc/iet/ietd.conf

Bash

vim /etc/iet/ietd.conf

In this file, you will find many comments and examples that are commented by default.

In this tutorial, we'll create a simple iSCSI share from a LVM logical volume.
Note that the logical volume to share over iSCSI should not be mounted.

If he is already mounted, use the "umount" command to unmount it.

To create a simple iSCSI share, you must indicate :
- a Target : it is the identifier of the iSCSI share.
The iSCSI RFC 3720 standard says that it's best to use the syntax : Target iqn.yyyy-mm.<reversed domain name>[:identifier]
yyyy-mm : it is the date of the creation of the iSCSI share.
<reversed domain name> : it's the domain name of the machine, but reversed. (You can invent if you wish)
[:identifier] : is the name of the iSCSI share.
- IncomingUser : login credentials for the iSCSI share. This is a CHAP authentication.
- Lun : informations about the volume to share. Path + share's type.

In our case, we'll add this iSCSI share :

Plain Text

Target iqn.2016-09.lan.informatiweb:mon_partage
   IncomingUser informatiweb my_password
   Lun 0 Path=/dev/iwvg/iw_vol1,Type=fileio

Then, restart the iSCSI server by typing this command :

Bash

/etc/init.d/iscsitarget restart

To verify that your shares are configured correctly, you can use this command :

Bash

cat /proc/net/iet/volume

If you get a result similar to this, is that your configuration is good.

Plain Text

tid:1 name:iqn.2016-09.lan.informatiweb:mon_partage
	lun:0 state:0 iotype:fileio iomode:wt blocks:104652800 blocksize:512 path:/dev/iwvg/iw_vol1

3. Installation and configuration of the iSCSI client (Initiator)

Before we begin, we recommend that you set a static IP address for the machine on which you install the iSCSI client.
Indeed, otherwise, the connection to the iSCSI server may not be performed properly. This also will cause an error for mounting iSCSI shares at startup with fstab.

To install an iSCSI client, you must install the open-iscsi package.

Bash

apt-get install open-iscsi

By default, the iSCSI client does not start automatically.
To automatically start the iSCSI client at startup, you must change the "node.startup" line of the "/etc/iscsi/iscsid.conf" file.

Bash

vim /etc/iscsi/iscsid.conf

Change the "node.startup" line like this :

Plain Text

node.startup = automatic

Then, restart the service.

Bash

/etc/init.d/open-iscsi restart

If the iSCSI server requires a CHAP authentication, you need to edit the "/etc/iscsi/iscsid.conf" file to allow your iSCSI client to connect to the iSCSI share of your server.
Note that you will find many interesting comments in this file.

Bash

vim /etc/iscsi/iscsid.conf

In this file, add this :

Plain Text

node.session.auth.authmethod = CHAP
node.session.auth.username = informatiweb
node.session.auth.password = my_password
discovery.sendtargets.auth.authmethod = CHAP
discovery.sendtargets.auth.username = informatiweb
discovery.sendtargets.auth.password = my_password

Then, to detect the available shares on your iSCSI server, use the "iscsiadm" command.
Note : 10.0.0.10 is the IP address of our iSCSI server.

Bash

iscsiadm -m discovery -t st -p 10.0.0.10

This command will show you a result similar to this :

Plain Text

10.0.0.10:3260,1 iqn.2016-09.lan.informatiweb:mon_partage

Note that the execution of the command "iscsiadm -m discovery ..." has generated a "iqn.../default" file in the "/etc/iscsi/nodes/" folder.
In this file, you will find the complete configuration for this iqn.
The configuration present in this file was copied from the file "iscsid.conf" during the execution of the discovery command.
So, it's important to configure the file "iscsid.conf" BEFORE starting the discovery.

Then, restart your iSCSI client.

Bash

/etc/init.d/open-iscsi restart

If you find a line similar to this one, your configuration is correct :

Plain Text

Login to [iface: default, target: iqn.2016-09.lan.informatiweb:mon_partage, portal: 10.0.0.10,3260] successful.

Once connected to the iSCSI server, a new hard drive will be available.
To find it, you can use the command

Bash

iscsiadm -m session -P 3

This command will show you information about the established iSCSI sessions including this :

Plain Text

Target: iqn.2016-09.lan.informatiweb:mon_partage
...
*****
CHAP:
*****
username: informatiweb
password: ********
username_in: <empty>
password_in: ********
...
************************
Attached SCSI devices:
************************
Host Number: 12	State: running
scsi12 Channel 00 Id 0 Lun: 0
Attached scsi disk sdb		State: running

At the end of this information, you will find that this iSCSI share will be usable as a SCSI hard drive (/dev/sdb).

Plain Text

Attached scsi disk sdb		State: running

For this tutorial, we will create a single primary partition on the entire disk with fdisk.
For more information about the partitioning of a hard drive with fdisk, refer to our tutorial : Partition your hard drive with fdisk.

Then, to store data on this iSCSI share, you have 2 options :
- Mount a partition of this "hard disk" (the disk obtained through the iSCSI connection) to a folder with the "mount" command.
- Or perform the mount at system startup through fstab.

To mount the first partition of the "hard drive" in a folder, use these commands :

Bash

mkdir /mnt/my_iscsi_disk
mount /dev/sdb1 /mnt/my_iscsi_disk

To automatically mount the hard drive at startup, create the folder in which the mount will be done, and then edit the "/etc/fstab" file.

Bash

mkdir /mnt/my_iscsi_disk
vim /etc/fstab

And add this :

Plain Text

/dev/sdb1     /mnt/my_iscsi_disk      ext4    _netdev 0       0

Note that we use the "_netdev" option to mount the partition (of the disk obtained through the iSCSI connection) once the network is available.

Now, the partition "/dev/sdb1" will be mounted at each startup of the machine.
However, to avoid restarting now you can use this command :

Plain Text

mount -a

When you restart your client machine, the mount will be done automatically at startup without problems.

Share this tutorial

Partager
Tweet

To see also

  • Debian / Ubuntu - Monitor your server with Monit

    Linux 12/20/2014

    Debian / Ubuntu - Monitor your server with Monit

  • OVH - KVM mode

    Linux 2/12/2016

    OVH - KVM mode

  • Ubuntu - Securing your dedicated server or VPS with Iptables

    Linux 2/28/2014

    Ubuntu - Securing your dedicated server or VPS with Iptables

  • Ubuntu - Update your server

    Linux 1/31/2014

    Ubuntu - Update your server

Comments

You must be logged in to post a comment

Share your opinion

Pinned content

  • Software (System admin)
  • Linux softwares
  • Our programs
  • Terms and conditions
  • Share your opinion

Contact

  • Guest book
  • Technical support
  • Contact

® InformatiWeb-Pro.net - InformatiWeb.net 2008-2022 - © Lionel Eppe - All rights reserved.

Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.