Useful Tips about Linux , Apache , Mysql , Tomcat , PHP and lot more..
Thursday, October 27, 2011
Linux command to get hardware and system information
#!/bin/bash
#########################################################################
# #
# Get System Information #
# By Suvabrata Mukherjee #
#Linux command to get hardware info
#########################################################################
echo "System Report" > report.txt
echo "##########################################################################" >> report.txt
echo "HostName" >> report.txt
hostname >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "OS Version" >> report.txt
cat /etc/issue.net >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Total Memory in GB" >> report.txt
echo `free -g | head -n 2 | tail -n 1 | awk '{print $2}'` >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Total number of processors" >> report.txt
echo `cat /proc/cpuinfo | grep processor | wc -l` >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Processor Make " >> report.txt
echo `cat /proc/cpuinfo | grep 'model name' | head -1` >> report.txt
#Linux command to get hardware info
echo "----------------------------------------------------------" >> report.txt
echo "HardDisk Details :" >> report.txt
echo "Number of Harddisk" >> report.txt
echo `/sbin/fdisk -l | grep Disk | wc -l` >> report.txt
echo `/sbin/fdisk -l | grep Disk` >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Ip Addresses:" >> report.txt
echo `/sbin/ifconfig | grep 'inet addr' | awk '{print $2}'| cut -c6-25` >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Number of Ethernet Cards" >> report.txt
echo `/sbin/lspci | grep -i ethernet | wc -l` >> report.txt
echo "----------------------------------------------------------" >> report.txt
echo "Server Model and Serial" >> report.txt
echo `/usr/sbin/dmidecode -t system | grep Manufacturer` >> report.txt
echo `/usr/sbin/dmidecode -t system | grep 'Product Name'` >> report.txt
echo ` /usr/sbin/dmidecode -t system | grep 'Serial Number'` >> report.txt
echo "----------------------------------------------------------" >> report.txt
#Linux command to get hardware information
echo "Total DIMM Module available" >> report.txt
echo ` /usr/sbin/dmidecode -t 17 | grep 'Size' | wc -l` >> report.txt
echo "Total DIMM Module free" >> report.txt
echo ` /usr/sbin/dmidecode -t 17 | grep 'Size: No Module Installed' | wc -l` >> report.txt
echo "----------------------------------------------------------" >> report.txt
cat report.txt
# End of Linux command to get hardware information
Thursday, January 28, 2010
vicidial campaign set caller id
find your outbound dialing pattern and route
for example
##################### USA Calling ###########################
exten => _1XXXXXXXXXX,1,AGI(AGI(agi://127.0.0.1:4577/call_log)
exten => _1XXXXXXXXXX,2,Set(CALLERID(all)=122222222XX <122222222XX>)
exten => _1XXXXXXXXXX,4,Dial(sip/${EXTEN}@sip-provider,30,WtTo)
exten => _1XXXXXXXXXX,5,Hangup
####################################
Wednesday, January 27, 2010
Monitoring MySql replication
This script should have both master and slave server authentication details
#!/usr/bin/perl -w
use Mysql;
$ENV{MYSQL_UNIX_PORT} = "/tmp/mysql.sock";
# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "DB-NAME";
$user = "DB-USER";
$pw = "DB-PASS";
$host_master = "192.168.75.70";
$database_master = "DB-NAME";
$user_master = "Monitor";
$pw_master = "DB-PASS";
# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);
# DEFINE A MySQL QUERY
$myquery = "show slave status";
# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);
## Tag : Monitoring MySql replication
# FETCHROW ARRAY
@results = $execute->fetchrow();
if ( $results[11] eq "No" || $results[10] eq "No" )
{
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: Monitor
To: Administrator
Cc: Administrator
Subject: DB-NAME DB Replication failed on slave
DB-NAME DB Replication failed
Error No -- $results[18]
Error Details --
Error -- $results[19]
EOF
close(SENDMAIL) or warn "sendmail didn't close nicely";
}
else
{
print "Db replication is good";
}
$connect2 = Mysql->connect($host_master, $database_master, $user_master, $pw_master);
$myquery2 = "show master status";
## Tag : Monitoring MySql replication
# EXECUTE THE QUERY FUNCTION
$execute2 = $connect2->query($myquery2);
# FETCHROW ARRAY
@results2 = $execute2->fetchrow();
if ( $results2[0] eq $results[5] )
{
print "DB in sync";
## Tag : Monitoring MySql replication
}
else
{
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
or die "Can't fork for sendmail: $!\n";
print SENDMAIL <<"EOF";
From: Monitor
To: Administrator
Cc: Administrator
Subject: DB-NAME DB Replication not in Sync
DB-NAME DB Replication is not in Sync
Master Log File is $results2[0]
where in slave log file is $results[5]
EOF
close(SENDMAIL) or warn "sendmail didn't close nicely";
}
## Tag : Monitoring MySql replication
Friday, June 5, 2009
Creating a self signed certificate for apache - A very quick HowTo
Thursday, June 4, 2009
Rsync backup - a quick HowTo
Password Less SSH -- quick HowTo
Wednesday, June 3, 2009
Nagios Temperature Monitoring
NFS Cluster setup - a Quick HowTo
Thursday, May 28, 2009
linux network configuration - A Quick Howto
/sbin/ifconfig eth0 192.168.75.50 netmask 255.255.255.0 broadcast 192.168.75.255
For debian Just edit /etc/network/interfaces and put like-------------------------# The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet static address 192.168.75.50 netmask 255.255.255.0 network 192.168.75.0 broadcast 192.168.75.255
How to copy a disk - Linux
Tuesday, December 9, 2008
Quick Setup SVN with Apache2 on Linux
Step 1. Install Apache2 , if not already installed. (apache2,SVN,Linux)
Step 2. Install libapache2-svn, subversion ,subversion-tools(apache2,SVN,Linux)
If you are using debian try "apt-get install libapache2-svn subversion subversion-tools" or in Redhat/Fedora
try "yum install install libapache2-svn subversion subversion-tools".(apache2,SVN,Linux)
Step 3. Create SVN Repo Directory(apache2,SVN,Linux)
as root user(apache2,SVN,Linux)
mkdir /src (apache2,SVN,Linux)
chown -R ApacheUser /src (apache2,SVN,Linux)
svnadmin create /src/trunk (apache2,SVN,Linux)
Step 3. Now create apache config , put this config (apache2,SVN,Linux)
Under Location directive: (apache2,SVN,Linux)
DAV svn (apache2,SVN,Linux)
SVNPath /src/trunk (apache2,SVN,Linux)
AuthType Basic (apache2,SVN,Linux)
AuthName "SVN Authentication" (apache2,SVN,Linux)
AuthUserFile /etc/apache2/.svn.passwd (apache2,SVN,Linux)
Require valid-user (apache2,SVN,Linux)
Restart apache (apache2,SVN,Linux)
Step 4. Create SVN user (apache2,SVN,Linux)
htpasswd -c -m /etc/apache2/.svn.passwd user
You can add more user later
Step 5. Test you installation (apache2,SVN,Linux)
Open in your browser
http://yourservername/src/trunk
Step 6. If all set then import your files to this SVN Repo (apache2,SVN,Linux)
svn --username user import
Apache rewrite with cookie value set
This will redirect any specific request and sets client cookie with defined values. (Apache rewrite with cookie)
For Example:
RewriteRule ^/abc/ff/(.+) http://www.somedomain.com/abc.php?code=$1 (Apache rewrite with cookie) [CO=DemoCookie:$1:.somedomain.com:100:/]
This will redirect
http://www.somedomain.com/abc/ff/123
to
http://www.somedomain.com/abc.php?code=123
and set cookie at client browser with name DemoCookie , value 123, domain somedomain.com and time set 100. (Apache rewrite with cookie)
Wednesday, December 3, 2008
New features in MySql 5.1
Some important items are given below :
1. Table partitioning and sub-portioning as well .
2. FAST execution for ALTER TABLE .
3. Task Scheduler - CREATE EVENT Statement to add task , a good use for DB maintenance activities
Apache Modsecurity with GeoIP blocking country specific traffic
ModSecurity is a web application firewall that can work either embedded or as a reverse proxy.
It provides protection from a range of attacks against web applications and allows for HTTP
traffic monitoring, logging and real-time analysis.
Requirements:[
To install modsecurity with geop support we need following packages [
1.ModSecurity v2.5 or greater ( Download from http://www.modsecurity.org/)[
2.mod_geoip2 ( Download from http://www.maxmind.com/)[
3.GeoIP-1.4 or greater ( Download from http://www.maxmind.com/) [
Additionaly we need apxs to compile apache modules.
Apache unique_id_module and libxml2 must be installed in the system.
Download GeoLiteCity.dat database file from http://www.maxmind.com/ and place it in
/usr/share/
After installing all these packages, include four files under tour apache configuration directory and include them under main config file (httpd.conf)
1. mod-security.load
LoadFile /usr/local/lib/libxml2.X[[BR]]
LoadModule security2_module /usr/local/lib/apache2/mod_security2.so[[BR]][[BR]]
2. mod_sec.conf[
SecRuleEngine On[
Include /
3. mod_geoip.load[
LoadModule geoip_module /
4. mod_geoip.conf
GeoIPEnable On
GeoIPDBFile /usr//share/GeoLiteCity.dat
Now for modsecurity configuration files visit http://www.gotroot.com/ [[BR]]
A complete set of configuration files can be downloaded from http://downloads.prometheus-group.com/delayed/rules/modsec-2.5-free-latest.tar.gz
Extract all files and move them to /
level and available system resource. Including all rule files may slowdown the apache server
Create a file name geo_ip_rules.conf under /
and put for example
SecGeoLookupDb /usr/share/GeoLiteCity.dat
SecRule REMOTE_ADDR "@geoLookup" "chain,drop,msg:'COUNTRY IP address'
SecRule GEO:COUNTRY_CODE "@streq
This configuration will block all ipaddress from mentioned country.
As per requirement we can change this country code.
After all these installation and configuration we need to restart the apache server to take effect.
We can monitor the apache error.log for mod geoip ip address blocking.
Apache DOS Attack
Mod-Evasive is the most common solution to this problem , but it seems for user feedback that it does not work properly or very difficult to configure as per your server need.
Another very helpful solution is (D)Dos-Deflate script which is really effective .
A lot of people are using it to prevent their sites from DOS attacks .
http://deflate.medialayer.com/
Quick InnoDB Tuning Guide
In brief there are some major tuning directives , which can improve InnoDB performance.
1. innodb_log_flush_at_trx_commit - If you set it to 0 , InnoDB does not flush each commit to Disk rather it would flush after ter one second , If you are running non financial site and can afford to loss 1-2 seconds data loss incase of failure , this trick will work good
2. innodb_flush_method -- the default method work well for innodb
3. Check if the version of mysql is tested against your operating system.
Also you need to set
innodb_buffer_pool_size
innodb_additional_mem_pool_size
innodb_thread_concurrency
innodb_log_file_size
innodb_log_buffer_size
innodb_flush_log_at_trx_commit
innodb_file_per_table
options as per your database server hardware environment and need to tune it perfectly for optimize innodb performance.
Please don't tests these options on your production environment , unless you are 100% sure about your changes and after effects
Quick Setup -- NRPE for NAGIOS in debian
Please change this script as per your environment .
This script is for debian users only , Others can use it after some modification.
(Setup NRPE NAGIOS)
########################################
# NRPE INSTALLATION (Setup NRPE NAGIOS ) (Setup NRPE NAGIOS)
########################################
useradd nagios
groupadd nagios
apt-get -y install xinetd make openssl libssl-dev g++ gcc
wget http://osdn.dl.sourceforge.net/sourcefo ... 4.6.tar.gz
tar xzf nagios-plugins-1.4.6.tar.gz
cd nagios-plugins-1.4.6
./configure
make
make install
chown -R nagios.nagios /usr/local/nagios/
cd ..
wget http://osdn.dl.sourceforge.net/sourcefo ... 2.8.tar.gz
tar xzf nrpe-2.8.tar.gz
cd nrpe-2.8
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
`sed -i 's/127.0.0.1/
cd ..
########################
## edit your nrpe.cfg file if required
chown -R nagios.nagios /usr/local/nagios/
echo "nrpe 5666/tcp #nrpe" >> /etc/services
/etc/init.d/xinetd restart
A very quick howto about Linux LVM
Secondly you need to install LVM package in your system.
Assuming here
1. /dev/sda10 - disk partition
2. Disk space is 200G
3. mount point is /home
Now follow the commands
pvcreate /dev/sda10
pvscan
vgscan
Create a volume group
vgcreate -s 16M vol_grp_1 /dev/sda10
vgdisplay
lvcreate -l 200G -n lv_1 vol_grp_1
lvdisplay
mke2fs -j /dev/vol_grp_1/lv_1
mount /dev/vol_grp_1/lv_1 /home
add to /etc/fstab
/dev/vol_grp_1/lv_1 /home ext3 defaults 0 2
Quick Setup APF firewall
** You need to have iptables installed in your server **
wget http://www.r-fx.ca/downloads/apf-current.tar.gz
tar zxf apf-current.tar.gz
cd apf-x
./install.sh
edit /etc/apf/conf.apf
IFACE_IN="xxx"
IFACE_OUT="xxx" -- replace xxx with internet exposed interface
IFACE_TRUSTED="yyy" -- -- replace xxx with internal network where firewall not applicable ( if available ) .
change
# Common inbound (ingress) TCP ports
IG_TCP_CPORTS="22,80,4443" --- mention the ports that you want to keep open in external interface .
A lot of other directives are there to manipulate your config .
Only basic configs are mentioned here .
then start apf " apf -s" andf test your firewall
If all set just set DEVEL_MODE="0" in conf.apf then
stop apf " apf -f"
and start "apf -s"