Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Tuesday, 28 August 2018

Configure an iSCSI Server in RHEL/CentOS 7

configure-iscsi-server-in-linux1iSCSI (Internet Small Computer System Interface) is a protocol used to link data storage devices over an IP network infrastructure. An iSCSI target is often a dedicated network-connected hard disk storage device, but may also be a general-purpose computer. Nearly all modern mainstream server operating systems (such as BSD, Linux, Solaris or Windows Server) can provide iSCSI target functionality, either as a built-in feature or with supplemental software. The computer providing the iSCSI targets is called iSCSI Server.

An iSCSI initiator is an iSCSI client. An iSCSI initiator typically serves the same purpose to a computer as a SCSI bus adapter would, except that, instead of physically cabling SCSI devices (like hard drives and tape changers), an iSCSI initiator sends SCSI commands over an IP network.

In this post, we will

- configure a iSCSI Server,
- create an iSCSI Target on the Server and
- persistently mount that Target on a iSCSI Initiator.

 

System Specification:

  iSCSI Server iSCSI Initiator
Operating System: RHEL 7 RHEL 7
Hostname: server1.example.com desktop1.example.com
IP Address: 192.168.116.11/24 192.168.116.12/24

Read Also: Installation of CentOS 7 Server

 

Configure an iSCSI Target:

We have an spare hard disk (20 GB) is available. we have created a partition (20GB) in it using fdisk to make it usable by iSCSI Server.

[root@server1 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x94c52e45 Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 83 Linux

we need targetcli package to configure an iSCSI Target.

[root@server1 ~]# yum install -y targetcli Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package targetcli.noarch 0:2.1.fb34-1.el7 will be installed --> Processing Dependency: python-rtslib >= 2.1.fb41 for package: targetcli-2.1.fb34-1.el7.noarch --> Processing Dependency: python-configshell for package: targetcli-2.1.fb34-1.el7.noarch --> Running transaction check ---> Package python-configshell.noarch 1:1.1.fb11-3.el7 will be installed --> Processing Dependency: pyparsing for package: 1:python-configshell-1.1.fb11-3.el7.noarch --> Processing Dependency: python-urwid for package: 1:python-configshell-1.1.fb11-3.el7.noarch ---> Package python-rtslib.noarch 0:2.1.fb46-1.el7 will be installed --> Processing Dependency: python-kmod for package: python-rtslib-2.1.fb46-1.el7.noarch --> Running transaction check ---> Package pyparsing.noarch 0:1.5.6-9.el7 will be installed ---> Package python-kmod.x86_64 0:0.9-4.el7 will be installed ---> Package python-urwid.x86_64 0:1.1.1-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: targetcli noarch 2.1.fb34-1.el7 localyum 55 k Installing for dependencies: pyparsing noarch 1.5.6-9.el7 localyum 94 k python-configshell noarch 1:1.1.fb11-3.el7 localyum 64 k python-kmod x86_64 0.9-4.el7 localyum 57 k python-rtslib noarch 2.1.fb46-1.el7 localyum 75 k python-urwid x86_64 1.1.1-3.el7 localyum 654 k Transaction Summary ================================================================================ Install 1 Package (+5 Dependent packages) Total download size: 998 k Installed size: 3.9 M Downloading packages: -------------------------------------------------------------------------------- Total 97 MB/s | 998 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python-kmod-0.9-4.el7.x86_64 1/6 Installing : python-rtslib-2.1.fb46-1.el7.noarch 2/6 Installing : pyparsing-1.5.6-9.el7.noarch 3/6 Installing : python-urwid-1.1.1-3.el7.x86_64 4/6 Installing : 1:python-configshell-1.1.fb11-3.el7.noarch 5/6 Installing : targetcli-2.1.fb34-1.el7.noarch 6/6 Verifying : python-rtslib-2.1.fb46-1.el7.noarch 1/6 Verifying : python-urwid-1.1.1-3.el7.x86_64 2/6 Verifying : targetcli-2.1.fb34-1.el7.noarch 3/6 Verifying : 1:python-configshell-1.1.fb11-3.el7.noarch 4/6 Verifying : pyparsing-1.5.6-9.el7.noarch 5/6 Verifying : python-kmod-0.9-4.el7.x86_64 6/6 Installed: targetcli.noarch 0:2.1.fb34-1.el7 Dependency Installed: pyparsing.noarch 0:1.5.6-9.el7 python-configshell.noarch 1:1.1.fb11-3.el7 python-kmod.x86_64 0:0.9-4.el7 python-rtslib.noarch 0:2.1.fb46-1.el7 python-urwid.x86_64 0:1.1.1-3.el7 Complete!

Now obtain a targetcli shell.

[root@server1 ~]# targetcli targetcli shell version 2.1.fb34 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. />

Check the status of current iSCSI Target configurations.

/> 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] />

At the targetcli shell, create a Storage Block using following commands.

/> cd backstores/block/ /backstores/block> create block1 /dev/sdb1 Created block storage object block1 using /dev/sdb1. /backstores/block> ls o- block .................................................. [Storage Objects: 1] o- block1 ....................... [/dev/sdb1 (20.0GiB) write-thru deactivated]

Create a TPG (Target Portal Group).

/backstores/block> cd /iscsi /iscsi> create iqn.2018-07.com.example.server1:remotedisk1 Created target iqn.2018-07.com.example.server1:remotedisk1. Created TPG 1. /iscsi> ls o- iscsi .......................................................... [Targets: 1] o- iqn.2018-07.com.example.server1:remotedisk1 ..................... [TPGs: 1] o- tpg1 ............................................. [no-gen-acls, no-auth] o- acls ........................................................ [ACLs: 0] o- luns ........................................................ [LUNs: 0] o- portals .................................................. [Portals: 0] /iscsi>

