Author: Ravi Bhure

Installing PDO_OCI extension for php5

Installing PDO_OCI extension for php5

To enable pdo_oci module you may need to install oracle client and oci8 module is require. I have installed oracle 10g client here.

[root@ravi.com ~]# export ORACLE_HOME=/usr/lib/oracle/10.2.0.3/client64/ ; export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client64/
[root@ravi.com ~]# cd /tmp
[root@ravi.com tmp]# pecl download pdo_oci
[root@ravi.com tmp]# tar xvzf PDO_OCI-1.0.tar.gz
[root@ravi.com tmp]# cd PDO_OCI-1.0 && phpize
[root@ravi.com tmp]# ./configure
[root@ravi.com PDO_OCI-1.0]# make
/bin/sh /tmp/PDO_OCI-1.0/libtool –mode=compile gcc -I/usr/include/php/ext -I. -I/tmp/PDO_OCI-1.0 -DPHP_ATOM_INC -I/tmp/PDO_OCI-1.0/include -I/tmp/PDO_OCI-1.0/main -I/tmp/PDO_OCI-1.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext  -DHAVE_CONFIG_H  -g -O2   -c /tmp/PDO_OCI-1.0/pdo_oci.c -o pdo_oci.lo
mkdir .libs
gcc -I/usr/include/php/ext -I. -I/tmp/PDO_OCI-1.0 -DPHP_ATOM_INC -I/tmp/PDO_OCI-1.0/include -I/tmp/PDO_OCI-1.0/main -I/tmp/PDO_OCI-1.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -DHAVE_CONFIG_H -g -O2 -c /tmp/PDO_OCI-1.0/pdo_oci.c  -fPIC -DPIC -o .libs/pdo_oci.o
In file included from /tmp/PDO_OCI-1.0/pdo_oci.c:31:
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:21:17: error: oci.h: No such file or directory
In file included from /tmp/PDO_OCI-1.0/pdo_oci.c:31:
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:26: error: expected specifier-qualifier-list before ‘sb4’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:32: error: expected specifier-qualifier-list before ‘OCIServer’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:48: error: expected specifier-qualifier-list before ‘OCIDefine’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:62: error: expected specifier-qualifier-list before ‘OCIStmt’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:73: error: expected specifier-qualifier-list before ‘OCIBind’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:85: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PDO_OCI_INIT_MODE’
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:87: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/tmp/PDO_OCI-1.0/php_pdo_oci_int.h:89: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_oci_error’
/tmp/PDO_OCI-1.0/pdo_oci.c:71: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PDO_OCI_INIT_MODE’
/tmp/PDO_OCI-1.0/pdo_oci.c:87: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/tmp/PDO_OCI-1.0/pdo_oci.c: In function ‘zm_startup_pdo_oci’:
/tmp/PDO_OCI-1.0/pdo_oci.c:96: error: ‘pdo_oci_Env’ undeclared (first use in this function)
/tmp/PDO_OCI-1.0/pdo_oci.c:96: error: (Each undeclared identifier is reported only once
/tmp/PDO_OCI-1.0/pdo_oci.c:96: error: for each function it appears in.)
/tmp/PDO_OCI-1.0/pdo_oci.c:96: error: ‘PDO_OCI_INIT_MODE’ undeclared (first use in this function)
/tmp/PDO_OCI-1.0/pdo_oci.c: In function ‘zm_shutdown_pdo_oci’:
/tmp/PDO_OCI-1.0/pdo_oci.c:111: error: ‘dvoid’ undeclared (first use in this function)
/tmp/PDO_OCI-1.0/pdo_oci.c:111: error: expected expression before ‘)’ token
make: *** [pdo_oci.lo] Error 1

Is this the error that pdo does not connect to oci library and its find these into include subfolder, so you may need to copy all the files into include folder.

[root@ravi.com PDO_OCI-1.0]# cp -f /usr/include/oracle/10.2.0.3/client64/* /tmp/PDO_OCI-1.0/include/

Now run make & make install to compile and install the module.

[root@ravi.com PDO_OCI-1.0]# make && make install

enable the pdo_oci extension with php.

