Thursday, May 12, 2011

Three Sysadmin Ultimate Rules

Rule 1: Backup Everything

 

Experienced sysadmin knows that production system will crash someday, no matter how proactive we are. The best way to be prepared for that situation is to have a valid backup.

 

Rule 2: Master the Command Line

 

There is not a single task on a Unix / Linux server, that you cannot perform from command line. While there are some user interface available to make some of the sysadmin task easy, you really don’t need them and should be using command line all the time.
So, if you are a Linux sysadmin, you should master the command line.
On any system, if you want to be very fluent and productive, you should master the command line. The main difference between a Windows sysadmin and Linux sysadmin is — GUI Vs Command line. Windows sysadmin are not very comfortable with command line. Linux sysadmin should be very comfortable with command line.


Rule 3: Automate Everything


Lazy sysadmin is the best sysadmin. (oh~ i love that sentence!).

There is not even a single sysadmin that I know of, who likes to break this rule. That might have something to do with the lazy part.
Take few minutes to think and list out all the routine tasks that you might do daily, weekly or monthly. Once you have that list, figure out how you can AUTOMATE THOSE. The best sysadmin typically doesn’t like to be busy. He would rather be relaxed and let the system do the job for him.  



Monday, May 9, 2011

Simple Script for Autorotate the mysqld-slow-query.log

This script is for Autorotate the mysqld-slow-query.log

#Start script
#!/bin/bash

SERVER=`hostname`

DATE=`date +%Y%m%d_%H%M`

logsize=`ls -l /mysql/mysqld-slow-query.log | awk -F" " '{print $5}'`
echo "LogSizeNow = $logsize";

limit=100000000
#Limit 100MB log file auto rotate

if [ $logsize -gt $limit ];

then


        echo "Rotating MYSQL Slow Queries";

        #Actions
        cp /mysql/mysqld-slow-query.log /home/mysql-slow-query/mysqld-slow-query.log-$DATE
        echo "" > /mysql/mysqld-slow-query.log
        bzip2 /home/mysql-slow-query/mysqld-slow-query.log*

        echo "Done Zipping mysql slow queries";

else

        echo "The Log file still not big enough";

fi



#End of Script

dont forget to "chmod +x <your_script.sh>" and put it in the Cron jobs :)
Cheers!!!

Author : IndraSusanto

Simple Automatic Swap Alert and Action

What is the Most Important for Our Server?
I think it is the Swap Memory Monitoring!
If all of the physical memory space used by programs, the Kernel begin to use Swap to allocate more memory.
If all of the swap already in use, the server (or computer) will hang and needs to reboot (Dangerous for productions Servers)
I share the most important part of my Simple script to prevent high swap memory usage.
I hope this helps!

Just put it in Crontab every 5 minutes to runs automatically in the background.
Cheers!!!

#Start Script
#!/bin/bash


SERVER=`hostname`


DATE=`date +%Y%m%d_%H%M`


swap=`free -m | awk -F" " '{print $3}' | tail -1`
echo "SWAP Used NOW = $swap";
limit=1000


if [ $swap -gt $limit ];


then


        #This is the Actions if Limit reached
        /etc/init.d/httpd reload;


        echo "$SERVER Swap Memory Warning!";


else


        echo "Swap still safe now.."


fi


#End of Script


Save the script anywhere in the Server, but don't forget to add "chmod +x <your_script>.sh"

Author : IndraSusanto