unix:linux:iscsi_tricks_and_techniques
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
unix:linux:iscsi_tricks_and_techniques [2016/09/06 19:57] – external edit 127.0.0.1 | unix:linux:iscsi_tricks_and_techniques [2022/12/17 14:05] (current) – [Adding new target on target device] rodolico | ||
---|---|---|---|
Line 22: | Line 22: | ||
===== Tricks and Techniques ===== | ===== Tricks and Techniques ===== | ||
+ | |||
+ | ==== Script to update all targets ==== | ||
+ | |||
+ | For some reason, I'm occasionally a little out of sync between what my target offers and what my initiator knows about. The following script will not //remove// anything, but it will add every target offered by the iscsi target. | ||
+ | |||
+ | Add one or more entries into @servers, and it will scan the targets in question, then compare against what our initiator knows, then add any new entries. | ||
+ | |||
+ | <code perl addAlliSCSIS.pl> | ||
+ | #! / | ||
+ | |||
+ | use strict; | ||
+ | use warnings; | ||
+ | |||
+ | # change following to be a list of 1 or more iSCSI targets to be queried | ||
+ | my @servers = ( ' | ||
+ | my %targets; | ||
+ | |||
+ | |||
+ | foreach my $server ( @servers ) { | ||
+ | print " | ||
+ | my @list = `iscsiadm -m discovery -t st -p $server`; | ||
+ | chomp @list; | ||
+ | # @list contains lines of type | ||
+ | # 10.19.209.2: | ||
+ | # split them apart and add them to the hash | ||
+ | | ||
+ | my ( $portal, $targetName ) = split( ' ', $entry ); | ||
+ | # $portal has some extra info after a comma, so clean it up | ||
+ | $portal =~ m/ | ||
+ | $portal = $1; | ||
+ | # some targets return multiple IP's for a given name, so | ||
+ | # only add them if they are in this IP | ||
+ | $targets{ $targetName } = $portal if $portal =~ m/ | ||
+ | print " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | print " | ||
+ | # now, get active sessions so we can filter them | ||
+ | my @activeSessions = `iscsiadm -m session`; | ||
+ | chomp @activeSessions; | ||
+ | foreach my $session ( @activeSessions ) { | ||
+ | | ||
+ | my ( $portal, | ||
+ | print " | ||
+ | if ( exists( $targets{$targetName} ) ) { | ||
+ | print "\tNOT updating\n"; | ||
+ | delete $targets{ $targetName }; | ||
+ | } else { | ||
+ | print "Needs to be added\n"; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # check if we have any new entries and bail if not | ||
+ | if ( scalar keys %targets ) { | ||
+ | # We have new entries, so run them; | ||
+ | | ||
+ | my $portal = $targets{$targetName}; | ||
+ | print " | ||
+ | `iscsiadm -m node --targetname ' | ||
+ | } | ||
+ | } else { | ||
+ | print "No new entries\n"; | ||
+ | } | ||
+ | # print `ls / | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Fixing bolluxed machine ==== | ||
+ | |||
+ | Ok, your initiator is in a really bad shape, or you did something on the target you shouldn' | ||
+ | |||
+ | <code bash> | ||
+ | / | ||
+ | rm -fR / | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | **Note**: This is on an old Debian Wheezy machine, so start/stop commands are different after that. | ||
+ | |||
+ | The first line stops the initiator. The second line removes all remembered connections from the initiators cache, then we start the initiator again. | ||
+ | |||
+ | At this point, we don't " | ||
==== Viewing targets exported from a target device, from the target device ==== | ==== Viewing targets exported from a target device, from the target device ==== | ||
Line 37: | Line 121: | ||
</ | </ | ||
- | Edit / | + | Edit / |
< | < | ||
Line 45: | Line 129: | ||
</ | </ | ||
Restart iet | Restart iet | ||
- | <code bash> | + | <code bash>/ |
+ | service ctld reload # FreeBSD | ||
+ | </ | ||
==== Adding new target to initiator ==== | ==== Adding new target to initiator ==== | ||
Line 92: | Line 178: | ||
# first, log out of the session | # first, log out of the session | ||
iscsiadm -m node --target=' | iscsiadm -m node --target=' | ||
- | # now, do a discovery and delete the entry from your local database | + | # now, do a remove it from the session |
- | iscsiadm -m discovery | + | iscsiadm -m node --target=' |
</ | </ | ||
unix/linux/iscsi_tricks_and_techniques.1473209837.txt.gz · Last modified: 2016/09/06 19:57 by 127.0.0.1