[root@ravi.com PDO_OCI-1.0]# echo “extension=pdo_oci.so” > /etc/php.d/pdo_oci.ini

[root@ravi.com PDO_OCI-1.0]# php -m | grep pdo_oci

To work pdo_oci properly you have to restart apache.

Thanks

Ravi

How to install & configure VNC server on CentOS

How to install & configure VNC server on CentOS

How to install VNCSERVER on CentOS

yum groupinstall “GNOME Desktop Environment”
yum install xterm vnc-server vnc

remove the existing file & edit with ‘/etc/sysconfig/vncservers‘ and put the following lines in it

VNCSERVERS=”2:root”
VNCSERVERARGS[2]=”-geometry 800×600 -nolisten tcp -nohttpd -localhost”

set the vnc password to open the vnc for user root (you have to login as a root)
vncpasswd

set the vnc password to open the vnc for user (you have to login as a normal user that way it will create the file xstartup in $home/.vnc)
vncpasswd

Now start the vncserver as root user
/etc/init.d/vncserver start

Now kill the vncserver proocesses using ‘ps aux | grep vnc | xargs kill -9’

and start vnc server by following command
vncserver

check the given path to open the vnc display as given in example
New ‘appserver.ravi.com:3 (root)’ desktop is appserver.ravi.com:3

before open the vncviewer remove the file ‘/tmp/.X1-lock’

Now open the vnc display you will get the default ‘xterm’ open on it.

How to install GeoIP and mod_geoip2 on centos for apache

How to install GeoIP and mod_geoip2 on centos for apache

How to install GeoIP and mod_geoip2 on centos for apache

1) yum install GeoIP GeoIP-devel GeoIP-data zlib-devel

2) mkdir /usr/local/share/GeoIP

3) Download the latest Country and City database files from maxmind

cd /usr/local/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz

4) yum install httpd-devel apr-devel

5) wget http://geolite.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2_1.2.5.tar.gz

6) tar xvzf mod_geoip2_1.2.5.tar.gz && cd mod_geoip2_1.2.5

7) apxs -i -a -L/usr/lib64 -I/usr/include -lGeoIP -c mod_geoip.c

8) Enabling mod-geoip
Nothing’s going to work unless mod-geoip is enabled in your apache configuration. You’ll need the following lines in your httpd.conf file (located on CentOS systems at /etc/httpd/conf/httpd.conf)

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat Standard
GeoIPDBFile /usr/local/share/GeoIP/GeoLiteCity.dat Standard
</IfModule>

9) Restart Apache so your changes will take effect by entering the following command.

#/etc/init.d/httpd restart

10) /usr/local/bin/geoipupdate

How to build RPM of PHP for apache with mpm-worker

How to build RPM of PHP for apache with mpm-worker

In my last post, we have seen how we build rpm package for apache with default mpm-worker now it this tutorial we will see how we build rpm of php that can work with apache with mpm-worker.

Download php source rpm from mirror.centos.org

http://mirror.centos.org/centos-5/5.2/os/SRPMS/php-5.1.6-20.el5.src.rpm

To resolve the dependancies to build RPM package for PHP installing the require some lib packages

[root@testbed2:/tmp]# yum install bzip2-devel curl-devel gmp-devel aspell-devel libjpeg-devel libpng-devel pam-devel openssl-devel sqlite-devel pcre-devel krb5-devel libc-client-devel mysql-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel ncurses-devel gd-devel freetype-devel

install source rpm using
[root@testbed2:/tmp]# rpm -i php-5.1.6-20.el5.src.rpm

[root@testbed2:/tmp]# cd /usr/src/redhat/SPECS

vi php.spec and find “%configure” (without quote) where you can put the “–enable-maintainer-zts \” (without quote)

then rebuild rpm using below command

[root@testbed2:/usr/src/redhat/SPECS]# rpmbuild -bb php.spec

after creating rpm you will find all rpm in /usr/src/redhat/RPMS/{your arch folder} folder
in my condition the rpm’s in /usr/src/redhat/RPMS/x86_64

now change the httpd mpm to worker

[root@testbed2:/usr/src/redhat/X86_64]# /etc/init.d/httpd stop

edit file /etc/sysconfig/httpd

