iscsi notes
Mon, 10/15/2012 - 10:13 — sandipiscsi target
-
Install iscsi utils:
yum install scsi-target-utils
chkconfig tgtd on
service tgtd start
# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2012-10.com.linuxweblog.sr v01:lv1_iscsi0
# tgtadm --lld iscsi --op delete --mode target --tid 1
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/vg1/lv1_iscsi0
# tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1
# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
# tgtadm --lld iscsi --op show --mode target
# tgt-admin --dump >/etc/tgt/targets.conf
iscsi initiator
-
install the initiator client:
# yum install iscsi-initiator-utils
# chkconfig iscsid on
# chkconfig iscsi on
# service iscsid start
# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.11
# service iscsi restart
# iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.sr v01:lv1_iscsi0 --portal 192.168.1.11 --login
# iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.sr v01:lv1_iscsi0 --portal 192.168.1.11 --logout
# iscsiadm --mode node --targetname iqn.2012-10.com.linuxweblog.sr v01:lv1_iscsi0 --portal 192.168.1.11 -o delete
# iscsiadm -m session
# iscsiadm -m node
Accessing ssh servers behind NAT
Tue, 10/09/2012 - 10:29 — sandipCreate 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
Wed, 10/03/2012 - 15:51 — sandip# 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
Thu, 08/30/2012 - 17:00 — sandipmd5 digest:
echo -n 'md5 digest of text' | openssl dgst -md5
841fc570f41fad1a64cc237b1612 7225
sha1 digest:
echo -n 'sha1 digest of text' | openssl dgst -sha1
80efdb4abbeb92c0ea15a4146d68 c39adff5ad47
base64 encoding decoding with openssl
Thu, 08/30/2012 - 16:28 — sandipBase64 encoding with openssl:
echo -n 'encode this with base64' | openssl enc -base64
ZW5jb2RlIHRoaXMgd2l0aCBiYXNl NjQ=
Base64 decoding with openssl:
echo 'ZW5jb2RlIHRoaXMgd2l0aCBi YXNlNjQ=' | openssl enc -base64 -d
encode this with base64
Handling filenames with spaces, carriage returns or other control characters
Mon, 08/27/2012 - 23:42 — sandipfind -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
Mon, 08/27/2012 - 21:01 — sandipGet 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
Fri, 06/22/2012 - 08:04 — sandipThis 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
Thu, 06/07/2012 - 10:20 — sandipIf 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
Tue, 05/15/2012 - 15:22 — sandipOne 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