Friday, September 28, 2012

Cassandra Useful nodetool commands

nodetool info              -Displays node-level info.
nodetool ring              -Displays info on nodes on the ring.
nodetool cfstats          -Displays Column Family statistics.
nodetool tpstats          -Displays what operations Cassandra is doing right now.
nodetool netstats        -Displays streaming information.
nodetooldrain             -Flushes Memtables to SSTables on disk and stops accepting writes.
                                     Useful before a restart to make startup quicker(no Commit Log to replay)

Monday, September 24, 2012

MySQL Replicaiton Slave Monitor Script

MySQL Replicaiton Slave Monitor Script


Slave_IO_Running=`mysql  -u root -pB0Mb@cu7$ -e "show slave status\G" | grep Slave_IO_Running | awk '{ print $2 }'`
Slave_SQL_Running=`mysql  -u root -pB0Mb@cu7$ -e "show slave status\G" | grep Slave_SQL_Running | awk '{ print $2 }'`

if [ $Slave_IO_Running == 'Yes' ] && [ $Slave_SQL_Running == 'Yes' ] ; then
        echo "Replication slave is running"
else
   echo "Replication slave is down"
fi

Friday, September 14, 2012

FreeSWITCH Installation

FreeSWITCH Installation 
#############################################
#        FreeSWITCH Installation            #
#############################################

# Install GIT and dependencies
cd /usr/src
yum -y install gcc-c++ gettext-devel expat-devel curl-devel zlib-devel openssl-devel bzip2
yum -y install autoconf automake libtool gcc-c++ ncurses-devel make expat-devel zlib zlib-devel libjpeg-devel
# GIT Install
wget http://git-core.googlecode.com/files/git-1.7.9.5.tar.gz && tar xzvf git-1.7.9.5.tar.gz && cd git-1.7.9.5 && make prefix=/usr/local all && make prefix=/usr/local install
cd ..

# Download Git trunk
git clone git://git.freeswitch.org/freeswitch.git freeswitch-git
cd freeswitch-git
./bootstrap.sh
vim modules.conf // enable xml_curl and disable uncessary modules
./configure
make
make install
make sounds-install
make moh-install
make samples
vim /usr/local/freeswitch/conf/autoload_configs/modules.conf //again enable/disable necessary modules
cd /usr/local/freeswitch/bin/
./freeswitch -nonat

## iSWITCH performance & Optimization ##
mv db/ db_old
mkdir db
mount -t tmpfs tmpfs /usr/local/freeswitch/db
df -h
# to remove ramdisk
umount -lt tmpfs /usr/local/freeswitch/db

#increase ulimits
ulimit -c unlimited;
ulimit -d unlimited;
ulimit -f unlimited;
ulimit -i unlimited;
ulimit -n 999999;
ulimit -q unlimited;
ulimit -u unlimited;
ulimit -v unlimited;
ulimit -x unlimited;
ulimit -s 244;
ulimit -l unlimited;
ulimit -a;

# Freeswitch troubleshooting
#to stop freeswitch
... (three dots on freeswitch console)
#to start freeswitch
cd /usr/local/freeswitch/bin
./freeswitch -nonat

Friday, September 7, 2012

Critical variables of MySQL that you should monitor

