{"id":5930,"date":"2016-05-14T11:04:58","date_gmt":"2016-05-14T03:04:58","guid":{"rendered":"http:\/\/rmohan.com\/?p=5930"},"modified":"2016-05-14T11:05:59","modified_gmt":"2016-05-14T03:05:59","slug":"iscsi-configuration-on-rhel-7-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5930","title":{"rendered":"iSCSI Configuration on RHEL 7 \/ CentOS 7"},"content":{"rendered":"<p>iSCSI Configuration on RHEL 7 \/ CentOS 7 <\/p>\n<p>Step 1: First you need to create partition <\/p>\n<p>    [root@server1 ~]# fdisk -c \/dev\/sdb <\/p>\n<p>    Press &#8216;p&#8217; to print partition table <\/p>\n<p>    Press &#8216;n&#8217; to create a new partition <\/p>\n<p>    Press &#8216;p&#8217; to create primary partition <\/p>\n<p>    Type Partition Number : 1<\/p>\n<p>    First Sector        : PRESS ENTER <\/p>\n<p>    Last Sector        : +1G<\/p>\n<p>    Press &#8216;p&#8217; to print partition tables again <\/p>\n<p>    Press &#8216;t&#8217; to change partition ID <\/p>\n<p>    Type your partition Number :1<\/p>\n<p>    Type Partition code     : 8e<\/p>\n<p>     Press &#8216;p&#8217; to print partition tables again<\/p>\n<p>    Press &#8216;w&#8217; to save and exit<br \/>\nStep 2: if required, use partprobe command to update partition table entry into kernel. <\/p>\n<p>    [root@server1 ~]# partprobe \/dev\/sdb<\/p>\n<p>Step 3: Now create a Logical Volume using \/dev\/sdb1 partition <\/p>\n<p>    [root@server1 ~]# pvcreate \/dev\/sdb1<\/p>\n<p>    [root@server1 ~]# vgcreate iSCSI_vg \/dev\/sdb1<\/p>\n<p>    [root@server1 ~]# lvcreate -n iscsi_lv1 -l 100%FREE iSCSI_vg <\/p>\n<p>Step 4: First you need to install &#8220;targetcli&#8221; package<\/p>\n<p>    [root@server1 ~]# yum install targetcli -y <\/p>\n<p>Step 5: Now run targetcli with no options to enter into interactive mode: <\/p>\n<p>    [root@server1 ~]# targetcli <\/p>\n<p>    \/> ls<\/p>\n<p> Now Configure the existing \/dev\/iSCSI_vg\/iscsi_lv1 logical volume as a block-type backing store using the name of &#8220;server1.disk1&#8221;. <\/p>\n<p>    \/> cd backstores\/<\/p>\n<p>    \/backstores> ls<\/p>\n<p>    \/backstores> cd block <\/p>\n<p>    \/backstores\/block> ls<\/p>\n<p>    \/backstores\/block> create server1.disk1 \/dev\/iSCSI_vg\/iscsi_lv1 <\/p>\n<p>    \/backstores\/block> ls<\/p>\n<p> Now Create a unique iSCSI Qualified Name (IQN) for the target. <\/p>\n<p>    \/backstores\/block> cd \/iscsi <\/p>\n<p>    \/iscsi> create iqn.2014-10.com.example.server1:iscsi-1<\/p>\n<p> Now an ACL for client node (initiator). the initiator will be connecting with it&#8217;s initiator name. <\/p>\n<p>    \/iscsi> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-1\/tpg1\/acls <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/acls> create iqn.2014-10.com.example.com.server1:server2<br \/>\n Now set username and password into ACL to access this LUN <\/p>\n<p>    \/> cd iqn.2014-10.com.example.com.server1:server2<\/p>\n<p>    \/> set auth userid=user1<\/p>\n<p>    \/> set auth password=password <\/p>\n<p> Now Create a LUN under the target, The LUN should use the previously defined backing storage device named &#8220;server1.disk1&#8243; <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/acls> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-1\/tpg1\/luns <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/luns> create \/backstores\/block\/server1.disk1 <\/p>\n<p>Now Configure a portal for the target to listen on 192.168.0.254<\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/luns> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-1\/tpg1\/portals <\/p>\n<p>    \/iscsi\/iqn.20&#8230;\/tpg1\/portals> create 192.168.0.254<\/p>\n<p> Now view, verify and save the target server configuration <\/p>\n<p>    \/iscsi\/iqn.20&#8230;\/tpg1\/portals> cd \/<\/p>\n<p>    \/> ls<\/p>\n<p> Now Save this configuration<\/p>\n<p>        \/> saveconfig<\/p>\n<p>        \/> exit<\/p>\n<p> NOTE-: this configuration will be saved to &#8221; ~]# cat \/etc\/target\/saveconfig.json&#8221; <\/p>\n<p>Step 6: Now Enable and Start target service <\/p>\n<p>    [root@server1 ~]# systemctl enable target.service <\/p>\n<p>    [root@server1 ~]# systemctl restart target.service<br \/>\n    [root@server1 ~]# systemctl status target.service <\/p>\n<p>Step 7: Now Configure firewall to allow target service<br \/>\n    [root@server1 ~]# firewall-cmd &#8211;permanent &#8211;add-port=3260\/tcp<br \/>\n    [root@server1 ~]# firewall-cmd &#8211;reload <\/p>\n<p>                     Accessing iSCSI Storage with CHAP Authentication  <\/p>\n<p>Step 1: First you need to install iSCSI initiator package <\/p>\n<p>    [root@server2 ~]# yum install iscsi-initiator-utils -y <\/p>\n<p>Step 2: Now Create a unique iSCSI IQN name for the client initiator. Otherwise you will not able to connect\/login into IQN<\/p>\n<p>    [root@server2 ~]# vim \/etc\/iscsi\/initiatorname.iscsi <\/p>\n<p>    InitiatorName=iqn.2014-10.com.example.server1:server2<br \/>\n     :wq (save and exit) <\/p>\n<p>Step 3: Now you need to modify &#8220;\/etc\/iscsi\/iscsid.conf&#8221; to provide username and password for chap authentication <\/p>\n<p>    [root@server2 ~]# vim \/etc\/iscsi\/iscsid.conf <\/p>\n<p>    # line 54: uncomment<\/p>\n<p>    node.session.auth.authmethod = CHAP <\/p>\n<p># line 58,59: uncomment and specify the username and password you set on the iSCSI target server<\/p>\n<p>    node.session.auth.username = user1<\/p>\n<p>    node.session.auth.password = password<br \/>\n     :wq (save and exit) <\/p>\n<p>Step 4: Now Enable and start iscsi client service<br \/>\n    [root@server2 ~]# systemctl restart iscsid.service <\/p>\n<p>    [root@server2 ~]# systemctl enable iscsid.service <\/p>\n<p>Step 5: Now discover target using the following command: <\/p>\n<p>    [root@server2 ~]# iscsiadm -m discovery -t st -p 192.168.0.254<\/p>\n<p>Step 6: Confirm status after discovery<\/p>\n<p>    [root@server2 ~]# iscsiadm -m node -o show <\/p>\n<p>Step 7: Now connect\/login the discovered target into system <\/p>\n<p>  [root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:tgt1 -p 192.168.0.254 -l<br \/>\nStep 8: Confirm the established session<\/p>\n<p>    [root@server2 ~]# iscsiadm -m session -o show <\/p>\n<p>Step 9: Confirm the partitions<\/p>\n<p>    [root@server2 ~]# cat \/proc\/partitions <\/p>\n<p>Step 10: Create label,  create a new primary partition, format it using xfs file system and the mount it on \/mnt directory.  <\/p>\n<p>    [root@server2 ~]# parted &#8211;script \/dev\/sdb &#8220;mklabel msdos&#8221; <\/p>\n<p>    [root@server2 ~]# parted &#8211;script \/dev\/sdb &#8220;mkpart primary 0% 100%&#8221; <\/p>\n<p>    [root@server2 ~]# mkfs.xfs -i size=1024 -s size=4096 \/dev\/sdb1 <\/p>\n<p>    [root@server2 ~]# mount \/dev\/sdb1 \/mnt <\/p>\n<p>    [root@server2 ~]# df -hT<br \/>\nStep 11: Now make it persistent entry to mount at booting<br \/>\n    [root@server2 ~]# blkid <\/p>\n<p>    Now Copy the UUID of \/deb\/sdb1 and paste it into \/etc\/fstab as following: <\/p>\n<p>    [root@server2 ~]# vim \/etc\/fstab <\/p>\n<p>    UUID=&#8221;be41aa12-1e30-4678-8c19-da3506df1d84&#8243; \/mnt                xfs     _netdev     0 0<br \/>\n     :wq (save and exit)  <\/p>\n<p>    [root@server2 ~]# umount \/mnt\/<\/p>\n<p>    [root@server2 ~]# mount -a<\/p>\n<p>    [root@server2 ~]# df -h Step 12: Now unmount the iSCSI Storage <\/p>\n<p>    [root@server2 ~]# cd <\/p>\n<p>    [root@server2 ~]# umount \/mnt\/<\/p>\n<p>    [root@server2 ~]# vim \/etc\/fstab <\/p>\n<p>    Remove the following entry form this file<\/p>\n<p>     UUID=&#8221;be41aa12-1e30-4678-8c19-da3506df1d84&#8243; \/mnt                xfs     _netdev         0 0<br \/>\n     :wq (save and exit)<\/p>\n<p>     To Disconnect iSCSI storage <\/p>\n<p>  [root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:tgt1 -p 192.168.0.254 -u<\/p>\n<p>     To delete cache as well <\/p>\n<p>[root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:tgt1 -p 192.168.0.254 -o delete <\/p>\n<p>     Now if you want to connect it again, you need to discover it again. <\/p>\n<p>                            Configuring iSCSI Targets without CHAP Authentication <\/p>\n<p>Step 1: First you need to create partition <\/p>\n<p>    [root@server1 ~]# fdisk -c \/dev\/sdc <\/p>\n<p>    Press &#8216;p&#8217; to print partition table <\/p>\n<p>    Press &#8216;n&#8217; to create a new partition <\/p>\n<p>    Press &#8216;p&#8217; to create primary partition <\/p>\n<p>    Type Partition Number : 1<\/p>\n<p>    First Sector        : PRESS ENTER <\/p>\n<p>    Last Sector        : +1G<\/p>\n<p>    Press &#8216;p&#8217; to print partition tables again <\/p>\n<p>    Press &#8216;t&#8217; to change partition ID <\/p>\n<p>    Type your partition Number :1<\/p>\n<p>    Type Partition code     : 8e<\/p>\n<p>     Press &#8216;p&#8217; to print partition tables again<\/p>\n<p>    Press &#8216;w&#8217; to save and exit <\/p>\n<p>Step 2: if required, use partprobe command to update partition table entry into kernel. <\/p>\n<p>    [root@server1 ~]# partprobe \/dev\/sdc<\/p>\n<p>Step 3: Now create a Logical Volume using \/dev\/sdc1 partition<br \/>\n    [root@server1 ~]# pvcreate \/dev\/sdc1<\/p>\n<p>    [root@server1 ~]# vgcreate iSCSI_vg2 \/dev\/sdc1<\/p>\n<p>    [root@server1 ~]# lvcreate -n iscsi_lv2 -l 100%FREE iSCSI_vg2 <\/p>\n<p>Step 4: First you need to install &#8220;targetcli&#8221; package<\/p>\n<p>    [root@server1 ~]# yum install targetcli -y <\/p>\n<p>Step 5: Now run targetcli with no options to enter into interactive mode: <\/p>\n<p>    [root@server1 ~]# targetcli <\/p>\n<p>    \/> ls<\/p>\n<p>Now Configure the existing \/dev\/iSCSI_vg2\/iscsi_lv2 logical volume as a block-type backing store using the name of &#8220;server1.disk2&#8221;. <\/p>\n<p>    \/> cd backstores\/<\/p>\n<p>    \/backstores> ls<\/p>\n<p>    \/backstores> cd block <\/p>\n<p>    \/backstores\/block> ls<\/p>\n<p>    \/backstores\/block> create server1.disk2 \/dev\/iSCSI_vg2\/iscsi_lv2 <\/p>\n<p>    \/backstores\/block> ls<\/p>\n<p>Now Create a unique iSCSI Qualified Name (IQN) for the target. <\/p>\n<p>    \/backstores\/block> cd \/iscsi <\/p>\n<p>    \/iscsi> create iqn.2014-10.com.example.server1:iscsi-2<\/p>\n<p>Now an ACL for client node (initiator). the initiator will be connecting with it&#8217;s initiator name. <\/p>\n<p>    \/iscsi> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-2\/tpg1\/acls <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/acls> create iqn.2014-10.com.example.com.server1:tgt1<\/p>\n<p>By default authentication is enabled. To disable it: <\/p>\n<p>    \/> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-2\/tgp1\/<\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1> set attribute authentication=0<\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1> set attribute generate_node_acls=1<\/p>\n<p>Now Create a LUN under the target, The LUN should use the previously defined backing storage device named &#8220;server1.disk2&#8243; <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/acls> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-2\/tpg1\/luns <\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/luns> create \/backstores\/block\/server1.disk2 <\/p>\n<p>Now Configure a portal for the target to listen on 192.168.0.254<\/p>\n<p>    \/iscsi\/iqn.20&#8230;i-1\/tpg1\/luns> cd \/iscsi\/iqn.2014-10.com.example.server1:iscsi-2\/tpg1\/portals <\/p>\n<p>    \/iscsi\/iqn.20&#8230;\/tpg1\/portals> create 192.168.0.254<\/p>\n<p>Now view, verify and save the target server configuration <\/p>\n<p>    \/iscsi\/iqn.20&#8230;\/tpg1\/portals> cd \/<\/p>\n<p>    \/> ls<\/p>\n<p>Now Save this configuration<\/p>\n<p>        \/> saveconfig<\/p>\n<p>        \/> exit<\/p>\n<p>NOTE-: this configuration will be saved to &#8221; ~]# cat \/etc\/target\/saveconfig.json&#8221; <\/p>\n<p>Step 6: Now Enable and Start target service <\/p>\n<p>    [root@server1 ~]# systemctl enable target.service <\/p>\n<p>    [root@server1 ~]# systemctl restart target.service<br \/>\n    [root@server1 ~]# systemctl status target.service <\/p>\n<p>Step 7: Now Configure firewall to allow target service <\/p>\n<p>    [root@server1 ~]# firewall-cmd &#8211;permanent &#8211;add-port=3260\/tcp<br \/>\n    [root@server1 ~]# firewall-cmd &#8211;reload <\/p>\n<p>                    Accessing iSCSI Storage without CHAP Authentication  <\/p>\n<p>Step 1: First you need to install iSCSI initiator package<br \/>\n    [root@server2 ~]# yum install iscsi-initiator-utils -y <\/p>\n<p>Step 2: Now Create a unique iSCSI IQN name for the client initiator. Otherwise you will not able to connect\/login into IQN<\/p>\n<p>    [root@server2 ~]# vim \/etc\/iscsi\/initiatorname.iscsi <\/p>\n<p>    InitiatorName=iqn.2014-10.com.example.server1:tgt1<\/p>\n<p>    :wq (save and exit) <\/p>\n<p>Step 3: Now Enable and start iscsi client service <\/p>\n<p>    [root@server2 ~]# systemctl restart iscsid.service <\/p>\n<p>    [root@server2 ~]# systemctl enable iscsid.service <\/p>\n<p>Step 4: Now discover target using the following command:<br \/>\n    [root@server2 ~]# iscsiadm -m discovery -t st -p 192.168.0.254<\/p>\n<p>Step 5: Now you need to connect iscsi storage into system <\/p>\n<p>[root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:iscsi-2 -p 192.168.0.254 -l <\/p>\n<p>    [root@server2 ~]# fdisk -l <\/p>\n<p>Step 6: Create label,  create a new primary partition, format it using xfs file system and the mount it on \/iscsi2 directory.  <\/p>\n<p>    [root@server2 ~]# parted &#8211;script \/dev\/sdb &#8220;mklabel msdos&#8221; <\/p>\n<p>    [root@server2 ~]# parted &#8211;script \/dev\/sdb &#8220;mkpart primary 0% 100%&#8221; <\/p>\n<p>    [root@server2 ~]# mkfs.xfs -i size=1024 -s size=4096 \/dev\/sdb1 <\/p>\n<p>    [root@server2 ~]# mount \/dev\/sdb1 \/iscsi2<\/p>\n<p>    [root@server2 ~]# df -hT <\/p>\n<p>Step 7: Now make it persistent entry to mount at booting <\/p>\n<p>    [root@server2 ~]# blkid <\/p>\n<p>    Now Copy the UUID of \/deb\/sdc1 and paste it into \/etc\/fstab as following: <\/p>\n<p>    [root@server2 ~]# vim \/etc\/fstab <\/p>\n<p>    UUID=&#8221;be41aa12-1e30-4678-8c19-da3506df1d84&#8243; \/iscsi2                xfs     _netdev     0 0<\/p>\n<p>    :wq (save and exit)  <\/p>\n<p>    [root@server2 ~]# umount \/mnt\/<\/p>\n<p>    [root@server2 ~]# mount -a<\/p>\n<p>    [root@server2 ~]# df -h <\/p>\n<p>Step 8: Now unmount the iSCSI Storage <\/p>\n<p>    [root@server2 ~]# cd <\/p>\n<p>    [root@server2 ~]# umount \/iscsi2<\/p>\n<p>    [root@server2 ~]# vim \/etc\/fstab <\/p>\n<p>    Remove the following entry form this file<\/p>\n<p>     UUID=&#8221;be41aa12-1e30-4678-8c19-da3506df1d84&#8243; \/mnt                xfs     _netdev         0 0<\/p>\n<p>    :wq (save and exit)<\/p>\n<p>    To Disconnect iSCSI storage  <\/p>\n<p>root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:iscsi-2 -p 192.168.0.254 -u<\/p>\n<p>    To delete cache as well <\/p>\n<p>    [root@server2 ~]# iscsiadm -m node -T iqn.2014-10.com.example.server1:iscsi-2 -p 192.168.0.254 -o delete <\/p>\n<p>    Now if you want to connect it again, you need to discover it again.<br \/>\nNOTE-: iSCSI store caching in  \/var\/lib\/iscsi\/ directory sometimes when we try to add another iscsi targets, system takes some information<br \/>\n    from cache. so you have two option to address it. <\/p>\n<p>    1. reboot your system <\/p>\n<p>    2. remove iscsi cache <\/p>\n<p>    To remove nodes cache<br \/>\n    [root@server2 ~]# rm -rf \/var\/lib\/iscsi\/nodes\/*<\/p>\n<p>    To remove send_targets cache <\/p>\n<p>    [root@server2 ~]# rm -rf \/var\/lib\/iscsi\/send_targets\/*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>iSCSI Configuration on RHEL 7 \/ CentOS 7 <\/p>\n<p>Step 1: First you need to create partition <\/p>\n<p> [root@server1 ~]# fdisk -c \/dev\/sdb <\/p>\n<p> Press &#8216;p&#8217; to print partition table <\/p>\n<p> Press &#8216;n&#8217; to create a new partition <\/p>\n<p> Press &#8216;p&#8217; to create primary partition <\/p>\n<p> Type Partition Number : [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5930"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5930"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5930\/revisions"}],"predecessor-version":[{"id":5931,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5930\/revisions\/5931"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}