Thursday, November 18, 2010

Apache daily Logrotate in linux

Apache log rotation : access_logs etc...etc...

In Linux kernel, program daemons, firewalls, etc, generate their respective log files and they are everywhere. In fact, there are so many log files of various levels that sometimes, it can be a nightmare to maintain them.

Log files are one of the most important files where almost all precious and sometimes unnecessary information are stored in regard to your server’s running state.

tail -f /var/log/messages ” is the command if you want to get feel and see the actual current logs generated by various daemons running on your system.

Now if your server also has a Apache Web server running and you want to manage their respective logs in your own fashion, then the following information might help you out.

How to see them

tail -f /var/log/httpd/access_log

First of all, you will need the program called “logrotate”. Logrotate is very useful utility which can rotate log files and archive them in a location that you specify. We will be using “logrotate” in conjunction with “cron“.

By Default the logrotate.conf file have weekly rotation of logs and logs are kept for 4 weeks.

cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files daily
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}


if you want to change them then you have to change the
weekly ---->daily
rotation
4---->2
like below.....

cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files daily
daily

# keep 4 weeks worth of backlogs
rotate 2

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}

# system-specific logs may be also be configured here.


or you can use command to do the same

perl -pi -e 's/weekly/daily/' /etc/logrotate.conf
perl -pi -e 's/rotate 4/rotate 2/' /etc/logrotate.conf

To cross check
logrotate -dv /etc/logrotate.d/httpd

Thursday, November 11, 2010

USB drive format by linux machine

check you drive in /var/log/messeges for the device.

#mkfs.vfat /dev/sdxx

now mount it

#mount -t vfat /dev/sdxx /media/usbdir

#umount /media/usbdir

How to check files in linux without comments

grep -v '#' /etc/httpd/conf/httpd.conf > /tmp/httpd.conf

Backup of Important Files in linux

Vi MyBackupFiles.txt

/etc/passwd
/etc/users
/etc/groups
/home/userName

save and exit by :wq

now

# tar -zcf backup-`date +%Y-%m-%d`.tar.gz -T /MyBackupFiles.txt

Mail Send by command line

# Mail -s “Hello world” abc@xyz.com

#echo | mutt -a mybackup.tar -s “daily backup” abc@mydomain.com

#printf “Hello\nWorld” | mail abc@xyz.com

#printf “This is the main body of the mail\n with line break” | mail -s “Subject of the Email” to@abc.com -f from@abc.com

# echo “Welcome to Jungle ” | mail -s “Hello world” abc@xyz.com -c pqr@xyz.com -b ghi@xyz.com

#( df -h; free -m ) | mail -s "disk and RAM report" abc@xyz.com

Wednesday, November 10, 2010

Adding second harddisk to ESXi

Under "Configuration > Storage"
Click "Add Storage..."
Choose the new disk, and go.

or

If you are in a non-production environment you just :
- down the server
- put into the server the new disk
- start the server and make attention to controller BIOS utility to create LUN
- create the new LUN using the new disk
- start and connect with VI client to ESX
- follow the procedure described bottom to discover and format the new disk as VMFS