Saturday, June 26, 2010

How I deal with log files on my SSD Web Server

My backup web server has a 8GB CF card. I want to reduce the number of writes to it as much as possible to save money and keep my server healthy. I added the following to my /etc/rc.local so that the logs files are created in RAM every time the server boots.

How it works:

1. Create the ram disk directory.
2. Mount the ram file system.
3. Erase old logs.
4. Use touch to create an empty log file in the ram disk directory.
5. Link the log file in the ram disk directory to /var/log

[ /etc/rc.local ]
#Creates a tmpfs RAM disk and mount it
mkdir /ramfs;mount -t tmpfs /dev/ram0 /ramfs;mkdir /ramfs/httpd
LOG[0]=messages
LOG[1]=secure
LOG[2]=maillog
LOG[3]=yum.log
LOG[4]=rpmpkgs
LOG[5]=dmesg
LOG[6]=boot.log
LOG[7]=spooler
LOG[8]=scrollkeeper.log
LOG[9]=cron
LOG[10]=Xorg.0.log
LOG[11]=acpid
LOG[12]=btmp
LOG[13]=wtmp

LOG[14]=httpd/access_log

LOG[15]=httpd/error_log

for ((c=0;c<=15;c++))
do
rm -f /var/log/${LOG[c]};touch /ramfs/${LOG[c]};ln -s /ramfs/${LOG[c]} /var/log/${LOG[c]}
done

No comments:

Post a Comment