Variable Purpose Why you should monitor it
Threads_connected This variable indicates the total number of clients that have currently open connections to the server. It provides real-time information on how many clients are currently connected to the server. This can help in traffic analysis or in deciding the best time for a server re-start.
Created_tmp_disk_tables This variable indicates the number of temporary tables that have been created on disk instead of in-memory. Accessing tables on disk is typically slower than accessing the same tables in memory. So queries that use the CREATE TEMPORARY TABLE syntax are likely to be slow when this value is high.
Handler_read_first This variable indicates the number of times a table handler made a request to read the first row of a table index. If MySQL is frequently accessing the first row of a table index, it suggests that it is performing a sequential scan of the entire index. This indicates that the corresponding table is not properly indexed.
Innodb_buffer_pool_wait_free This variable indicates the number of times MySQL has to wait for memory pages to be flushed. If this variable is high, it suggests that MySQL's memory buffer is incorrectly configured for the amount of writes the server is currently performing.
Key_reads This variable indicates the number of filesystem accesses MySQL performed to fetch database indexes. Performing filesystem reads for database indexes slows query performance. If this variable is high, it indicates that MySQL's key cache is overloaded and should be reconfigured.
Max_used_connections This variable indicates the maximum number of connections MySQL has had open at the same time since the server was last restarted. This value provides a benchmark to help you decide the maximum number of connections your server should support. It can also help in traffic analysis.
Open_tables This variable indicates the number of tables that are currently open. This value is best analyzed in combination with the size of the table cache. If this value is low and the table_cache value is high, it's probably safe to reduce the cache size without affecting performance. On the other hand, if this value is high and close to the table_cache value, there is benefit in increasing the size of the table cache.
Select_full_join This variable indicates the number of full joins MySQL has performed to satisfy client queries. A high value indicates that MySQL is being forced to perform full table joins (which are performance-intensive) instead of using indexes. This suggests a need for greater indexing of the corresponding tables.
Slow_queries This variable indicates the number of queries that have taken longer than usual to execute. A high value indicates that many queries are not being optimally executed. A necessary next step would be to examine the slow query log and identify these slow queries for optimization.
Uptime This variable indicates the number of seconds since the server was last restarted. This value is useful to analyze server uptime, as well as to generate reports on overall system performance. A consistent low value indicates that the server is being frequently restarted, thereby causing frequent interruptions to client service.

Wednesday, September 5, 2012

Script to find PID from a port number - Solaris specific

bash-2.05# cat find_PID_from_port
#!/bin/ksh
#*********************************************************************************************************#
# Purpose is to find the PID on which given port is active.
# Need to be root to check other folk's PID's out
#
# Note: This script gives the PID and process details which is using the port number given in argument
# ./find_PID_from_port 80
#*********************************************************************************************************#

line='-------------------------------------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')