just uncomment the HTTPD=/usr/sbin/httpd.worker line

save and exit then start the httpd service

Now install php rpms from /usr/src/redhat/RPMS/{your arch folder}

[root@testbed2:/tmp]# /etc/init.d/httpd start
[root@testbed2:/tmp]# httpd -V
[root@testbed2:/tmp]# php -v

This is the way that I have done this. I know people are many way and good idea’s to do this.

So keep commenting that update that the things.

How to build rpm for http with mpm worker (on x86_64)

How to build rpm for http with mpm worker (on x86_64)

Guy’s since I started working on apache, I found that apache is most use ful web technology over network.
Everyone knows that (multi-processing module) MPM Prefork is default included in apache rather than MPM Worker.

MPM Prefork = This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
MPM Worker = This Multi-Processing Module (MPM) implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server. However, it retains much of the stability of a process-based server by keeping multiple processes available, each with many threads.

More information is available on apache.org manuals

http://vr-zone.com/manual/en/mod/prefork.html
http://vr-zone.com/manual/en/mod/worker.html

On RPM based OS’s, apache is default with MPM-Prefork so we will build apache RPM (with default MPM-worker) for our own, don’t know this will be useful or now but will have know everyone with this 🙂

Download the source rpm packages from http://mirror.centos.org

[root@testbed2:/tmp]# wget http://mirror.centos.org/centos-5/5.3/os/SRPMS/httpd-2.2.3-22.el5.centos.src.rpm

install http source rpm

[root@testbed2:/tmp]# rpm -ivh httpd-2.2.3-22.el5.centos.src.rpm

[root@testbed2:/tmp]# cd /usr/src/redhat/SPECS

edit httpd.spec with vi editor

[root@testbed2:/usr/src/redhat/SPECS]# vi httpd.spec

find the –with-mpm and enter below config parameter under the –with-mpm

–enable-headers –enable-uniqueid \
–enable-deflate \
–enable-mime-magic \
–enable-so –enable-rewrite \
–enable-http \
–enable-log-config \
–with-libexpat=built-in \

Now find the “mpmbuild prefork”  and replace with “mpmbuild worker”

Now find the “mpmbuild worker” and replace with “mpmbuild prefork”
(you may find this, just few line below)

and most important thing is that you have to comment some lines i.e. (./prefork/httpd -l | grep -v prefork > prefork.mods to done)

find and comment from “./prefork/httpd -l | grep -v prefork > prefork.mods” to “Done” (i.e. just total 8 lines)

Now time to build http with mpmworker for that some dependancies are comes that we will resolve using yum

yum install xmlto db4-devel expat-devel libselinux-devel  apr-devel apr-util-devel pcre-devel openssl-devel distcache-devel

[root@testbed2:/usr/src/redhat/SPECS]# rpmbuild -bb httpd.spec

you have wait for few min and watch whats going on screen ……

your rpm build is created and placed into /usr/src/redhat/RPMS/x86_64

Now install the packages and check with ‘httpd -V’

N’joy

HAProxy Load Balancer

HAProxy Load Balancer

IT infra going day to day very critical and costly, So for that we need simple IP based load balancing solution that handles ssl traffic. Basically it’s very easy and secure way to manage your server load balancing.
This example will shows you how we use this with easy steps

The Configuration =
* Load Balancer:  <10.0.0.77>  // will be our haproxy server # This will listen on many ports that we will bind as per requirement
* Web Server 1: <10.0.1.209>  // web application server 1    #This will listen on tcp mode
* Web Server 2: <10.0.1.210>  // web application server 2   #This will listen on tcp mode
* Web Server 3: <10.0.1.227>  // web application server 3   #This will listen on http mode
* Admin Panel Port 8088: <10.0.0.77>  // Statistics Panel on port 8080  #This will listen on http mode

Get and Install haproxy
We’ll be using the 1.3.17 src files to install haproxy. You can get them from http://haproxy.1wt.eu/

wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.19.tar.gz

tar xvzf haproxy-1.3.19.tar.gz

cd haproxy-1.3.19

make TARGET=linux26 ARCH=x86_64

make install

Now add user haproxy or what ever need to run config

[root@ravi.com ~]# useradd haproxy

