Setting the iSCSI
Initiatorname
1. On server 2, open a root shell and type yum -y
install iscsi-initiator-utils lsscsi to install the software that you need
to perform this exercise.
[root@server1 /]# yum -y install iscsi-initiator-utils
Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Package iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 already installed and latest version Nothing to do |
2. As an iSCSI node, the
client requires a unique IQN. The default /etc/iscsi/initiatorname.iscsi file
contains a generated IQN using Red Hats' domain. Administrators typically reset
the IQN to their own domain and a appropriate client system string.
[root@server1 /]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2015-12.com.example:server1 |
After changing the iSCSI initiatorname,
do not forget to restart the iscsid service by using systemctl restart
iscsid !
[root@server1 /]# systemctl restart iscsid
[root@server1 /]# systemctl status iscsid -l iscsid.service - Open-iSCSI Loaded: loaded (/usr/lib/systemd/system/iscsid.service; disabled) Active: active (running) since Mon 2015-12-28 07:03:06 CET; 21s ago Docs: man:iscsid(8) man:iscsiadm(8) Process: 4694 ExecStop=/sbin/iscsiadm -k 0 2 (code=exited, status=0/SUCCESS) Process: 4699 ExecStart=/usr/sbin/iscsid (code=exited, status=0/SUCCESS) Main PID: 4702 (iscsid) CGroup: /system.slice/iscsid.service +-4701 /usr/sbin/iscsid +-4702 /usr/sbin/iscsidDec 28 07:03:06 server1.example.com systemd[1]: Starting Open-iSCSI... Dec 28 07:03:06 server1.example.com systemd[1]: Failed to read PID from file /var/run/iscsid.pid: Invalid argument Dec 28 07:03:06 server1.example.com systemd[1]: Started Open-iSCSI. Dec 28 07:03:06 server1.example.com iscsid[4701]: iSCSI daemon with pid=4702 started! |
Performing the Discovery
To connect to an iSCSI SAN,
you start by exploring which configuration is available. The iscsiadm command
has different modes, and in discovery mode the command shows available
connections
3. Type iscsiadm --mode discovery --type
sendtargets --portal 192.168.122.202 --discover . This should return the
name of the iSCSI target as you have configured it in the previous exercise.
[root@server1 /]# iscsiadm --mod
discovery --type sendtargets --portal 192.168.122.202 --discover
192.168.122.202:3260,1 iqn.2015-12.com.example:target |
4. After a successful discovery, you can request
more information about the target that was discovered, using the -P option.
This option can be used in any iscsiadm mode, and it will show details about
the current mode. In all modes, the print levels 0 and 1 are supported. In some
modes, you can go beyond that to display more additional information. Figure
shows the result of the iscsiadm --mode discovery -P 1 command.
[root@server1 /]# iscsiadm --mode discovery -P 1
SENDTARGETS: DiscoveryAddress: 192.168.122.202,3260 Target: iqn.2015-12.com.example:target Portal: 192.168.122.202:3260,1 Iface Name: default iSNS: No targets found. STATIC: No targets found. FIRMWARE: No targets found. |
Making the Connection
Based on the name that you
found when performing the iSCSI discovery and assuming that you have set the
initiatorname correctly, you can now log in to the iSCSI target and make the
actual connection. To do this, use a command that looks like the following:
5. Next, type iscsiadm --mode node --targetname
iqn.2015-12.com.example:target1 --portal 192.168.122.202:3260 --login .
[root@server1 etc]# iscsiadm --mode node --targetname
iqn.2015-12.com.example:target --portal 192.168.122.202:3260 --login
Logging in to [iface: default, target: iqn.2015-12.com.example:target, portal: 192.168.122.202,3260] (multiple) Login to [iface: default, target: iqn.2015-12.com.example:target, portal: 192.168.122.202,3260] successful. |
In this command, a few options
are used:
·
--mode node This specifies iscsiadm to enter “node” mode. This is the mode in
which the actual connection with the target can be established.
·
--targetname This specifies the name of the target as discovered when using the
iSCSI discovery process.
·
--portal This is the IP address and port on which the target is listening.
·
--login This authenticates to the target and will store credentials as
well to ensure that on reboot the connection can be reestablished again.
Making iSCSI Connections Persistent
After logging in to an iSCSI
target server, the connections are persistent automatically. That means that on
reboot, the iscsid and iscsi services are started on the iSCSI
client, and these services will read the iSCSI configuration that is locally
stored to automatically reconnect. Therefore, there is no need to put anything
in configuration files if you have successfully connected once to the iSCSI
server.
If you need an iSCSI
connection not to be restored after reboot, you first have to log out to
disconnect the actual session by using iscsiadm --mode node --targetname
iqn.2014-11.com.example:target1 --logout .
Next you need to delete the
corresponding IQN subdirectory and all of its contents. You can do this with
the rm command or by using iscsiadm --mode node --targetname
iqn.2014-11.com.example:target1 --op=delete . This ensures that all
configuration is wiped and that you can make a clean restart.
Mounting iSCSI Devices
6. The iSCSI devices should now be available. Type lsscsi
to show them. You should see three LIO devices. Use iscsiadm -m session
-P3 , which also shows all disks.
[root@server1 etc]# yum -y install lsscsi
Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Package lsscsi-0.27-3.el7.x86_64 already installed and latest version |
[root@server1 etc]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware SATA CD01 1.00 /dev/sr0 [30:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda [33:0:0:0] disk LIO-ORG block1 4.0 /dev/sdb [33:0:0:1] disk LIO-ORG block2 4.0 /dev/sdc [33:0:0:2] disk LIO-ORG file1 4.0 /dev/sdd |
[root@server1 etc]# iscsiadm -m session -P3
iSCSI Transport Class version 2.0-870 version 6.2.0.873-21 Target: iqn.2015-12.com.example:target (non-flash) Current Portal: 192.168.122.202:3260,1 Persistent Portal: 192.168.122.202:3260,1 ********** Interface: ********** Iface Name: default Iface Transport: tcp Iface Initiatorname: iqn.2015-12.com.example:server1 Iface IPaddress: 192.168.122.201 Iface HWaddress: <empty> Iface Netdev: <empty> SID: 1 iSCSI Connection State: LOGGED IN iSCSI Session State: LOGGED_IN Internal iscsid Session State: NO CHANGE ********* Timeouts: ********* Recovery Timeout: 120 Target Reset Timeout: 30 LUN Reset Timeout: 30 Abort Timeout: 15 ***** CHAP: ***** username: <empty> password: ******** username_in: <empty> password_in: ******** ************************ Negotiated iSCSI params: ************************ HeaderDigest: None DataDigest: None MaxRecvDataSegmentLength: 262144 MaxXmitDataSegmentLength: 262144 FirstBurstLength: 65536 MaxBurstLength: 262144 ImmediateData: Yes InitialR2T: Yes MaxOutstandingR2T: 1 ************************ Attached SCSI devices: ************************ Host Number: 33 State: running scsi33 Channel 00 Id 0 Lun: 0 Attached scsi disk sdb State: running scsi33 Channel 00 Id 0 Lun: 1 Attached scsi disk sdc State: running scsi33 Channel 00 Id 0 Lun: 2 Attached scsi disk sdd State: running [root@server1 etc]# |
7. On the first iSCSI device (I’ll assume that it is
/dev/sdb in this exercise, but it can be a different device on your server
depending on the configuration that is used), type mkfs.xfs /dev/sdb .
[root@server1 etc]# cat /proc/partitions
major minor #blocks name 11 0 3655680 sr0 8 0 20971520 sda 8 1 1048576 sda1 8 2 10485760 sda2 8 16 204800 sdb 8 32 204800 sdc 8 48 102400 sdd |
[root@server1 etc]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=256 agcount=8, agsize=6400 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=51200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 |
8. Use blkid /dev/sdb to get the UUID that is
set for the XFS file system that you have just created on /dev/sdb.
[root@server1 etc]# blkid /dev/sdb
/dev/sdb: UUID="48c4fa99-4bd6-4f06-a5fa-8a6b86d8a2d5" TYPE="xfs" |
9. Create a mount point for the iSCSI disk, using mkdir
/mnt/iscsi .
[root@server1 etc]# mkdir /mnt/iscsi
|
10. Type vim /etc/fstab to open the /etc/fstab
file in an editor and add a line that looks like the following. (Make sure to
replace the UUID with the UUID you have found in Step 6 of this exercise.)
UUID=XXXXXXXX-XXXX-XXXX-XXXXXX
/mnt/iscsi xfs _netdev 0 2
[root@server1 etc]# grep -i iscsi /etc/fstab
UUID=48c4fa99-4bd6-4f06-a5fa-8a6b86d8a2d5 /mnt/iscsi xfs _netdev 0 2 |
9. Type mount -a . This should mount the iSCSI
disk. Type mount without any arguments to verify.
[root@server1 /]# mount -a
[root@server1 /]# mount|grep iscsi /dev/sdb on /mnt/iscsi type xfs (rw,relatime,seclabel,attr2,inode64,noquota,_netdev) |
TIP If you want to make it easy to create an iSCSI
configuration, study man 8 iscsiadm . It contains some great examples
that help you go through the basic steps of configuring an iSCSI connection. Do
realize, though, that on the RHCE exam, you need to expect the unexpected, and
you might have to perform some tasks that
Thank you for reading.