redhat:storage-server-redhat:iscsi-redhat

This is an old revision of the document!


Configure an iSCSI Target And Initiator In Linux

With an iSCSI target we can provide access to disk storage on a server over the network to a client iSCSI initiator. The iSCSI initiator will then be able to use the storage from the iSCSI target server as if it were a local disk.

Here we cover how you can set up both an iSCSI target and an iSCSI initiator in Linux and connect them together.

System Umgebungen

We will be working with two different Linux servers, both of which are running CentOS 7.

  • Client: 192.168.1.100: This Linux system acts as the iSCSI initiator, it will connect to the iSCSI target on the server over the network.
  • Server: 192.168.1.200: This Linux system acts as the iSCSI target server, it provides the disk space that will be accessible over the network to the client.

First we’ll start by configuring the iSCSI target on our server, which will be offering its disk space over the network to our client which is the iSCSI initiator.

We want to install the ‘targetcli’ package on the server, this provides a shell for viewing and modifying the target configuration so that we can export local storage resources such as files, volumes or RAM disks to external systems. The layout is tree based and navigation works in a similar way to moving through the file system with commands such as ‘cd’ and ‘ls’ available.

# yum install targetcli -y

Once installed we want to start the target service, and enable it so that it automatically starts up on system boot.

# systemctl start target
# systemctl enable target

For further information on basic service management with systemctl, see our guide here.

Now we can run the targetcli command, followed by ls from within the targetcli prompt to get an idea of what is available.

# targetcli

Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / .................................... [...]
  o- backstores ......................... [...]
  | o- block ............. [Storage Objects: 0]
  | o- fileio ............ [Storage Objects: 0]
  | o- pscsi ............. [Storage Objects: 0]
  | o- ramdisk ........... [Storage Objects: 0]
  o- iscsi ....................... [Targets: 0]
  o- loopback .................... [Targets: 0]

The targetcli command offers tab completion, so if you get stuck just press tab a couple of times to view available options. These will change depending on what level of the hierarchy you are in, and just like the file system you can always go up with ‘cd ..’.

The first thing listed are the backstores. Backstores provide different ways of storing the data locally that will be exported to an external system. The available options are block, fileio, pscsi and ramdisk. In our example we’ll be demonstrating both block and fileio options as these are quite common.

A block backstore is simply a Linux block device such as a hard drive like /dev/sdc.

A fileio backstore is a file on the file system that has been created with a predefined size, generally the performance of a single file is not as good as a block backstore.

To create a backstore, type the backstores command followed by the type that you want to create, such as fileio. If you get stuck put the tab completion to work. Here we are creating the testfile fileio backstore, this will make a 500MB /tmp/fileio file on disk, where write_back=false simply says to not use any caching which will decrease performance but will reduce possible data loss – a better option in a production environment.

/> backstores/fileio create testfile /tmp/fileio 500M write_back=false

Created fileio testfile with size 524288000

If you’re using a block device rather than a file, the command would look like this. In this example we are using the disk /dev/sdc as our backstore.

/> backstores/block create name=block dev=/dev/sdc

Created block storage object block using /dev/sdc.

Once complete if you issue the 'ls' command again and the backstores should be listed.

/> ls

o- / ...................................................... [...]
  o- backstores ........................................... [...]
  | o- block ............................... [Storage Objects: 1]
  | | o- block ....... [/dev/sdc (1.0GiB) write-thru deactivated]
  | o- fileio .............................. [Storage Objects: 1]
  | | o- testfile .. [/tmp/fileio (500.0MiB) write-thru deactivated]
  | o- pscsi ............................... [Storage Objects: 0]
  | o- ramdisk ............................. [Storage Objects: 0]
  o- iscsi ......................................... [Targets: 0]
  o- loopback ...................................... [Targets: 0]

Next we want to create the actual iSCSI target itself, start by moving into the iSCSI path as shown below. You don’t need to prepend the 'cd' command to access it, however that works as well.

/> iscsi/

Once in here, we can create the iSCSI target with a specific IQN (iqn.2017-09.com.example) and iSCSI target name (target).

/iscsi> create iqn.2016-01.com.example:target

Created target iqn.2016-01.com.example:target.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

Alternatively you can just enter 'create' by itself and it will automatically use a default IQN and target name, you don’t have to manually pick these however the option is nice.

Now if we run ls' again we should see our iSCSI target listed.

/iscsi> ls

o- iscsi ............................. [Targets: 1]
  o- iqn.2016-01.com.example:target ..... [TPGs: 1]
    o- tpg1 ................ [no-gen-acls, no-auth]
      o- acls ........................... [ACLs: 0]
      o- luns ........................... [LUNs: 0]
      o- portals ..................... [Portals: 1]
        o- 0.0.0.0:3260 ...................... [OK]

As we can see here, a portal has already been created. As of RHEL 7.1 once a target has been set, a default portal will also be configured which will listen on TCP port 3260 on 0.0.0.0.

FIXME


https://www.rootusers.com/how-to-configure-an-iscsi-target-and-initiator-in-linux/

  • redhat/storage-server-redhat/iscsi-redhat.1504275129.txt.gz
  • Last modified: 2017/09/01 16:12
  • by michael