General Information
Creating iSCSI targets (storage on a server) and initiators (clients).
The following virtual machines will be used:
Finding help in this section.
#tab completion in targetcli utility
man iscsiadm
The iSCSI targets are on the storage server and are the volumes that can be mounted by clients.
Create a back-end logical volume or partition that will be an iSCSI target.
Example:
pvcreate /dev/sdb1 vgcreate vgsan /dev/sdb1 lvcreate --extents 100%PVS --name lvstor01 vgsan /dev/sdb1
Install packages
yum install targetcli
Enable the service
systemctl enable target
Start the targetcli interactive utility
targetcli
The targetcli utility commands available depend upon your path. Navigation is done via cd, pwd, and ls just like you would expect in a shell.
/> 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] /> pwd /
Backing Storage: Create a block storage object within the targetcli interactive prompt
/> backstores/block create name=block1 dev=/dev/vgsan/lvstor01
iSCSI Target: Create an iSCSI Target IQN (Iscsi Qualified Name)
/> iscsi/ create wwn=iqn.2018-05.com.example.server2:target
Change into the newly created IQN's TPG (Target Portal Group) and view the contents
/> cd iscsi/iqn.2018-05.com.example.server2:target/tpg1/ /iscsi/iqn.20...2:target/tpg1> ls
Create portal: RHEL 7.0 - 7.1 only
/iscsi/iqn.20...2:target/tpg1> portals create 0.0.0.0 ip_port=3260
LUN to Storage Map: Create a LUN within the target portal group
/iscsi/iqn.20...2:target/tpg1> luns/ create /backstores/block/block1
Client ACL: Create an ACL for a client to be able to connect to the IQN in the future
/iscsi/iqn.20...2:target/tpg1> acls/ create iqn.2018-05.com.example:server1
OPTIONAL: Create a CHAP Username/Password for client connections
/iscsi/iqn.20...2:target/tpg1> cd acls/iqn.2018-05.com.example:server1/ /iscsi/iqn.20...ample:server1> set auth userid=myuser password=mypassword
Save and exit the targetcli utility
/iscsi/iqn.20...ample:server1> cd / /> saveconfig /> exit
Firewall
firewall-cmd --permanent --add-port=3260/tcp firewall-cmd --reload OR firewall-cmd --permanent --add-service=iscsi-target firewall-cmd --reload
Start the target
systemctl start target
Setting up an iSCSI initiator (client).
Install initiator package
yum install iscsi-initiator-utils
Edit initiator name and change to the name setup on the server
vim /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2018-05.com.example:server1
Edit authentication information if set (optional)
vim /etc/iscsi/iscsid.conf node.session.auth.authmethod = CHAP node.session.auth.username = myuser node.session.auth.password = mypassword
Enable and start the iscsi service
systemctl enable iscsi
systemctl start iscsi
Note: See 'EXAMPLES' in “man iscsiadm” if you don't remember the discovery and login commands.
Use the iscsiadm command to discover IQN Information
iscsiadm --mode discovery --type sendtargets --portal 192.168.1.151
Login to the Target IQN (found during discovery)
iscsiadm --mode node --target iqn.2018-05.com.example.server2:target --portal 192.168.1.151 --login
View iSCSI Disk
lsblk --scsi
Create a partition
fdisk /dev/sdb
Create file system
mkfs.xfs /dev/sdb1
Get the disk UUID
blkid | grep sdb1
Mount via fstab
vim /etc/fstab #Mount iscsi device UUID=<uuid-here> /data/iscsi xfs _netdev 0 0
View Connected ISCSI Target Information
iscsiadm -m session -P 3