The personal website of Philip Mather

how-to

Parasitic IP

ip addr del www.xxx.yyy.zzz dev eth0
ip addr add www.xxx.yyy.zzz dev eth0

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=www.xxx.yyy.zzz
NETMASK=255.255.255.0
ONBOOT=no

Install & Use SQLPlus

Download oracle-instantclient-basic-10.2.0.4-1.i386.rpm and oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm to the /tmp/ directory of the server...

rpm -ivh /tmp/oracle-instantclient-*
vi /tmp/tnsnames.ora
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.4/client/lib/:${LD_LIBRARY_PATH}
export TNS_ADMIN=/path/to/tnsnames.ora/nofile/
sqlplus system/oracle@targetfromora

OracleXE will need the following export first...

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/sqlplus

Hot P2V

Linux

http://conshell.net/wiki/index.php/Linux_P2V
http://www.debianhelp.org/node/11558
mkinitrd
grub-install

1) Recover the content of the disks to a staging post, on the staging machine execute...

# nc -l 80 | dd of=clone.hda.gz

...this will then sit awaiting data to arrive on port 80, this assumes that nothing else like a web server is already using port 80 and then your using the root account to allow netcat to bind to a system port.

2) Pipe the data off of the machine being cloned, you'll want to do this for each device (i.e. hdb or sda etc)...

# dd if=/dev/hda | gzip -c  | nc 192.168.96.104 80

Grow multipath LVM FS

Off-line

I took this guide and boiled it down a bit...

1. Check what's mounted on the the VG/LV that you want to resize...

[root]# mount
[...snip...]
/dev/mapper/vg_data-lv_orahome on /u01 type ext3 (rw)
/dev/mapper/vg_data-lv_oraredo1 on /u02 type ext3 (rw)
/dev/mapper/vg_data-lv_oraredo2 on /u03 type ext3 (rw)
/dev/mapper/vg_data-lv_oradata on /u04 type ext3 (rw)

[root]# cat /etc/fstab                                 
[...snip...]
/dev/vg_data/lv_orahome    /u01                    ext3    defaults        0 0
/dev/vg_data/lv_oraredo1   /u02                    ext3    defaults        0 0
/dev/vg_data/lv_oraredo2   /u03                    ext3    defaults        0 0
/dev/vg_data/lv_oradata    /u04                    ext3    defaults        0 0

[root]# /usr/sbin/vgdisplay vg_data
  --- Volume group ---
  VG Name               vg_data
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  15
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               100.00 GB
  PE Size               4.00 MB
  Total PE              51199
  Alloc PE / Size       51199 / 200.00 GB
  Free  PE / Size       0 / 0
  VG UUID               R0vsEk-6E72-wmOQ-0VAz-TflV-2W4v-T7B5yj

[root@]# /usr/sbin/lvdisplay vg_data                    
  --- Logical volume ---                                            
  LV Name                /dev/vg_data/lv_orahome                    
  VG Name                vg_data                                    
  LV UUID                7e36Fr-AiUK-UacN-ag5F-seEj-QDQh-J8rnxJ     
  LV Write Access        read/write                                 
  LV Status              available                                  
  # open                 1                                          
  LV Size                10.00 GB                                   
  Current LE             2560                                       
  Segments               1                                          
  Allocation             inherit                                    
  Read ahead sectors     auto                                       
  - currently set to     256                                        
  Block device           253:8                                      
                                                                    
  --- Logical volume ---                                            
  LV Name                /dev/vg_data/lv_oraredo1                   
  VG Name                vg_data                                    
  LV UUID                GHGtKL-fSMA-KSbe-rmr3-UYOT-6N7d-6nyJwd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.00 GB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:9

  --- Logical volume ---
  LV Name                /dev/vg_data/lv_oraredo2
  VG Name                vg_data
  LV UUID                es1Nco-AT44-Yrte-2r59-wQIB-xn3A-oNsNF0
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.00 GB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:10

  --- Logical volume ---
  LV Name                /dev/vg_data/lv_oradata
  VG Name                vg_data
  LV UUID                de60o2-FP0e-2H3d-6uAu-eGE7-ZPAP-lHAn0s
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                80.00 GB
  Current LE             46079
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:11

[root]# umount /u01
[root]# umount /u02
[root]# umount /u03
[root]# umount /u04

2. Deactivate the volume group...

[root]# /usr/sbin/vgchange -an vg_data
  0 logical volume(s) in volume group "vg_data" now active

3. Work out on what physical device the actual PV relates to...

[root]# /usr/sbin/pvdisplay
  --- Physical volume ---
  PV Name               /dev/dm-7
  VG Name               vg_data
  PV Size               100.00 GB / not usable 3.81 MB
  Allocatable           yes (but full)
  PE Size (KByte)       4096
  Total PE              51199
  Free PE               0
  Allocated PE          51199
  PV UUID               fXYKfP-BlU7-NZ3Y-Silt-6wZr-uDNp-n8FcSh

  --- Physical volume ---
  PV Name               /dev/dm-3
  VG Name               vg_root
  PV Size               9.99 GB / not usable 20.89 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              319
  Free PE               0
  Allocated PE          319
  PV UUID               Asi9qk-0VCR-W01d-7lhG-mDr9-YBl1-dP5d68

4. ...and tell the multipath driver to rescan it, if you havn't deactivated the VG it'll hang the machine...

[root]# /sbin/multipath -ll
mpath1 (36005076308ffc0bd0000000000001102) dm-7 IBM,2107900
[size=200G][features=1 queue_if_no_path][hwhandler=0][rw]  
\_ round-robin 0 [prio=2][active]                          
 \_ 1:0:0:1 sdd 8:48  [active][ready]                      
 \_ 0:0:0:1 sdb 8:16  [active][ready]                      
mpath0 (36005076308ffc0bd0000000000001100) dm-0 IBM,2107900
[size=16G][features=1 queue_if_no_path][hwhandler=0][rw]   
\_ round-robin 0 [prio=2][active]                          
 \_ 0:0:0:0 sda 8:0   [active][ready]                      
 \_ 1:0:0:0 sdc 8:32  [active][ready]  

[root]#  for i in `/sbin/multipath -ll mpath1 | grep sd | awk '{print $3}'`; do /sbin/blockdev --rereadpt /dev/$i ; done
1:0:0:1
0:0:0:1

[root]#  dmesg

5. Instruct multipath to expand the device...

[root]#   /sbin/multipathd -k"resize multipath mpath1"
ok

6. Resize the Physical Volume...

[root]#  /usr/sbin/pvresize /dev/mapper/mpath1
  Physical volume "/dev/mpath/mpath1" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

7. Extend the Logical Volume and reactivate the VG...

[root]#  /usr/sbin/lvextend  -L +100G /dev/mapper/vg_data-lv_oradata
  Extending logical volume vg_data-lv_oradata to 180.00 GB
  Logical volume vg_data-lv_oradata successfully resized

[root]#  /usr/sbin/vgchange -ay vg_data

8. Fsck (no harm unless it's huge) and then resize the file system...

[root]#  /sbin/e2fsck -f /dev/vg_data/lv_oradata

[root]#  /sbin/resize2fs /dev/mapper/vg_data-lv_oradata

9. Remount everything...

[root]# umount /u01
[root]# umount /u02
[root]# umount /u03
[root]# umount /u04

On-line

Technically this is unsupported on Linux because the multipath drivers can't handle the resizing however there is a guide here but I'm not sure I'd try it on a production system.

Passwordless SSH

OpenSSH instructions
These steps were used on an OpenSSH client and server.

First, generate your OpenSSH protocol 2 rsa key (you may use -t dsa if you want to use dsa keys):
ssh-keygen -t rsa

You will be prompted for a passphrase for your private key. Although you are not required to passphrase-protect your private key, it is considered good practice to do so. Your passphrase should ideally consist of a difficult-to-guess phrase or sentence containing several symbols and/or numbers.

Append the contents of your public key to the authorized_keys file on the remote OpenSSH server:
cat ~/.ssh/id_rsa.pub | ssh remote_server "mkdir -p ~/.ssh && cat - >> ~/.ssh/authorized_keys"

If you are using the X Window System, start X with the following command:
ssh-agent startx

From a terminal or from your desktop environment (ex. GNOME, KDE), run the following command to prompt for your private key passphrase:
ssh-add

All terminals and subprocesses spawned within X will remember your private key passphrase.

Enable Serial Access

Add...

"
# Local serial lines
s0:12345:respawn:/sbin/agetty -L ttyS0 9600 vt100
"

...to /etc/inittab and add...

"
ttyS0
"

...to /etc/securetty... and then execute

$ telinit q

Rate of Change

Script to monitor the rate of change of something...

#!/bin/bash 
 
LastOutput=0
 
# Used to keep averages
NumberOfDeltas=0
RunningAverage=0
 
dT=60
 
echo "------------------------------------------------------------------------------"
echo "MM/DD/YY HH:MM:SS AM: VALUE DELTA/${dT}s AVE. DELTA/${dT}s"
echo "------------------------------------------------------------------------------"
 
while true
do
   Output=`netstat -st | grep -E "(TCP timeouts)" | tr -d [:alpha:] | tr -d : | tr -d " "`
 
   if [ "$LastOutput" != "0" ]
   then
      Delta=`expr $Output - $LastOutput`
 
      # Notice that we don't count first entry. This is the number of deltas
      NumberOfDeltas=`expr $NumberOfDeltas + 1`
 
      # Calculate the average change. Unfortunately, significant
      # round-off errors due to no decimal point support in expr
      EntriesMinusThisCount=`expr $NumberOfDeltas - 1`
      Product=`expr $EntriesMinusThisCount \* $RunningAverage + $Delta`
      RunningAverage=`expr $Product / $NumberOfDeltas`
 
      echo "$(date +"%D %r"): $Output $Delta $RunningAverage"
   else
      echo "$(date +"%D %r"): $Output - -"
   fi
 
   # Set the last output to current for next iteration
   LastOutput=$Output
 
   # Sleep for minute
   sleep $dT 
done

Backup multiple F5s

Needs refining, should also add the license files to the tar archive and not use the "ls -t ¦ head -n 1" bodge...

for h in 192.168.1.1 192.168.1.2 \
            192.168.2.3 192.168.2.4; do ssh -o ConnectTimeout=5 ${h} "cd /var/local/ucs/; b config save `date +%Y.%m.%d-%H.%M.%S.%N`.${h}; ls -t | head -n 1 | xargs cat" > `date +%Y.%m.%d-%H.%M.%S.%N`.${h}.ucs ; done; tar -czvf F5.configs.`date +%Y.%m.%d-%H.%M.%S.%N`.tar.gz `date +%Y.%m.%d-%H`*

Extract an RPM

Extract the directory hierarchy of the RPM to the current directory...

rpm2cpio modutils-2.4.22-8.i386.rpm | cpio -idv

Bond Network Interfaces

Links

Process

Add for Centos...

alias bond0 bonding
install bonding0 /sbin/modprobe bonding -o bond0 miimon=100 mode=1 primary=eth0
alias bond1 bonding
install bonding1 /sbin/modprobe bonding -o bond1 miimon=100 mode=1 primary=eth2

...or for slackware...

alias bond0 bonding
options bond0 miimon=100 mode=1 primary=eth0
alias bond1 bonding
options bond1 miimon=100 mode=1 primary=eth1

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.###.0
NETMASK=255.255.255.0
IPADDR=192.168.###.###
GATEWAY=192.168.###.1
USERCTL=no
TYPE=Ethernet

ifcfg-bond1

DEVICE=bond1
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.###.0
NETMASK=255.255.255.0
IPADDR=192.168.###.###
USERCTL=no

ifcfg-eth{0-3}

DEVICE=eth{0-3}
BOOTPROTO=none
HWADDR=##:##:##:##:##:##
ONBOOT=yes
MASTER=bond{0/1}
SLAVE=yes
USERCTL=no
TYPE=Ethernet
ETHTOOL_OPTS="autoneg off speed 100 duplex full"