Obtain the client iqn (iSCSI Qualified Name) from the client machine and use it to create an ACL, to limit the access to our iSCSI Target by desktop1.example.com machine.

/iscsi> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/acls /iscsi/iqn.20...sk1/tpg1/acls> create iqn.1994-05.com.redhat:31532b60ee10 Created Node ACL for iqn.1994-05.com.redhat:31532b60ee10 /iscsi/iqn.20...sk1/tpg1/acls> ls o- acls .............................................................. [ACLs: 1] o- iqn.1994-05.com.redhat:31532b60ee10 ...................... [Mapped LUNs: 1] o- mapped_lun0 .................................... [lun0 block/block1 (rw)] /iscsi/iqn.20...sk1/tpg1/acls>

Create a LUN (Logical Unit Number).

/iscsi/iqn.20...sk1/tpg1/acls> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/luns /iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/block1 Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:31532b60ee10 /iscsi/iqn.20...sk1/tpg1/luns> ls o- luns .............................................................. [LUNs: 1] o- lun0 ........................................... [block/block1 (/dev/sdb1)] /iscsi/iqn.20...sk1/tpg1/luns>

Create a Portal now.

/iscsi/iqn.20...sk1/tpg1/luns> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/portals /iscsi/iqn.20.../tpg1/portals> create 192.168.116.11 Using default IP port 3260 Created network portal 192.168.116.11:3260. /iscsi/iqn.20.../tpg1/portals> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json [root@server1 ~]#

Allow the port 3260/tcp through firewall.

[root@server1 ~]# firewall-cmd --permanent --add-port=3260/tcp success [root@server1 ~]# firewall-cmd --reload success

Start and enable the target service.

[root@server1 ~]# systemctl enable target ; systemctl start target ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

iSCSI Target has been configured successfully.

 

Configure a iSCSI Initiator:

Install iscsi-initiator-utils package. It is required to configure a iSCSI Initiator.

[root@desktop1 ~]# yum install -y 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. Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast localyum | 4.1 kB 00:00 Resolving Dependencies --> Running transaction check ---> Package iscsi-initiator-utils.x86_64 0:6.2.0.873-21.el7 will be installed --> Processing Dependency: iscsi-initiator-utils-iscsiuio >= 6.2.0.873-21.el7 for package: iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 --> Running transaction check ---> Package iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.873-21.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: iscsi-initiator-utils x86_64 6.2.0.873-21.el7 localyum 411 k Installing for dependencies: iscsi-initiator-utils-iscsiuio x86_64 6.2.0.873-21.el7 localyum 79 k Transaction Summary ================================================================================ Install 1 Package (+1 Dependent package) Total download size: 490 k Installed size: 2.5 M Downloading packages: -------------------------------------------------------------------------------- Total 7.1 MB/s | 490 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : iscsi-initiator-utils-iscsiuio-6.2.0.873-21.el7.x86_64 1/2 Installing : iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 2/2 Verifying : iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 1/2 Verifying : iscsi-initiator-utils-iscsiuio-6.2.0.873-21.el7.x86_64 2/2 Installed: iscsi-initiator-utils.x86_64 0:6.2.0.873-21.el7 Dependency Installed: iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.873-21.el7 Complete!

We can confirm the iSCSI Initiator’s iqn that, we have used during iSCSI Target configuration to create an ACL.

[root@desktop1 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:31532b60ee10

Start and enable iscsi service.

[root@desktop1 ~]# systemctl enable iscsi ; systemctl start iscsi

Discover the available iSCSI Targets at 192.168.116.11.

[root@desktop1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.116.11 192.168.116.11:3260,1 iqn.2018-07.com.example.server1:remotedisk1 [root@desktop1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ââsda1 8:1 0 300M 0 part /boot ââsda2 8:2 0 1.5G 0 part [SWAP] ââsda3 8:3 0 18.2G 0 part / sr0 11:0 1 3.5G 0 rom /mnt/iso [root@desktop1 ~]# systemctl restart iscsi [root@desktop1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ââsda1 8:1 0 300M 0 part /boot ââsda2 8:2 0 1.5G 0 part [SWAP] ââsda3 8:3 0 18.2G 0 part / sdb 8:16 0 20G 0 disk sr0 11:0 1 3.5G 0 rom /mnt/iso

Our iSCSI Target Disk has been successfully discovered as /dev/sdb. Let’s create a partition and the filesystem.

[root@desktop1 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x08f4940d. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (8192-41940991, default 8192): Using default value 8192 Last sector, +sectors or +size{K,M,G} (8192-41940991, default 41940991): Using default value 41940991 Partition 1 of type Linux and of size 20 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@desktop1 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21473787904 bytes, 41940992 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes Disk label type: dos Disk identifier: 0x08f4940d Device Boot Start End Blocks Id System /dev/sdb1 8192 41940991 20966400 83 Linux [root@desktop1 ~]# mkfs.xfs /dev/sdb1 meta-data=/dev/sdb1 isize=256 agcount=16, agsize=327600 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=5241600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0

Now, persistently mount the partition at /mnt/remotedisk1.

[root@desktop1 ~]# echo "/dev/sdb1 /mnt/remotedisk1 xfs _netdev 0 0" >> /etc/fstab [root@desktop1 ~]# mount -a [root@desktop1 ~]# mount | grep /mnt/remotedisk1 /dev/sdb1 on /mnt/remotedisk1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota,_netdev)

We have successfully created an iSCSI Target and then persistently mount it at our iSCSI Initiator.

Read Also: Installation of Openfiler Appliance
  Configure an iScsi Target in Openfiler
Configure an iSCSI Server in RHEL/CentOS 7


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment