Tipsheet

Tips and tricks...

Creating LVM partitions.

After creating a new partition (/dev/hda5) with fdisk run the below commands:

# partprobe
# pvcreate /dev/hda5
# vgcreate vg0 /dev/hda5
# lvcreate -L 1G -n lv0 vg0
# mke2fs -j /dev/vg0/lv0

Extending LVM

Extend partition by 1Gb.

# lvresize -L +1G /dev/vg00/lvol0
# e2fsck -f /dev/vg00/lvol0
# resize2fs -pf /dev/vg00/lvol0


Notes:

  • resize2fs has replaced ext2online in FC6.
  • need to unmount volume prior to doing resize2fs.

Restoring corrupt rpm database

If you have a corrupt rpm database, simply delete the db files and rebuild it again.

# rm -rf /var/lib/rpm/*db.*
# rpm --rebuilddb

Serving files from a folder outside the web root with mod_rewrite

I was serving static content within a drupal installation, which became a huge nightmare when doing upgrades. So, I decided, I should just create a symbolic link to a folder outside the installation and route the traffic via mod_rewrite rules.

I first created a folder called "/var/www/site_files" and then symlinked to it from "/var/www/html/site_files". This way, I just have to recreate one single symbolic link after doing the upgrades.

With the below rules, I was able to maintain the links to the existing pages.

  ## BEGIN: site_files ##
  # Redirect to the homepage if site_files is being called
  RewriteRule ^site_files/?$ http://%{HTTP_HOST}/ [L,R=301]
  # Apped / at the end of url, if directory is being called without /
  RewriteCond %{REQUEST_URI} !^/?$
  RewriteCond %{DOCUMENT_ROOT}/site_files%{REQUEST_URI} -d
  RewriteRule ^(.+[^/])$ /$1/ [R=301,L]
  # Get directory or file if exists in site_files directory
  RewriteCond %{REQUEST_URI} !^/$
  RewriteCond %{DOCUMENT_ROOT}/site_files%{REQUEST_URI} -d [OR]
  RewriteCond %{DOCUMENT_ROOT}/site_files%{REQUEST_URI} -f
  RewriteRule ^(.*)$ site_files/$1 [L]
  ## END: site_files ##

New Server CentOS 4.4 at LT Grid with ISPConfig Installed

These are notes, I had taken down while setting up ISPConfig Hosting Control Panel on LayeredTechs Grid. Most of the steps were referenced via howtoforge and ispconfig installation notes. There were some gotchas to look out for and has bee noted below:

Search Engine Friendly Redirects

301 redirect is the most efficient and Search Engine friendly method for webpage redirection. If you have to change file names or move pages around, it's the safest option and preserves your search engine rankings. The code "301" is interpreted as "moved permanently".

With php:

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://host.domain.tld" );
?>

With mod_rewrite:

RewriteEngine on

#Redirect Old domain to New domain
RewriteRule (.*) http://host.domain.tld/$1 [R=301,L]

# Redirect a particular domain
RewriteCond %{http_host} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ http://host.newdomain.tld/$1 [R=301,L]

# Redirect a particular file
RewriteRule ^old_file.html$ http://host.domain.tld/new_file.html [R=301,L]

Block IP addresses from accessing your site via .htaccess

There are couple ways to block an IP, the one general way is to use htaccess deny feature.

SetEnvIf REMOTE_ADDR "^xxx.xxx.xxx.xxx$" badip
SetEnvIf REMOTE_ADDR "^xxx.xxx.xxx.xxx$" badip

<Limit GET POST>
order deny,allow
deny from env=badip
</Limit>

Extract individual files from an RPM

To extract an individual file from an rpm package without installing the rpm:

  1. Use rpm2cpio or rpm -qpl to list files and full paths in the package:
    $ rpm2cpio <package_name> | cpio -t

  2. Use rpm2cpio to extract a file. Run this command from /tmp or elsewhere in order to avoid overwriting any current system files.
    This creates the full path in the current directory and extracts the file specified.
    $ rpm2cpio <package_name> | cpio -iv --make-directories <full-file-path>

  3. To extract everything to the current directory:
    $ rpm2cpio <package_name> | cpio -ivd

extracting initrd.img file on Fedora Core 6

initrd in Fedora Core 6 is a gzipped cpio archive which can be extracted using:

$ cd /tmp
$ gunzip < /boot/initrd.img |cpio -i --make-directories

Firefox2.0 Tips...

This is going to consist of tips on Firefox2.0 usage. If you have any good tips please leave it in the comments.

Hide Go Button

Type in "about:config" in the address bar, then do a search for "hideGoButton" and toggle the value to "true".

Comment