Thursday, January 30, 2014

How to Create iSCSI Server and Target

Create ISCI Server 
  1. yum install scsi-target-utils.x86_64' 
  2. Turn on tgtd 
    1. # chkconfig tgtd on 
    2. # service tgtd start Starting SCSI target daemon:                               [  OK  ]  
  3. Use tgtadm  to configure target 
    1. tgtadm -help  

  1. Check if any existing targets exist 
    1. tgtadm --lld iscsi --mode target --op show 

  2. Configure the first target ID as 101 
    1. # tgtadm --lld iscsi --mode target --op new --tid 101 --targetname iqn.server1.example.com:target1  
  3. Verify the target  
    1. # tgtadm --lld iscsi --mode target --op show   
  4. Create 1G logical volume for testing (of course in the real world you'd use a storage volume or lun) 
    1. ]# lvcreate -L 1G -n lv_iscsi vg_server1  
  5. Attach LUN to the ISCSI Target (decide which disk to use - example in step above) 
    1. ]# tgtadm --lld iscsi --mode logicalunit --op new --tid 101 --lun 1 --backing-store /dev/mapper/vg_server1-lv_iscsi  
    2.  repeat of you want two 'luns'  
  6. Verify new lun 
    1. # tgtadm --lld iscsi --mode target --op show 

  7. Share to specific Network or Client 
    1. # tgtadm --lld iscsi --mode target --op bind --tid 101 --initiator-address 192.168.0.0/24 

  8. Configure authentication to the target 
    1. # tgtadm --lld iscsi --mode account --op new --user iclient --password password  
  9. Attach user to the 101 target 
    1. # tgtadm --lld iscsi --mode account --op bind --tid 101 --user iclient 

  10. Verify User was attached to target 101 
    1. # tgtadm --lld iscsi --mode account --op show Account list:     iclient 
    2. # tgtadm --lld iscsi --mode target --op show 

  11. Backup the original configuration 
    1. # cp /etc/tgt/targets.conf /etc/tgt/targets.orig  
  12. Create configuration file from the dump command 
    1. # tgt-admin --dump default-driver iscsi  <target iqn.server1.com.example.target1>         backing-store /dev/mapper/vg_server1-lv_iscsi         incominguser iclient PLEASE_CORRECT_THE_PASSWORD         initiator-address 192.168.0.0/24 </target>   
  13. Copy or 'echo' the output of above dump command into targets.conf file to allow for persitance  
    1. tgt-admin --dump >> /etc/tgt/targets.conf 
    2. remove or comment out the duplicate 'default-driver iscsi'  
  14. Verify configuration after restart 
    1. # service tgtd restart  
  15. Check what ports are in use 
    1. # netstat -pantl | grep tgt  
  16. Add firewall rules (if using iptables) 

Client Configuration 

  1. Install client tools if not installed 
    1. # yum install iscsi-initiator-utils 

  1. Configure for restart  
    1. # service iscsid restart Stopping iscsid: Starting iscsid:                                           [  OK  ] [root@tester1 ~]# service iscsid force-start Starting iscsid: [root@tester1 ~]# chkconfig --list iscsid iscsid          0:off   1:off   2:off   3:on    4:on    5:on    6:off 

  2. # iscsiadm -m discovery -t st -p 192.168.56.102 
    1. # dmesg | tail  
  3. # iscsiadm -m node T iqn.2013-10.com.example.server1:target1 -p 192.168.56.102:3260,1 -l 
################### 
Firs not down question points correctly 
 Exam use FQDN  DON’T FORGET TO LOGOUT AT  END ITS VERY IMP  
  
yum install iscsi* -y 
man iscsiadm , go to end of page it will be given 
iscsiadm --mode discoverydb --type sendtargets --portal 192.168.0.254 --discover [ change to server ip ] 
192.168.0.254:3260,1 iqn.2010-09.com.example:rdisks.server24 
now copy IQN  "iqn.2010-09.com.example:rdisks.server24" IP 192.168.0.254 , leave port as it is. 
Copy Login line , replace iqn and ip of server 
iscsiadm --mode node --targetname iqn.2010-09.com.example:rdisks.server24 --portal 192.168.0.254:3260 --login 
now fdisk -l 
check the mounted /dev/sda 
create partition of given size 
now mkfs.xt4 /dev/sda1 
blkid /dev/sda1 and copy uuid [ UUID="f48afc51-d621-4046-932e-b6084d2286be" ] 
vim /etc/fstab 
   [ Device Name]                                                              [Where to store] file-type   defaults 
UUID="f48afc51-d621-4046-932e-b6084d2286be"     /mnt/storage       ext4      _netdev 0 0 
umount -a 
mount  -a 
go to mount /mnt/storage 
download file and chmod 644 to file

No comments:

Post a Comment