cp /path/to/haproxy-1.3.19/examples/haproxy.init /etc/init.d/haproxy

chmod +x /etc/init.d/haproxy

create the /etc/haproxy folder and create haproxy.cfg config file in it.

mkdir /etc/haproxy

Now Please add your config file haproxy.cfg in /etc/haproxy

Configure /etc/haproxy/haproxy.cfg

#[root@app71 haproxy]# more haproxy.cfg
global
log 127.0.0.1   local0
log 127.0.0.1   local1 notice
#log loghost    local0 info
maxconn 25000    # count about 1 GB per 25000 connections
#debug
#quiet
user ravi
group ravi

defaults
log         global
mode        tcp
option      dontlognull
retries 3
option         redispatch
maxconn     20000
contimeout      5000
clitimeout      50000
srvtimeout      50000

#Configuration for www.ravi.com
listen VIP:www.ravi.com:10.0.0.77:80
bind            10.0.0.77:80    # or any other IP:port combination we listen to.
bind            10.0.0.77:443    # or any other IP:port combination we listen to.
mode            tcp
option          ssl-hello-chk
option          forwardfor    # set the client’s IP in X-Forwarded-For.
balance         roundrobin
# set the maxconn parameter below to match Apache’s MaxClients minus
# one or two connections so that you can still directly connect to it.
# you have to set server health check it it’s down it showing you on stat
# Set server weights normally it should be 1 for all
server          app139:10.0.1.209:80 10.0.1.209 weight 1 maxconn 5000 check
server          app140:10.0.1.210:80 10.0.1.210 weight 1 maxconn 5000 check

listen VIP:www.ravi.com:10.0.0.77:8080
bind            10.0.0.77:8080    # or any other IP:port combination we listen to.
mode            http
option          forwardfor    # set the client’s IP in X-Forwarded-For.
balance         roundrobin
# set the maxconn parameter below to match Apache’s MaxClients minus
# one or two connections so that you can still directly connect to it.
# you have to set server health check it it’s down it showing you on stat
# Set server weights normally it should be 1 for all
server          app127:10.0.1.227:8080 10.0.1.227 weight 1 maxconn 5000 check

# Enable the stats page on a dedicated port (8088). Monitoring request errors
# on the frontend will tell us how many potential attacks were blocked.
listen  ha_stats 10.0.0.77:8088
mode            http
stats enable
stats auth user:password ##Auth user pass

edit the /etc/sysctl.conf and add the end of file then run sysctl -p to load the setting

net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65023
net.ipv4.tcp_max_syn_backlog = 10240
net.ipv4.tcp_max_tw_buckets = 400000
net.core.somaxconn = 10000

start haproxy using (/etc/init.d/haproxy start or /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid)

Configuring logging

Edit /etc/sysconfig/syslog

1.SYSLOGD_OPTIONS=”-m 0 -r”

Edit /etc/syslog.conf. Add the following:

1.local0.* /var/log/haproxy/haproxy.log
2.local1.* /var/log/haproxy/haproxy-1.log

Restart Syslog

service syslog restart

Now check with

ps auxwww | grep haproxy

Thanks

Ravi

How to configure vpn client on Linux

How to configure vpn client on Linux

This has been tested under RHEL 4/5, CentOS 4.4/5 and fedora 8 (kernel version 2.6.15+)

I found and stored few required rpm packages from various places that you will download from given.

http://www.4shared.com/file/113579629/ee5e0aed/libglade-017-11i386.html
http://www.4shared.com/file/113579642/2fd674e3/libglade-devel-017-11i386.html
http://www.4shared.com/file/113579654/dfaee097/libxml-1817-8i386.html
http://www.4shared.com/file/113579677/7491d3af/libxml-devel-1817-8i386.html
http://www.4shared.com/file/113579714/ba004fa4/php4-pcntl-449-1fc5i386.html
http://www.4shared.com/file/113579747/5e7eea5b/php4-pcntl-gtk-102-4fc5i386.html
http://www.4shared.com/file/113579758/d7dac68b/pptp-172-3fc5i386.html
http://www.4shared.com/file/113579764/f541d963/pptpconfig-20060821-1fc5noarch.html

