Pages

Wednesday, 31 July 2019

RHCE-EX300-Configure a system as either an iSCSI target or initiator that persistently mounts an iSCSI target

1. Example Question

system1 plays as an iSCSI target while system2 plays as an iSCSI initiator.
  • system1, IP: 192.168.100.161
  • system2, IP: 192.168.100.198
  • system1
    • iSCSI target
    • iqn.2015-02.com.example:system1
    •  port 3260
    •  back store , fileio, 2GB
    • only accessible to system2
  • system2: 
    • iSCSI initiator
    • iqn.2015-02.com.example:system2
    • create a partition on iSCSI LUN with 1GB size
    • format partition as xfs
    • mount it under /mnt/data 
    • the mount survives reboot

2. Answer

2.1 system1

  • install "targetcli" package
    • yum install targetcli
  • enable/start target.service
    • systemctl enable target
    • systemctl start target
  • create iSCSI target via "targetcli"
    • create backstore
      • cd /backstores/fileio
      • create disk1 /tmp/disk1.bin 2GB
    • create iSCSI target (portals, lun, and acl)
      • cd /iscsi
      • create iqn.2015-02.com.example:system1
      • cd iqn.2015-02.com.example:system1/tpg1/portals 
      • create (only for RHEL 7.0)
      • cd ../luns
      • create /backstores/fileio/disk1
      • cd ../acl
      • create iqn.2015-02.com.example:system2
      • cd /
      • saveconifg
      • exit
  • verify the portal
    • ss -tln | grep 3260
  • firewall
    • firewall-cmd --add-service=iscsi-target  --permanent   # OR
    • firewall-cmd --add-port=3260/tcp
    • firewall-cmd --reload
  • reboot the server
    • reboot

2.2 system2

  • install "iscsi-initiator-utils" package
    • yum install iscsi-initiator-utils
  • modify /etc/iscsi/initiatorname.iscsi
    • vim /etc/iscsi/initiatorname.iscsi
    • iqn.2015-02.com.example:system2
  • enable/start iscsi.service and iscsid.service
    • systemctl enable iscsi
    • systemctl enable iscsid
    • systemctl start iscsi
    • systemctl start iscsid
  • create iSCSI node with "iscsiadm"
    • discovery
      • iscsiadm -m discovery --type sendtargets --portal 192.168.100.161:3260
    • login
      • iscsiadm -m node --target iqn.2015-02.com.example:system1  --portal 192.168.100.161:3260 --login
  • format and partition LUN
    • lsblk to check disk name
    • parted or fdisk to partition
    • blkid to find the UUID
  • modify /etc/fstab
    • cp /etc/fstab /etc/fstab.bk
    • add one line like this: 
      • UUID="cb251f37-4cea-49e9-89ef-d611670a5147"     /mnt/data       xfs     _netdev         0       0
    • mount -a
  • reboot the server

3. Tips

  • target.service vs targetd.service
    • targetd.service is from "targetd" package which is a web UI for target management and not related to our task
  • iscsi.service vs iscsid.service
    • both are needed for this task
  • Keep target online when reboot initiator 
    • otherwise, initiator system may hang on shutdown..
  • man iscsiadm, EXAMPLE section helps alot
  • targetcli's builtin help is useful

No comments:

Post a Comment