Вы находитесь на странице: 1из 13

We are going to configure iSCSI Target as a shared storage and iSCSI Initiator as a

client to access that storage.


 

Here, we have iSCSI Target (Server) machine


(rhel7dns01.example.com/192.168.122.100) & iSCSI Initiator (Client) machine
(rhel7dns02.example.com/192.168.122.200). We will create a 512MB logical volume (lv)
on iSCSI Target machine and will configure as a share disk for the client.
 

iSCSI target configuration:


To create an iSCSI target, We need to follow several steps on the server machine.
 

To identify the disk to be used as a iSCSI target storage:


 

[root@rhel7dns01 ~]# cat /proc/partitions


major minor #blocks name
 

11 0 3799040 sr0
252 0 10485760 vda
252 1 512000 vda1
252 2 9972736 vda2
252 16 1048576 vdb
253 0 1048576 dm-0
253 1 8880128 dm-1
253 2 524288 dm-2
 

[root@rhel7dns01 ~]# fdisk -l


:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::
Disk /dev/vdb: 1073 MB, 1073741824 bytes, 2097152 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
 

:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::


 

To create a 512MB lv partition:


[root@rhel7dns01 ~]# pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created
 

[root@rhel7dns01 ~]# vgcreate sanvg01 /dev/vdb


Volume group "sanvg01" successfully created
 

[root@rhel7dns01 ~]# lvcreate -L 512M -n lunlv01 sanvg01


Logical volume "lunlv01" created.
 

To verify system configuration:


[root@rhel7dns01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.122.100 rhel7dns01.example.com rhel7dns01
192.168.122.200 rhel7dns02.example.com rhel7dns02
 

[root@rhel7dns01 ~]# ifconfig eth0


eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.100 netmask 255.255.255.0 broadcast 192.168.122.255
inet6 fe80::5054:ff:fe23:5378 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:23:53:78 txqueuelen 1000 (Ethernet)
RX packets 905 bytes 94602 (92.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 430 bytes 45840 (44.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 

To Install required rpm on the system:


[root@rhel7dns01 ~]# # yum install -y targetcli
 

:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::


Installed:
targetcli.noarch 0:2.1.fb37-3.el7
 

Dependency Installed:
pyparsing.noarch 0:1.5.6-9.el7 python-configshell.noarch 1:1.1.fb14-1.el7 python-
kmod.x86_64 0:0.9-4.el7
python-rtslib.noarch 0:2.1.fb50-1.el7 python-urwid.x86_64 0:1.1.1-3.el7
 

Complete!
 

To configure the iSCSI target for Share Disk:


[root@rhel7dns01 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb37
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
 

/> cd backstores/block
/backstores/block> create sharedisk01 /dev/sanvg01/lunlv01
Created block storage object sharedisk01 using /dev/sanvg01/lunlv01.
 

/backstores/block> cd /
/> cd iscsi
/iscsi> create iqn.2015-03.com.example:lun1
Created target iqn.2015-03.com.example:lun1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
 

/iscsi> cd iqn.2015-03.com.example:lun1/tpg1/
/iscsi/iqn.20...ple:lun1/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls,
no-auth]
o- acls ................................................................................................................ [ACLs: 0]
o- luns ................................................................................................................ [LUNs: 0]
o- portals .......................................................................................................... [Portals: 1]
o- 0.0.0.0:3260 ...........................................................................................................
[OK]
 

/iscsi/iqn.20...ple:lun1/tpg1> portals/ create 192.168.122.100


Using default IP port 3260
Could not create NetworkPortal in configFS.
 

/iscsi/iqn.20...ple:lun1/tpg1> acls/ create iqn.2015-03.com.example:clientlun1


Created Node ACL for iqn.2015-03.com.example:clientlun1
 

/iscsi/iqn.20...ple:lun1/tpg1> luns/ create /backstores/block/sharedisk01


Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2015-03.com.example:clientlun1
 

/iscsi/iqn.20...ple:lun1/tpg1> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
 
Main configuration file /etc/target/saveconfig.json:
[root@rhel7dns01 ~]# cat /etc/target/saveconfig.json
Click this link to download the saveconfig.json file 
 

To start, enable and verify the iSCSI target service:


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

[root@rhel7dns01 ~]# systemctl start target.service


 

[root@rhel7dns01 ~]# netstat -atunp|grep 3260


tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN -
 

To enable/open 3260 port on Firewall (if Required):


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

iSCSI initiator configuration:


To create an iSCSI initiator, we need to follow several steps on the client machine.
To verify system configuration:
[root@rhel7dns02 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.122.100 rhel7dns01.example.com rhel7dns01
192.168.122.200 rhel7dns02.example.com rhel7dns02
 

[root@rhel7dns02 ~]# ifconfig eth0


eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.200 netmask 255.255.255.0 broadcast 192.168.122.255
inet6 fe80::5054:ff:fe09:dc6a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:09:dc:6a txqueuelen 1000 (Ethernet)
RX packets 2049 bytes 197569 (192.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 356 bytes 35720 (34.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 

To Install required rpm on the system:


[root@rhel7dns02 ~]# 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.
Package iscsi-initiator-utils-6.2.0.873-29.el7.x86_64 already installed and latest version
Nothing to do
 

To verify the initiator name on the client system (as per the acls):
[root@rhel7dns02 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2015-03.com.example:clientlun1
 

To discover the target (sendtargets or st):


[root@rhel7dns02 ~]# iscsiadm -m discovery -t st -p rhel7dns01.example.com
192.168.122.100:3260,1 iqn.2015-03.com.example:lun1
 

To login to the target (sendtargets or st):


[root@rhel7dns02 ~]# iscsiadm -m node -T iqn.2015-03.com.example:lun1 -l
Logging in to [iface: default, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260] (multiple)
Login to [iface: default, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260] successful.
 

To verify the devices node for the iSCSI disk:


[root@rhel7dns02 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 512M 0 disk
sr0 11:0 1 4.3G 0 rom /mnt
vda 252:0 0 10G 0 disk
├─vda1 252:1 0 500M 0 part /boot

└─vda2 252:2 0 9.5G 0 part

├─rhel-swap 253:0 0 1G 0 lvm [SWAP]

└─rhel-root 253:1 0 8.5G 0 lvm /


 

[root@rhel7dns02 ~]# tail /var/log/messages


Apr 6 07:30:43 rhel7dns02 kernel: scsi 2:0:0:0: alua: Attached
Apr 6 07:30:43 rhel7dns02 kernel: sd 2:0:0:0: [sda] 1048576 512-byte logical blocks:
(536 MB/512 MiB)
Apr 6 07:30:43 rhel7dns02 kernel: sd 2:0:0:0: [sda] Write Protect is off
Apr 6 07:30:43 rhel7dns02 kernel: sd 2:0:0:0: [sda] Write cache: enabled, read cache:
enabled, supports DPO and FUA
Apr 6 07:30:43 rhel7dns02 kernel: sda: unknown partition table
Apr 6 07:30:43 rhel7dns02 kernel: sd 2:0:0:0: [sda] Attached SCSI disk
Apr 6 07:30:43 rhel7dns02 iscsid: Could not set session1 priority. READ/WRITE
throughout and latency could be affected.
Apr 6 07:30:43 rhel7dns02 iscsid: Connection1:0 to [target: iqn.2015-
03.com.example:lun1, portal: 192.168.122.100,3260] through [iface: default] is
operational now
 

[root@rhel7dns02 ~]# iscsiadm -m session -P3


iSCSI Transport Class version 2.0-870
version 6.2.0.873-28
Target: iqn.2015-03.com.example:lun1 (non-flash)
Current Portal: 192.168.122.100:3260,1
Persistent Portal: 192.168.122.100:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.2015-03.com.example:clientlun1
Iface IPaddress: 192.168.122.200
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: 2 State: running
scsi2 Channel 00 Id 0 Lun: 0
Attached scsi disk sda State: running
 
 

To identify the iSCSI target disk on client system:


[root@rhel7dns02 ~]# fdisk -l
:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::
Disk /dev/sda: 536 MB, 536870912 bytes, 1048576 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
 

[root@rhel7dns02 ~]# cat /proc/partitions


major minor #blocks name
 

252 0 10485760 vda


252 1 512000 vda1
252 2 9972736 vda2
11 0 4470784 sr0
253 0 1048576 dm-0
253 1 8880128 dm-1
8 0 524288 sda
 

To create file system & persistent mount:


[root@rhel7dns02 ~]# pvcreate /dev/sda
Physical volume "/dev/sda" successfully created
 

[root@rhel7dns02 ~]# vgcreate datavg01 /dev/sda


Volume group "datavg01" successfully created
 

[root@rhel7dns02 ~]# lvcreate -L 400M -n datalv01 datavg01


Logical volume "datalv01" created.
 

[root@rhel7dns02 ~]# mkdir /datafs


 

[root@rhel7dns02 ~]# mkfs.ext4 /dev/datavg01/datalv01


mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=4096 blocks
102400 inodes, 409600 blocks
20480 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
50 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
 

Allocating group tables: done


Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
 

[root@rhel7dns02 ~]# blkid


/dev/vda1: UUID="5dcdd9e6-3da8-4cf7-ae50-94fff809569d" TYPE="xfs"
/dev/vda2: UUID="r6yOzA-6RlM-PkNY-Uo4p-X0XW-M2AX-cAZidE"
TYPE="LVM2_member"
/dev/sr0: UUID="2013-11-27-06-31-43-00" LABEL="RHEL-7.0 Server.x86_64"
TYPE="iso9660" PTTYPE="dos"
/dev/mapper/rhel-swap: UUID="4824d65a-a9b7-42b5-b3ab-0859d9d4aef1"
TYPE="swap"
/dev/mapper/rhel-root: UUID="cd688587-7979-49c4-891a-3fca0dd133f1" TYPE="xfs"
/dev/mapper/datavg01-datalv01: UUID="02815ae7-ee37-48fa-9bbb-b21d957c7885"
TYPE="ext4"
/dev/sda: UUID="pK0Nvf-cPXv-rV4e-xQkq-qilF-d5Ur-Zppvsm" TYPE="LVM2_member"
 

[root@rhel7dns02 ~]# echo "UUID="02815ae7-ee37-48fa-9bbb-b21d957c7885"


/datafs ext4 _netdev 0 0" >> /etc/fstab
 

[root@rhel7dns02 ~]# mount -a


 

[root@rhel7dns02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 8.5G 3.0G 5.5G 35% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 80K 497M 1% /dev/shm
tmpfs 497M 7.1M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/vda1 497M 124M 373M 25% /boot
/dev/sr0 4.3G 4.3G 0 100% /mnt
/dev/mapper/datavg01-datalv01 380M 2.3M 354M 1% /datafs
 

To verify the mount point after reboot the client machine:


[root@rhel7dns02 ~]# reboot
Connection to 192.168.122.200 closed by remote host.
Connection to 192.168.122.200 closed.
 

[munshi@munshi ~]$ ssh root@192.168.122.200


root@192.168.122.200's password:
Last login: Mon Apr 6 06:26:32 2015 from 192.168.122.1
 

[root@rhel7dns02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 8.5G 3.0G 5.5G 35% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 80K 497M 1% /dev/shm
tmpfs 497M 7.1M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/vda1 497M 124M 373M 25% /boot
/dev/mapper/datavg01-datalv01 380M 2.3M 354M 1% /datafs
 

Troubleshooting:
Connectivity Issue:
[root@rhel7dns02 nodes]# ping rhel7dns01.example.com
PING rhel7dns01.example.com (192.168.122.100) 56(84) bytes of data.
64 bytes from rhel7dns01.example.com (192.168.122.100): icmp_seq=1 ttl=64
time=0.485 ms
64 bytes from rhel7dns01.example.com (192.168.122.100): icmp_seq=2 ttl=64
time=0.292 ms
^C
--- rhel7dns01.example.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.292/0.388/0.485/0.098 ms
 

[root@rhel7dns02 ~]# iscsiadm -m discovery -t st -p rhel7dns01.example.com


iscsiadm: cannot make connection to 192.168.122.100: No route to host
iscsiadm: cannot make connection to 192.168.122.100: No route to host
iscsiadm: cannot make connection to 192.168.122.100: No route to host
iscsiadm: cannot make connection to 192.168.122.100: No route to host
^Ciscsiadm: caught SIGINT, exiting...
 

Able to Ping but cant able acces 3260 port.


Check iptables or use telnet to verify 3260 port accessible or not.
 

[root@rhel7dns02 ~]# iscsiadm -m discovery -t st -p rhel7dns01.example.com


192.168.122.100:3260,1 iqn.2015-03.com.example:lun1
[root@rhel7dns02 ~]# telnet rhel7dns01.example.com 3260
Trying 192.168.122.100...
Connected to rhel7dns01.example.com.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
 
 

Authentication Issue:
[root@rhel7dns02 nodes]# iscsiadm -m node -T iqn.2015-03.com.example:lun1 -l
Logging in to [iface: default, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2015-03.com.example:lun1,
portal: 192.168.122.100,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
 

[root@rhel7dns01 ~]# vim /etc/target/saveconfig.json


:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::
"targets": [
{
"fabric": "iscsi",
"tpgs": [
{
"attributes": {
"authentication": 0,
:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::
 

manually change the authentication parameter to 0 in the main configuration as above


or run below command:
 

[root@rhel7dns01 ~]# targetcli /iscsi/iqn.2015-03.com.example:lun1/tpg1 set


attribute authentication=0
Parameter authentication is now '0'.
 

[root@rhel7dns01 ~]# targetcli saveconfig


Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
 

[root@rhel7dns01 ~]# cat /etc/target/saveconfig.json|grep authentication


"authentication": 0,
 

Restart the services:


[root@rhel7dns01 ~]# systemctl restart target.service
 

User Authentication Configuration:


On Server Side:
[root@rhel7dns01 ~]# targetcli /iscsi/iqn.2015-03.com.example:lun1/tpg1 set
attribute authentication=1
Parameter authentication is now '1'.
 

[root@rhel7dns01 ~]# targetcli /iscsi/iqn.2015-


03.com.example:lun1/tpg1/acls/iqn.2015-03.com.example:clientlun1 set auth
userid=munshi
Parameter userid is now 'munshi'.
 

[root@rhel7dns01 ~]# targetcli /iscsi/iqn.2015-


03.com.example:lun1/tpg1/acls/iqn.2015-03.com.example:clientlun1 set auth
password=munshi
Parameter password is now 'munshi'.
 

[root@rhel7dns01 ~]# targetcli saveconfig


Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
 

[root@rhel7dns01 ~]# systemctl restart target.service


 

On Client Side:
[root@rhel7dns02 nodes]# vi /etc/iscsi/iscsid.conf
 

:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::


# *************
# CHAP Settings
# *************
 

# To enable CHAP authentication set node.session.auth.authmethod


# to CHAP. The default is None.
node.session.auth.authmethod = CHAP
 

# To set a CHAP username and password for initiator


# authentication by the target(s), uncomment the following lines:
node.session.auth.username = munshi
node.session.auth.password = munshi
:::::::::::::::::::::::::::::::::::: CUT SOME OUTPUT ::::::::::::::::::::::::::::::::::::
 

[root@rhel7dns02 nodes]# vi /etc/iscsi/initiatorname.iscsi


InitiatorName=iqn.2015-03.com.example:clientlun1
 
[root@rhel7dns02 nodes]# iscsiadm -m discovery -t st -p
rhel7dns01.example.com
192.168.122.100:3260,1 iqn.2015-03.com.example:lun1
 

[root@rhel7dns02 nodes]# iscsiadm -m node -T iqn.2015-03.com.example:lun1 -l


Logging in to [iface: default, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260] (multiple)
Login to [iface: default, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260] successful.
 

[root@rhel7dns02 nodes]# iscsiadm -m node -T iqn.2015-03.com.example:lun1 -u


Logging out of session [sid: 37, target: iqn.2015-03.com.example:lun1, portal:
192.168.122.100,3260]
Logout of [sid: 37, target: iqn.2015-03.com.example:lun1, portal: 192.168.122.100,3260]
successful.
 

Thank you very much to being with us. Hope this document will help you to configure
iSCSI target & initiator on RHEL7 (Including PowerLinux

Вам также может понравиться