After downloading these first you will have to install lib packages and then pptp packages

rpm -ivh –nodeps libglade-0.17-11.i386.rpm libglade-devel-0.17-11.i386.rpm  libxml-1.8.17-8.i386.rpm libxml-devel-1.8.17-8.i386.rpm

rpm -ivh pptp-1.7.2-3.fc5.i386.rpm pptpconfig-20060821-1.fc5.noarch.rpm php4-pcntl-gtk-1.0.2-4.fc5.i386.rpm php4-pcntl-4.4.9-1.fc5.i386.rpm

now go to the given image that I would like to show how I added vpn connection

1) open vpnclient configuration launchpad with “pptpconfig”

2)  Now create your profile with all the details and add

Now you have to set you external route or tunnel IP range into it for that click on “Routing” and set  “All to Tunnel” and update your profile.

Now start your vpn client.

–Ravi

Automate script for hp_ltt with read option

Automate script for hp_ltt with read option

Hello Friends,

Many days back, I have configured this storageworks devices of HP and nowadays one of my friend is having like the same issue’s with the os’s to configuring HP storageworks, he has been doing manual driver scan with hp_ltt tool every time when system has been rebooted. Actually there some thing missing with os’s but still this scripts work for him now.

#!/usr/bin/expect  —
# This expect script is useful and working with driver Diagnostic automated tool
# I have tested this over “HP StorageWorks Library and Tape Tools”
# Please change the option number 10 for rescan as per mention in your hp_ltt script.
# Some older hp_ltt script it has option number 9, so please check once this option.
# If you have any queries about this script please send email on ravi <at> indiangnu <dot> org
set timeout -1
spawn ./hp_ltt
match_max 100000
send — “r”
# Look for prompt
expect “ommand>”
# Send option 1 for hardware scan
send — “1r”
send — “r”
# Look for  prompt
expect “ommand>”
# Send option 3 for continue
send — “3r”
send — “r”
# Look for prompt
expect “ommand>”
# send option 10 for rescan
send — “10r”
send — “r”
# Look for prompt
expect “ommand>”
# Send 1 (exit) from L & TT
send — “1r”
send — “r”
expect eof

Suggestion : You have to run this expect script under the $HOME folder of hp_ltt script.

–Ravi

Script for checking CPULOAD and send email to admin

Script for checking CPULOAD and send email to admin

This script is very useful for system admins, it checks Cpuload and get info of which process takes the cpuload, if cpuload is or above 70%  it sends alert email to admin

==============================

#!/bin/bash
# Shell script to monitor or watch the high cpu-load
# It will send an email to $ADMIN, if the (cpu load is in %) percentage
# of cpu-load is >= 70%
# If you have any suggestion or question please email to ravi<at>indiangnu <dot> org
# set admin email so that you can get email
# set alert level 70% is default
# you can set it to string LOAD with your value

AWK=/bin/awk
SAR=/usr/bin/sar
GREP=/bin/grep
TR=/usr/bin/tr
HEAD=/usr/bin/head
PS=/bin/ps
SORT=/bin/sort
HOSTNAME=indiangnu.org
SED=/bin/sed
LOAD=70
CAT=/bin/cat
MAILFILE=/tmp/mailviews$$
MAILER=/bin/mail
mailto=”ravi@indiangnu.org”
for path in $PATHS
do
CPU_LOAD=`$SAR -P ALL 1 2 | $GREP ‘Average.*all’ | $AWK -F” ” ‘{ print 100.0 -$NF}’`
echo $CPU_LOAD
if [[ $CPU_LOAD > $LOAD ]];
then
PROC=`$PS -eo pcpu,pid -o comm= | $SORT -k1 -n -r | $HEAD -1`
echo “Please check your processess on ${HOSTNAME} the value of cpu load is $CPU_LOAD % & $PROC” > $MAILFILE
$CAT $MAILFILE | $MAILER -s “CPU Load is $CPU_LOAD % on ${HOSTNAME}” $mailto
fi
done

=============================

After  end of  schedule cron job for this script like below

*/30 * * * * /bin/sh /root/cpuload.sh >/dev/null 2>&1

Thanks

Ravi