iSCSI (Internet Small Computer System Interface) is a network storage solution based on the communication protocol provided by SCSI. To understand iSCSI, you first need to know about some key terms:
Target — This term describes the storage device, which resides on a server. The server can either be on a LAN (Local Area Network) or a WAN (Wide Area Network). Think of the target as the storage device being shared. Also, keep in mind that a target is actually considered a device, not a filesystem. When the client system accesses this device, it can be treated as if it was a hard disk.
Initiator — This is the client that connects to the target. In some cases, the initiator is referred to as the iSCSI client.
To connect to iSCSI storage
1. Install the iscsi-initiator-utils package using:
# yum install iscsi-initiator-utils
2. Start the iscsi service and enable it to start when the system boots:
For CentOS/RHEL 6
# service iscsi start # chkconfig iscsi on
For CentOS/RHEL 7
For RHEL7, make sure iscsid.socket service is running.
# systemctl status iscsid.socket
iscsid.socket would start iscsid.service if required or stopped. To start any service, use
# systemctl start service-name
To make the changes persistent, do
#systemctl enable service-name
At this stage, the status of iscsi service “service iscsi status” might be seen as not running or iscsi is stopped. After the below discovery command, the status will be seen as running.
3. Obtain a listing of available targets from a given host (please note that ipaddress listed below must be replaced with the resolvable hostname or ip address of the system providing the port if different than default):
# iscsiadm -m discovery -t st -p [target_ipaddress] xxx.xxx.xxx.xxx:3260,1 iqn.2010-03.com.example:tgtd
In the above the “iqn.2010-03.com.example:tgtd” is the target_iqn_name. You can view the information of your target by:
# iscsiadm -m node -T [target_iqn_name] -p [target_ipaddress]
4. The following command will login to the discovered target (again, replace target_iqn_name with one from the output of the previous command and replace target_ipaddress below with that of the target system):
# iscsiadm -m node -T target_iqn_name -p ipaddress -l Logging in to [iface: default, target: iqn.2010-03.com.example:tgtd, portal: xxx.xxx.xxx.xxx,3260] Login to [iface: default, target: iqn.2010-03.com.example:tgtd, portal: xxx.xxx.xxx.xxx,3260]: successful
Note, you can log into all the LUNs exported on the target by running:
# iscsiadm -m discovery -t st -l
This procedure will enable the target(or targets if you logged into all) to be accessed upon reboot. The information is stored in the node database found in /var/lib/iscsi. The structure of the database is described in the file /usr/share/doc/iscsi-initiator-utils-VERSION/README.
To disconnect from iSCSI storage
1. If you want to disable the target, you need log out by:
# iscsiadm -m node -T target_iqn_name -p ipaddress -u
2. To remove the target from the iscsi database so that the iscsi does not reconnect upon reboot, delete the target after logging out of it:
# iscsiadm -m node -T target_iqn_name -p ip address --op delete
3. Note, you can log out of all targets by running:
# iscsiadm -m node -U all
To change configuration for existing sessions
1. Edit /etc/iscsi/iscsid.conf on initiator nodes.
2. umount the filesystem provided by iscsi session.
3. restart iscsid service.
For a more verbose listing of possible options for the iscsiadm command in Red Hat Enterprise Linux refer to the manual page using:
# man iscsiadm