When I installed HA extension in SLES 12 SP1, I used iSCSI Target as STONITH Block Device and I noticed that is a little bit different from SLES 11.

This is how I done it using: targetcli

Before all, we need be familiar with some concepts, the definitions according with the manpage targetcli(8) are:

Backstores
Backstores are different kinds of local storage resources that the kernel target uses to “back” the SCSI devices it exports. The mappings to local storage resources that each backstore creates are called storage objects.

Targets
Targets are instances of a fabric, which adapts the kernel target to a specific transport protocol such as iSCSI, Fibre Channel, or SBP-2. Creating a target in targetcli enables that target to be configured. The name of the target, its WWN (world wide name), may link the configuration to a specific hardware endpoint, like SRP for example, or it may not, like iSCSI.

iSCSI / Portals
An iSCSI target may be reached via multiple IP addresses and ports. These addr:port pairs are called portals. Both IPv4 and IPv6 addresses are supported.

iSCSI / Luns
The kernel target exports SCSI Logical Units, also called LUNs. This section links the previously-defined storage objects with the target, and defines which number (the Logical Unit Number) the device will use. Note that if ACLs are being used, a lun mapping must be created under the ACL that refers back to the TPG LUN.

iSCSI / Acls
ACLs (Access Control Lists) allow different configuration, depending on the initiator that is connecting to the target. This includes both per-initiator authentication settings as well as per-initiator LUN mappings.

In this demo, I'll use only two servers:

+---------------+      +---------------+
|    SERVER     |      |    CLIENT     |
|192.168.124.10 |      |192.168.124.20 |
+---------------+      +---------------+

Install packages

In server
# zypper in open-iscsi yast2-iscsi-lio-server targetcli

In client
# zypper in open-iscsi

Create an image

In server dump a blank image called: stonith.img

server:~ # dd if=/dev/zero of=/root/stonith.img bs=100M count=1
1+0 records in
1+0 records out
104857600 bytes (105 MB) copied, 0.433633 s, 242 MB/s
server:~ # ls -lah /root/stonith.img
-rw-r--r-- 1 root root 100M Jul  6 22:02 /root/stonith.img
server:~ #

Configure iSCSI Target

In server

server:~ # targetcli ls
o- / ....................................... [...]
  o- backstores ............................ [...]
  | o- fileio ................. [0 Storage Object]
  | o- iblock ................. [0 Storage Object]
  | o- pscsi .................. [0 Storage Object]
  | o- rbd .................... [0 Storage Object]
  | o- rd_mcp ................. [0 Storage Object]
  o- ib_srpt ......................... [0 Targets]
  o- iscsi ........................... [0 Targets]
  o- loopback ........................ [0 Targets]
  o- qla2xxx ......................... [0 Targets]
  o- tcm_fc .......................... [0 Targets]
  o- vhost ........................... [0 Targets]
server:~ #

Notice the configurations order and "path".

Create a Backstore called stonith_bd and use the image path /root/stonith.img

server:~ # targetcli /backstores/fileio create stonith_bd /root/stonith.img
Generating a wwn serial.
Using buffered mode.
Created fileio stonith_bd.
server:~ #

Create Target

server:~ # targetcli /iscsi create
Created target iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291.
Selected TPG Tag 1.
Created TPG 1.
server:~ #

Create a LUN (look the paths)

server:~ # targetcli /iscsi/iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291/
tpg1/luns create /backstores/fileio/stonith_bd
Selected LUN 0.
Created LUN 0.
server:~ #

Create Portal

server:~ # targetcli /iscsi/iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291/tpg1/portals create
Using default IP port 3260
Automatically selected IP address 192.168.124.10.
Created network portal 192.168.124.10:3260.
server:~ #

Create ACL
We need create the ACL with the correct name of the Initiator, to get this value, check:
/etc/iscsi/initiatorname.iscsi

server:~ # grep -v ^# /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1996-04.de.suse:01:0f52c5cc3e8
server:~ #
server:~ # targetcli /iscsi/iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291/tpg1/acls create iqn.1996-04.de.suse:01:0f52c5cc3e8
Created Node ACL for iqn.1996-04.de.suse:01:0f52c5cc3e8
Created mapped LUN 0.
server:~ #

Disable Authentication

server:~ # targetcli /iscsi/iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291/tpg1 set attribute authentication=0
Parameter authentication is now '0'.
server:~ #

Save the configuration

server:~ # targetcli saveconfig
WARNING: Saving server current configuration to disk will overwrite your boot settings.
The current target configuration will become the default boot config.
Are you sure? Type 'yes': yes
server:~ #

Test the configuration

In client discover targets of the server and try to login

client:~ # iscsiadm -m discovery -t sendtargets -p server.suse.lab
192.168.124.10:3260,1 iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291
client:~ # 
client:~ # iscsiadm -m node -p server.suse.lab --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291, portal: 192.168.124.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291, portal: 192.168.124.10,3260] successful.
client:~ #

Voilá

Now check the path of the new attached disk

client:~ # ls /dev/disk/by-path/
ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0
pci-0000:00:01.1-ata-2.0
pci-0000:00:01.1-scsi-2:0:0:0
pci-0000:00:0d.0-ata-1.0
pci-0000:00:0d.0-ata-1.0-part1
pci-0000:00:0d.0-ata-1.0-part2
pci-0000:00:0d.0-scsi-0:0:0:0
pci-0000:00:0d.0-scsi-0:0:0:0-part1
pci-0000:00:0d.0-scsi-0:0:0:0-part2
scsi-0:0:0:0
client:~ #

We are ready to use it to create the STONITH Block Device

client:~ # sbd -d /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0 create
Initializing device /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0
Creating version 2.1 header on device 4 (uuid: 2c200e09-efee-4b9f-87fc-5bb1582a9470)
Initializing 255 slots on device 4
Device /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0 is initialized.
client:~ #
client:~ # sbd -d /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0 dump
==Dumping header on disk /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0
Header version     : 2.1
UUID               : 2c200e09-efee-4b9f-87fc-5bb1582a9470
Number of slots    : 255
Sector size        : 512
Timeout (watchdog) : 5
Timeout (allocate) : 2
Timeout (loop)     : 1
Timeout (msgwait)  : 10
==Header on disk /dev/disk/by-path/ip-192.168.124.10:3260-iscsi-iqn.2003-01.org.linux-iscsi.server.x8664:sn.197d60c80291-lun-0 is dumped
client:~ #

Done!

Bonus

If you paid attention, you noticed that we can make a simple bash script to automate this process.

In bash we trust!

Billy Vera © 2017. All Rights Reserved.

The opinions expressed in this blog are purely my own and are not in any way endorsed by my employer.

Proudly published with Ghost using Ghostium Theme