Keep local environment when logging to remote servers

March 15, 2006

Use the script movein.sh from O’Reilley.

#!/bin/sh

if [ -z "$1" ]; then
echo "Usage: `basename $0` hostname"
exit
fi

cd ~/.skel
tar zhcf - . | ssh $1 "tar zpvxf -"

Read link for more info...

Advertisements

Apache Tweaks

March 15, 2006

Avoid truncated filenames in log by editing httpd.conf:
IndexOptions FancyIndexing NameWidth=*

Here is a handy Perl script to compress all Apache logs automatically called LogFlume.

Serve an additional site under same DocumentRoot:

Add new Virtual Host:

ServerName http://www.newsite.biz
ServerAdmin mike@newsite.biz
DocumentRoot /home/www/htdocs #same as other site
RewriteEngine On
RewriteRule ^/$ /home/www/htdocs/newsite/index.html
RewriteRule ^/index.html$ /home/www/htdocs/newsite/index.html


Find open ports and associated processes

March 15, 2006

netstat -lnp (as root)

gives you PID for any port, then just type:
ps auwex |grep -w PID

Also, try lsof -p PID to get files and sockets.


Use rsync over ssh

March 15, 2006

Keep remote directories in sync is a good use for this. Below will synch remote host (source_host) directory with localhost /home/tom:
rsync -ave ssh [--delete] source_host:/home/mike/ /home/tom/

Use the –delete switch if you want to syncrhonize source deletes as well.


Backing up with tar over ssh

March 15, 2006

Copy directory structure (e.g. apache) from one server to another:

cd /usr/local
tar zcf – apache/ | ssh remote_host “cd /usr/local; mv apache apache.bak; tar zpxvf -“


Linux hard disk performance tuning

March 15, 2006

Check I/O speed with:
hdparm -tT /dev/hda

Check settings with:
hdparm /dev/hda

Turbo-performance like this (may cause system to hang!):
hdparm -c3 -m16 /dev/hda

Recheck performance to see difference.


Find the disk hog

March 15, 2006

You can put this code in your .profile as an alias or run on command line.

alias ducks='du -cks * | sort -rn | head -11'

Shows which users hog the most space in the directory you run this in, plus recurses downward. Ex: run in /home.