Central Log Server with Rsyslog and Php Log Con with TLS/SSL with TCP Rsyslog V 5 supports TLS / SSL for sending and receiving logs. Download the source from here :http://www.rsyslog.com/rsyslog-5-8-4-v5-stable/ Steps : Do this on both client and server 1. cd /usr/src 2. wget http://www.rsyslog.com/rsyslog-5-8-4-v5-stable/ 3. tar -zxvf rsyslog-5-8-4-v5-stable 4. cd rsyslog-5-8-4 5. yum install
Add new mysql slave to an existing replication A new slave can be added to an existing replication without stopping the master. Setup the new slave by making a copy of existing slave. Dont forget to change the server-id value . To copy an existing slave : 1. Stop the slave : >mysqladmin shutdown 2. Copy the data directory from
Replicating An Existing Database MySQL The following steps are to be followed to setup replication of an existing MySQL Database : 1. Login To the Existing mysql database and issue the following command : > reset master; > FLUSH TABLES WITH READ LOCK; > Master Show Status; Note the Binary Log Position and the Binary Log name
MySQL Replication Switch Master/Slave It is good idea to turn of MySQL server at start. So that if the master goes down it does not start by itself when it comes back up. Follow these steps on the slave : Note: The Slave also has to be setup with binary logging enabled. In order to
apache init script > !/bin/sh # # Startup script for the Apache Web Server # # chkconfig: 345 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # pidfile: /var/run/httpd.pid # config: /etc/httpd/conf/httpd.conf # Source function library. . /etc/rc.d/
Compiling an additional module for apache apxs -i -a -c modules/filters/mod_deflate.c http://httpd.apache.org/docs/current/dso.html
Uninstall Perl Module The following script can help uninstall perl module > !/usr/bin/perl -w use ExtUtils::Packlist; use ExtUtils::Installed; $ARGV[0] or die “Usage: $0 Module::Name\n”; my $module = $ARGV[0]; my $inst = ExtUtils::Installed->new(); foreach my $item (sort($inst->files($module))) { print “Removing $item\n”
Yum Tips and Tricks To view what packages are installed from which repo : rpm -qa --qf '%{NAME} %{VENDOR}\n' Display RPM Architecture Just one line in ~/.rpmmacros will save all sorts of trouble later. echo "%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}" >> ~/.rpmmacros
View Last failed login attempts This command will show you the list of last failed login attempts : last -f /var/log/btmp This file can get huge, so you might want to rotate this file : > /var/log/btmp { monthly minsize 1M create 0600 root utmp rotate 1 } You can put this in logrotate.conf
Tutorial on logrotate Force Log Rotation : logrotate /etc/logrotate.d/file_to_be_rotated or `logrotate -v -f /etc/logrotate.d/firewall (v = verbose, f = force even if not required) ``` In order to rotate a log file you can add an entry to #/etc/logrotate.conf or you can create a custom separate
Email Piping with Postfix Create an alias email from postfixadmin and set go to to be pipe_handler@hostname eg. set support@xyz.com to go to supporthandler@hostname.com Edit aliases file : vi /etc/postfix/aliases Add the following line at the end: supporthandler: “| php -q /path/to/handler.php” save the file
Set server logs to be sent to an email address You can have your server log files sent to an email address. Edit the logwatch configuration file : vi /etc/logwatch/conf/logwatch.conf ( if this file is empty , edit the following file) vi /usr/share/logwatch/default.conf/logwatch.conf find mailto and put the email address there. Or you
Shell script to delete files and folders older than x days This script finds, logs and deletes files and folders older than x days. #/bin/bash DIRS="/dir1/,/path/to/dir2/,/dir3/" LOG_FILE="path to log file" TIMESTAMP=date +%Y:%m:%d DAYS_OLD="10" # This will find and delete folders and files older
Test Hard Drive Health Status (SMART) The health of hard drive can be checked in linux using the command : smartctl -H /dev/sda
Force Unmount busy drive Try the following command to forcefully unmount a busy or non existing mounted drive or partition. umount -l /mnt/path or if this doesnot work, issue: fuser -km /cdrom
Strange characters in pstree export LANG=’EN us’ Use pstree -A instead of pstree -p, the result would be like this:
Putty Tips and Tricks Export Putty Sessions : 1. Run > regedit /ea putty.reg HKEY_CURREN_USER\Software\SimonTatham\PuTTY 2. Copy putty.reg on to the new computer 3. On the new computer, open up a command prompt : > regedit /s putty.reg Delete All Putty sessions : c:>putty -cleanup >
Add Delete ip address to interface /sbin/ip address add IP_ADDR/32 dev /sbin/ip address del IP_ADDR/32 dev
Email Notification on Login On Linux Machines It’s a good idea to set email notification on login on your servers. You can set it by adding a script to your /etc/profile file. vi /etc/profile At the bottom add /path/to/your/script Now put the script in that path : > !/bin/bash #Author : Amit
Asterisk Tips To fix the jabber load issue : > echo “/usr/local/lib” > /etc/ld.so.conf.d/iksemel.conf This fixes the path issue
Repair broken MySQL Replication There are times, when replication stop working between mysql servers because of the invalid queries. First of all find out whether mysql replication is running and if not what caused it to stop. Usually the logs are located at /var/log/mysql In order to make sure.. log in to