Thursday, November 18, 2010

CentOS / Redhat: Create Software RAID 1 Array

Recently, I've added another 73GB SAS disk to my Linux server after the installation. I've 30GB empty partition on old hard disk. How do I convert old /dev/sda3 and new /dev/sdb1 (both 30GB) into RAID 1 to improve NFS server speed and reliability?

RAID devices are virtual devices created from two or more real block devices. Linux supports RAID1 and other levels. You need to have same size partition on both disks i.e. on second disk create partitions exactly the same size as those on the first disk, and set the type as fd (Linux raid autodetect). You need to use the following commands to create RAID 1.

Find Command Exclude Directories From Search Pattern

How do I exclude certain directories while using the find command under UNIX or Linux operating systems?

You can use the find command as follows to find all directories except tmp directory:
find /path/to/dest -type d \( ! -name tmp \) -print
Find all directories except tmp and cache:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache \) -print
The -prune option make sure that you do not descend into directory:
find /path/to/dest -type d \( ! -name tmp \) -o \( ! -name cache -prune \) -print
You can find all *.pl find except in tmp and root directory, enter:
find /  \( ! -name tmp \) -o \( ! -name root -prune \)  -name "*.pl" -print


Monday, November 8, 2010

Postfix masquerading or changing outgoing SMTP email or mail address

Address rewriting allows changing outgoing email ID or domain name itself. This is good for hiding internal user names. For example:
SMTP user: tom-01
EMAIL ID: tom@domain.com
Server name: server01.hosting.com


However when tom-01 send an email from shell prompt or using php it looks like it was send from tom-01@server01.hosting.com
In some cases internal hosts have no valid Internet domain name, and instead use a name such as localdomain.local or something else. This can be a problem when you want to send mail over the Internet, because many mail servers reject mail addresses with invalid domain names to avoid spam.
Postfix MTA offers smtp_generic_maps parameter. You can specify lookup tables that replace local mail addresses by valid Internet addresses when mail leaves the machine via SMTP.


Open your main.cf file
# vi /etc/postfix/main.cf
Append following parameter
smtp_generic_maps = hash:/etc/postfix/generic
Save and close the file. Open /etc/postfix/generic file:
# vi /etc/postfix/generic
Make sure tom-01@server01.hosting.com change to tom@domain.com
tom-01@server01.hosting.com tom@domain.com
Save and close the file. Create or update generic postfix table:
# postmap /etc/postfix/generic
Restart postfix:
# /etc/init.d/postfix restart
When mail is sent to a remote host via SMTP this replaces tom-01@server01.hosting.com by tom@domain.com mail address.

You can use this trick to replace address with your ISP address if you are connected via local SMTP.