# Prompt users or use 1st cmdline argument
if [ $# -eq 0 ]; then
        read ans?"Enter port you like to know pid for:  "
else
        ans=$1
fi

# Check all pids for this port, then list that process
for f in $pids
do
        /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
        if [ $? -eq 0 ] ; then
                echo $line
                echo "Port: $ans is being used by PID:\c"
                /usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
        fi
done
exit 0

shell script to find linux memory process usage

shell script to find linux memory process usage

Hi,
The following script will check for top 20 processes which uses maximum memory resource in the server and will store it in “overusage” file only if the free memory goes below 700MB. Set cron to execute this script whenever needed.
 
#!/bin/bash
#High RAM usage checker
r=`free -m |awk 'NR==2' |awk '{ print$4 }'`
if [ $r -lt 700 ];
then
ps -e -orss=,args= | sort -b -k1,1n |tail -n 20 >> overusage
exit
fi

how to configure mysql master slave replication


how to configure mysql master slave replication 

Here  is a basic step by step tutorial, that will cover the mysql master and slave replication and also will describe the mysql master and master replication.
 Step 1:

Install mysql on master 1 and slave 1. configure network services on both system, like

Master  ip: 192.168.16.4
Slave  ip : 192.168.16.5

Step 2:

On Master 1, make changes in my.cnf:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1

log-bin
binlog-do-db=<database name>  # input the database which should be replicated
binlog-ignore-db=mysql            # input the database that should be ignored for replication
binlog-ignore-db=test

server-id=1

[mysql.server]
user=mysql
basedir=/var/lib


[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Step 3:

On master 1, create a replication slave account in mysql.
mysql> grant replication slave on *.* to 'replication'@192.168.16.5 \
identified by 'slave';
and restart the mysql master1.

Step 4:

Now edit my.cnf on Slave1 or Master2 :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1

server-id=2

master-host = 192.168.16.4
master-user = replication
master-password = slave
master-port = 3306

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Step 5:

Restart mysql slave 1 and at
mysql> start slave;
mysql> show slave status\G;

Step 6:

On master 1:
mysql> show master status;

how to for mysql master master replication

Here  is a basic step by step tutorial, that will cover the mysql master and slave replication and also will describe the mysql master and master replication.
Notions: we will call system 1 as master1 and slave2 and system2 as master2 and slave 1
 Step 1:

Install mysql on master 1 and slave 1. configure network services on both system, like

Master 1/Slave 2 ip: 192.168.16.4
Master 2/Slave 1 ip : 192.168.16.5

Step 2:

On Master 1, make changes in my.cnf:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1

log-bin
binlog-do-db=<database name>  # input the database which should be replicated
binlog-ignore-db=mysql            # input the database that should be ignored for replication
binlog-ignore-db=test

server-id=1

[mysql.server]
user=mysql
basedir=/var/lib


[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


Step 3:

On master 1, create a replication slave account in mysql.
mysql> grant replication slave on *.* to 'replication'@192.168.16.5 \
identified by 'slave';
and restart the mysql master1.

Step 4:

Now edit my.cnf on Slave1 or Master2 :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
old_passwords=1

server-id=2

# for auto increment fields
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2

 
master-host = 192.168.16.4
master-user = replication
master-password = slave
master-port = 3306

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid



Step 5:

Restart mysql slave 1 and at
mysql> start slave;
mysql> show slave status\G;

Step 6:

On master 1:
mysql> show master status;

Note:The above scenario is for master-slave, now we will create a slave master scenario for the same systems and it will work as master master. 

Step 7:

On Master2/Slave 1, edit my.cnf and master entries into it:
 [mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
server-id=2

master-host = 192.168.16.4
master-user = replication
master-password = slave
master-port = 3306

log-bin                     #information for becoming master added
binlog-do-db=adam

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


Step 8:

Create a replication slave account on master2 for master1:
mysql> grant replication slave on *.* to 'replication'@192.168.16.4 identified by 'slave2';

Step 9:

Edit my.cnf on master1 for information of its master.
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1


log-bin
binlog-do-db=adam
binlog-ignore-db=mysql
binlog-ignore-db=test

server-id=1

replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1


#information for becoming slave.
master-host = 192.168.16.5
master-user = replication
master-password = slave2
master-port = 3306

[mysql.server]user=mysqlbasedir=/var/lib 

Step 10:

Restart both mysql master1 and master2.
On mysql master1:
mysql> start slave;
On mysql master2:
mysql > show master status;
On mysql master 1:
mysql> show slave status\G;



 

Monday, September 3, 2012

how to change timezone in centos

To change Timezone on centos 5 you need to follow the below mention Setup

1.yum install system-config-date
2. execute setup command on linux cli then see below figure



 3.Then you need to select 'Timezone Configuration' and press Enter Key and then you will get below figure.
4.From here select your require timezone and press Enter key.

how we can import freeswitch cdr from master.cv to mysql using linux shell script

#!/bin/bash
host='192.168.1.105'
user='dbuser'
password='dbpassword'
DB='livecalls'
cat /usr/local/freeswitch/log/cdr-csv/Master.csv >> /usr/local/freeswitch/log/cdr-csv/Full_CDR_Log.csv
mastercsvfile='/usr/local/freeswitch/log/cdr-csv/Master.csv'
if [[ -s $mastercsvfile ]] ; then
    /usr/local/bin/fs_cli -x 'cdr_csv rotate'
else
echo "$FILE is empty."
fi ;
NOW=$(date +"%Y-%m-%d-%H-%M")
file=$(ls  /usr/local/freeswitch/log/cdr-csv |grep Master.csv.$NOW)
#echo $file
FILE=/usr/local/freeswitch/log/cdr-csv/$file
if [[ -s $FILE ]] ; then
mysql -h $host -u$user -p$password  $DB < /usr/local/freeswitch/log/cdr-csv/$file
rm -rf  /usr/local/freeswitch/log/cdr-csv/$file
else
echo "$FILE is empty."
rm -rf  /usr/local/freeswitch/log/cdr-csv/$file
fi ;
Note:
Make a file with .sh extension and add is file in crontab for auto execution.

how we can check file is empty in linux shell script

#! /bin/ksh
FILE='/etc/passwd'
if [[ -s $FILE ]] ; then
echo "$FILE has data."
else
echo "$FILE is empty."
fi ;