Search This Blog

Tuesday, December 28, 2010

Linux Shell Command to Findout PV's from Apache Access Log

cat /var/log/httpd/access.log | cut -d'"' -f2 | cut -d' ' -f2 | cut -d'.' -f2 | cut -d'?' -f1 | cut -d'/' -f1 | grep -v -P "gif|jpg|ico|png" | wc -l

Friday, December 10, 2010

How to add additional ip into linux - ubuntu

modify /etc/network/interfaces

add the following


auto eth0:0
iface eth0:0 inet static
address xx.xx.xx.xx
gateway xx.xx.xx.xx
netmask xx.xx.xx.xx
network xx.xx.xx.xx
broadcast xx.xx.xx.xx

example,
auto eth0:0
iface eth0:0 inet static
address 192.168.0.100
gateway 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

AND, finally restart networking service

/etc/init.d/networking restart

Wednesday, December 8, 2010

Tuesday, December 7, 2010

Example of singleton class in PHP

<?
class singleton
{
    private static $_instance;

    public static function getInstance()
    {
        if (!(self::$_instance instanceof self))
        {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    // Do not allow an explicit call of the constructor: $v = new Singleton();
    final private function __construct() { }

    // Do not allow the clone operation: $x = clone $v;
    final private function __clone() { }
}

$instance = singleton::getInstance();
?>

Setting up an email notification for subversion repository

Add the following piece of code in the /.../<<svnroot>>/<<repository_name>>/hooks/post-commit


#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r "$REV" -C -d -H Alternative \
 --alt HTML::ColorDiff -p "$REPOS" -t "xxxx@xxxx.com" \
 --from 'SVN @ xxxx.com <svn@xxxx.com>'

if svnnotify command is not present on your svn server then use following code in the post-commit file

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/bin/svnlook diff -r "$REV" "$REPOS" | mutt -s "SVN Notify" xxxx@xxxx.com

Thursday, December 2, 2010

Mysql Replication - From one database on master to another database on slave

Mysql Replication - From one database on master to another database on slave


Tells the slave to translate the default database (that is, the one selected by USE) to to_name if it wasfrom_name on the master. Only statements involving tables are affected (not statements such as CREATE DATABASEDROP DATABASE, and ALTER DATABASE), and only if from_name is the default database on the master. This does not work for cross-database updates. To specify multiple rewrites, use this option multiple times. The server uses the first one with a from_name value that matches. The database name translation is done before the --replicate-* rules are tested.
If you use this option on the command line and the “>” character is special to your command interpreter, quote the option value. For example:
shell> mysqld --replicate-rewrite-db="olddb->newdb"

TO READ THE ORIGINAL ARTICLE AT dev.mysql.com, Click Here

Table Cache - Mysql Server - Performance Tunning

One of the many important parameter is table cache

__ Tables ______________________________________________________________
Open              533 of 2048    %Cache:  26.03
Opened          2.18k     0.0/s

(1) If the %Cache is inching towards 100% mark then it is good time to increase table cache value in my.cnf

table_cache = 2048

(2) Rate of opening table is another way to judge if the value of table cache needs any change. Rate of 1/s or Lower is a GOOD indicator. Anything above means - table cache needs to be increased.

Wednesday, December 1, 2010

shell script to send email alert - if mysql replication is down

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

mysql_hostname="-h localhost"
mysql_username="-u root"
mysql_userpass="" #-p pass
email_to="xxxx@xxxx.com"
email_subject="Replication is Down"
tmp_replication_slave_reason_filepath="/tmp/replication_slave_reason.txt"

if [ -f $tmp_replication_slave_reason_filepath ]; then
        rm -rf $tmp_replication_slave_reason_filepath
fi

echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_IO_Running: No"
if [ "$?" -ne "1" ]; then
        echo "Slave_IO_Running: No" >> $tmp_replication_slave_reason_filepath
fi

echo "show slave status\G;" |mysql $mysql_username $mysql_hostname $mysql_userpass 2>&1 |grep "Slave_SQL_Running: No"
if [ "$?" -ne "1" ]; then
        echo "Slave_SQL_Running: No" >> $tmp_replication_slave_reason_filepath
fi

if [ -f $tmp_replication_slave_reason_filepath ]; then
        mail -s $email_subject $email_to < $tmp_replication_slave_reason_filepath
        echo $tmp_replication_slave_reason_filepath
fi

Wednesday, November 24, 2010

Command to monitor mysql replication slave status

watch 'mysql -u xxxx -p xxxx -e "show slave status\G" | grep "Last_"'

Mysql processlist monitoring

To check running queries

watch 'mysqladmin -u xxxx -p xxxx processlist | grep -v Locked | grep -v Sleep | grep -v Waiting'

To check Locked queries + count for each query

watch 'mysqladmin -u xxxx -p xxxx processlist | grep Locked | cut -d"|" -f9 | sort | uniq -c'

Change next AUTO_INCREMENT value in mysql table

The command to change next AUTO_INCREMENT value in mysql table is

ALTER TABLE <<TABLE_NAME>> AUTO_INCREMENT = '0000';

Common myisamchk options

myisamchk -mfq xxxx.MYI


  -m, --medium-check  Faster than extend-check, but only finds 99.99% of
                      all errors.  Should be good enough for most cases.

  -f, --force         Restart with '-r' if there are any errors in the table.
                      States will be updated as with '--update-state'.

  -q, --quick         Faster repair by not modifying the data file.
                      One can give a second '-q' to force myisamchk to
                      modify the original datafile in case of duplicate keys.
                      NOTE: Tables where the data file is currupted can't be
                      fixed with this option.

Getting the data Sync'ed between master & slave servers in mysql replication

In order to get the database.tables sync'ed between master and slave server, follow these guidelines

  1. Shutdown mysql daemon on master server
  2. Shutdown mysql daemon on slave server
  3. Take dump of database.tables on master server
  4. Take backup of database.tables on slave server
  5. Load dump (of master) on slave
  6. Start mysql daemon on master server
  7. Take a note of new binlog filename on master server
  8. Update the master binlog filename on slave server
  9. Start mysql daemon on slave server

Find broken symlinks in linux

In order to find broken links in linux, we will use find command with some shell scripting

for i in `find ./ -type l`; do [ -e $i ] || echo $i; done