sandip's blog

iscsi notes

iscsi target

  • Install iscsi utils:
    yum install scsi-target-utils
  • Bring up tgtd:
    chkconfig tgtd on
    service tgtd start
  • Define an iscsi target name:
    # tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2012-10.com.linuxweblog.srv01:lv1_iscsi0
  • Delete specific iscsi target:
    # tgtadm --lld iscsi --op delete --mode target --tid 1
  • Add a logical unit to the target:
    # tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/vg1/lv1_iscsi0
  • Delete logical unit:
    # tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1
  • Enable the target to accept any initiators:
    # tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
  • View configuration:
    # tgtadm --lld iscsi --op show --mode target
  • Save the tgt conf:
    # tgt-admin --dump >/etc/tgt/targets.conf

iscsi initiator

  • install the initiator client:
    # yum install iscsi-initiator-utils
  • startup the iscsi daemon so all kernel modules get loaded:
    # chkconfig iscsid on
    # chkconfig iscsi on
    # service iscsid start
  • Discover targets:
    # iscsiadm --mode discovery --type sendtargets --portal 192.168.1.11
  • Login to target:
    # service iscsi restart
  • To manually login:
    # iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.srv01:lv1_iscsi0 --portal 192.168.1.11 --login
  • To manually logout:
    # iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.srv01:lv1_iscsi0 --portal 192.168.1.11 --logout
  • To delete targets:
    # iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.srv01:lv1_iscsi0 --portal 192.168.1.11 -o delete
  • List sessions:
    # iscsiadm -m session
  • List nodes:
    # iscsiadm -m node

Accessing ssh servers behind NAT

Create a "config" file in your "~/.ssh" directory with the below contents:

Host server1
  Hostname server1.example.com
  HostKeyAlias server1
  CheckHostIP no
  Port 221

Host server2
  Hostname server2.example.com
  HostKeyAlias server2
  CheckHostIP no
  Port 222

The key is to set CheckHostIP to "no" and use "HostKeyAlias" to specify an alias that should be used instead of the real host name when looking up or saving the host key in the host key database files.

The Port line avoids having to specify the port when connectig.

Connect to corresponding host via:

$ ssh {user}@server1
$ ssh {user}@server2

strace all apache child processes

# ps h --ppid `cat /var/run/httpd.pid` -o pid | awk '{print "-v -ff -tt -T -s 1024 -o /tmp/strace.out -p " $1}' | xargs strace

This will attach strace to each of the apache child processes.

-v verbose
-ff with -o will log the output to "/tmp/strace.out.{pid}" and follow forks.
-tt prints the timestamp of each call.
-T prints the duration of each call.
-s specifies the maximum size of the output string to more than the default 32.

Related links:

md5 and sha1 digest with openssl

md5 digest:

echo -n 'md5 digest of text' | openssl dgst -md5
841fc570f41fad1a64cc237b16127225

sha1 digest:

echo -n 'sha1 digest of text' | openssl dgst -sha1
80efdb4abbeb92c0ea15a4146d68c39adff5ad47

base64 encoding decoding with openssl

Base64 encoding with openssl:

echo -n 'encode this with base64' | openssl enc -base64
ZW5jb2RlIHRoaXMgd2l0aCBiYXNlNjQ=

Base64 decoding with openssl:

echo 'ZW5jb2RlIHRoaXMgd2l0aCBiYXNlNjQ=' | openssl enc -base64 -d
encode this with base64

Handling filenames with spaces, carriage returns or other control characters

find -print0 | while IFS= read -rd $'\0' filename ; do echo "[$filename]" ; done

-print0, prints the full file name on the standard output, followed by a null character instead of the newline character.

IFS, is the "Internal Field Separator" that is used for word splitting after expansion. Here, IFS is set to null string.

-r, specifies that backslash "\" does not act as an escape character.

-d, is the delimeter. Which in this case is the null character '\0'.

$'\0', the $ prefixed single quoted string decodes the backslash escape character. In this case a null character.

[], is simply there to print out the text, so you notice any spaces in the beginning and end of text.

Get public IP Address

Get current public IP via command line curl and wget.

With curl:

curl icanhazip.com
curl ifconfig.me

With wget:

wget -qO- icanhazip.com
wget -qO- ifconfig.me/ip

redirect stdout/stderr within bash script

This executes the date command via shell script and logs it to the specified file with current pid.

#!/bin/bash
LOG=$$.log
exec > $LOG 2>&1
date

vBulletin login quota

If you have typed in your admin password in vBulletin more than 5 times and get locked. Look at the vbulletin "strikes" table and truncate it to get back in and not have to wait for the 15 minutes lock out time.

TRUNCATE strikes;

Extract IP address

One liner with grep to extract the IP addresses from a file.

grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' /path/to/file

The "-o" option prints only the matched parts.

One liner with perl:

perl -ne 'print if s/.*((\d{1,3}\.){3}\d{1,3}).*/\1/' /path/to/file

Comment