User Tools

Site Tools


unix:linux:iscsi_tricks_and_techniques

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
unix:linux:iscsi_tricks_and_techniques [2019/08/14 19:43] rodolicounix:linux:iscsi_tricks_and_techniques [2022/12/17 14:05] (current) – [Adding new target on target device] rodolico
Line 30: Line 30:
  
 <code perl addAlliSCSIS.pl> <code perl addAlliSCSIS.pl>
-#! /usr/bin/perl -w+#! /usr/bin/env perl
  
-my @servers = ( '10.5.136.1' ); +use strict; 
 +use warnings; 
 + 
 +# change following to be a list of 1 or more iSCSI targets to be queried 
 +my @servers = ( '10.10.10.10','10.10.10.9' ); 
 my %targets; my %targets;
  
  
 foreach my $server ( @servers ) { foreach my $server ( @servers ) {
 +   print "\n" . '-'x40 . "\nGetting targets on server $server\n" . '-'x40 . "\n";
    my @list = `iscsiadm -m discovery -t st -p $server`;    my @list = `iscsiadm -m discovery -t st -p $server`;
    chomp @list;    chomp @list;
Line 50: Line 55:
       # only add them if they are in this IP       # only add them if they are in this IP
       $targets{ $targetName } = $portal if $portal =~ m/^$server/;       $targets{ $targetName } = $portal if $portal =~ m/^$server/;
 +      print "$targetName\t$targets{ $targetName }\n";
    }    }
 } }
  
 +print "\n" . '-'x40 . "\nGetting active sessions\n". '-'x40 . "\n";
 # now, get active sessions so we can filter them # now, get active sessions so we can filter them
 my @activeSessions = `iscsiadm -m session`; my @activeSessions = `iscsiadm -m session`;
 chomp @activeSessions; chomp @activeSessions;
-foreach $session ( @activeSessions ) { +foreach my $session ( @activeSessions ) { 
-   $session =~ m/([0-9,:]+).* (.*)$/;+   $session =~ m/^.*[^0-9:.]([0-9,:.]+).*(iqn\S*)/;
    my ( $portal,$targetName ) = ( $1,$2 );    my ( $portal,$targetName ) = ( $1,$2 );
-   delete $targets{ $targetName if exists( $targets{$targetName} );+   print "$portal\t$targetName"; 
 +   if exists( $targets{$targetName} ) ) { 
 +      print "\tNOT updating\n"; 
 +      delete $targets{ $targetName }; 
 +   } else { 
 +      print "Needs to be added\n"; 
 +   }
 } }
  
Line 74: Line 87:
 } }
 # print `ls /dev/disk/by-path/`; # print `ls /dev/disk/by-path/`;
 +
 </code> </code>
  
Line 107: Line 121:
 </code> </code>
  
-Edit /etc/iet/ietd.conf and add the following lines+Edit /etc/iet/ietd.conf (Linux) or /etc/ctl.conf (BSD) and add the following lines
  
 <code>   <code>  
Line 115: Line 129:
 </code> </code>
 Restart iet Restart iet
-<code bash>  /etc/init.d/iscsitarget restart</code>+<code bash>/etc/init.d/iscsitarget restart # Linux 
 +service ctld reload # FreeBSD 
 +</code>
  
 ==== Adding new target to initiator ==== ==== Adding new target to initiator ====
Line 162: Line 178:
 # first, log out of the session # first, log out of the session
 iscsiadm -m node --target='name of target' --portal "ip:port" --logout iscsiadm -m node --target='name of target' --portal "ip:port" --logout
-# now, do a discovery and delete the entry from your local database +# now, do a remove it from the session 
-iscsiadm -m discovery --target='name of target' --portal "ip:port" -o delete+iscsiadm -m node --target='name of target' --portal "ip:port" -o delete
 </code> </code>
  
unix/linux/iscsi_tricks_and_techniques.1565829800.txt.gz · Last modified: 2019/08/14 19:43 by rodolico