RHCE - Part3 - iSCSI: Target and Initiator
Target (server) = srv.example.local
Initiator (client) = client.example.local
TARGET
Install targetcli:
# yum install -y targetcli
Enable target:
# systemctl enable target
Enter the CLI to configure the target:
# targetcli
Create the backstores:
/> backstores/fileio create file1 /srv/lunfile 100M sparse=true write_back=false
/> backstores/block create block1 /dev/vg/lv_iscsi write_back=false
Create IQN:
/> iscsi/ create iqn.2020-02.local.example:srv
Create portal:
/> iscsi/iqn.2020-02.local.example:srv/tpg1/portals create
Create ACL (client/initiator configuration):
/> iscsi/iqn.2020-02.local.example:srv/tpg1/acls create iqn.2020-02.local.example:client
Create LUNs:
/> iscsi/iqn.2020-02.local.example:srv/tpg1/luns create /backstores/fileio/file1
/> iscsi/iqn.2020-02.local.example:srv/tpg1/luns create /backstores/block/block1
Optional: Set CHAP connection and set username and password for the initiator to log onto the target:
/> iscsi/iqn.2020-02.local.example:srv/tpg1/acls/iqn.2020-02.local.example:client set auth userid=user password=pass
Check target configuration:
/> ls
Save configuration and exit the CLI:
/> saveconfig
/> exit
Open port 3260/tcp in firewall:
# firewall-cmd --permanent --add-port=3260/tcp
# firewall-cmd --reload
INITIATOR
Install iscsi-initiator-utils:
# yum install -y iscsi-initiator-utils
Configure initiator name in /etc/iscsi/initiatorname.iscsi:
# vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2020-02.local.example:client
Optional: configure CHAP settings in /etc/iscsi/iscsid.conf:
# vi /etc/iscsi/iscsid.conf [...] node.session.auth.authmethod = CHAP [...] node.session.auth.username = user node.session.auth.password = pass [...]
Enable and start iscsi and iscsid:
# systemctl enable iscsi iscsid
# systemctl start iscsi iscsid
Start target discovery:
# iscsiadm -m discovery -t st -p srv.example.local:3260
Login and connect to the target:
# iscsiadm -m node -T iqn.2020-02.local.example:srv -p srv.example.local:3260 --login
Check iscsi LUNs provided by the target:
# lsblk -S | grep LIO
Last step, you can :
- use the mapped LUNs as LVMs (create a VG and LVs)
- format these drives/LVs to the required filesystem (xfs, ext4, etc. …)
- use blkid to retrieve UUIDs, logical names or aliases
- append the information to /etc/fstab
If the discovery failed, delete files under /var/lib/iscsi/nodes/* and retry with correct discovery parameters.