Archive for the “Articles” Category

DRBD – Heartbeat ( Active/Passive High Availability Cluster )

DRBD – Heartbeat  ( Active/Passive High Availability Cluster )
  • Overview
  • Software Requirements
  • Pre configuration
  • DRDB installation
  • Heartbeat Installation
  • Testing
  • Conclusion

Overview:

DRBD – Heartbeat cluster a good Active / Passive cluster solution for small scale applications using two servers in active and passive mode. This means , only one server will work at a time while keeping the other server as a backup  with realtime data updates.  DRBD is a kernel level service which will replicate your  block devices  ( HDD partition ) with the second server. So  all the data  that required for working your application must be need to  place in that hard disk partition. Also make sure that both of your servers need same amount of free space.

Heartbeat is a service which will manage the IP high availability and other services in your servers.  You can also integrate CRM along with heartbeat for your big cluster projects. Please see the pictorial representation of this cluster below.

HA IP:   10.0.0.100  -> This will be the high availability IP. Your website/application may need to point to this IP. This IP will be available only in the Active server . If the active server go down it will be switched to Passive server
Active Server : 10.0.0.101 ->  This is your active server
Passive Server : 10.0.0.102 ->  This will be your passive server , means backup server.

In both active  and passive server we need a hard disk partition , let us say  /dev/sdb1   with equal amount of disk space. The DRDB service will synchronize the  hdd partitions via a  drdb block file called /dev/drbd0. So keep in mind that this drdb block files is always refers to your original disk partition. So we are going to build this Active passive services  with high availability.

Software Requirements:

You may  need Centos 5.x or later version , because Centos already have drbd and heartbeat as binary distributions, otherwise you need to  compile and install drbd and heartbeat from  source.

Pre configuration:

You may need to disable SELinux your server and remove iptable firewalls. Also you need to edit /etc/hosts file in your active and passive servers as follows and make sure it is pointing to correct IPs.

10.0.0.101    active.yourserver.com
10.0.0.102    passice.yourserver.com

Now you need to unmount your disk partition  /dev/sdb1   and remove it from /etc/fstab too. We will erase this partition in the coming sessions. Also create a folder called /data, which we will use as mount point of drbd devic.

DRDB installation:

Let us install drbd first . You may need to install it in both servers and the drdb configuration must be unique.

# yum -y install kmod-drbd  drbd

Now  Edit  /etc/drbd.conf as follows,

resource mydrdb {
protocol C;
handlers {
pri-on-incon-degr “echo ‘DRBD: primary requested but inconsistent!’ | wall; /etc/init.d/heartbeat stop”; #”halt -f”;
pri-lost-after-sb “echo ‘DRBD: primary requested but lost!’| wall; /etc/init.d/heartbeat stop”; #”halt -f”;
}
startup {
degr-wfc-timeout 30;    #  30 seconds
}
disk {
on-io-error   detach;
}
net {
timeout 120;
connect-int 20;
ping-int 20;
max-buffers     2048;
max-epoch-size  2048;
ko-count 30;
cram-hmac-alg “sha1″;
shared-secret “drdbTest1gKey”;
}
syncer {
rate 50M;   # synchronization  data transfer rate
al-extents 257;
}
on active.yourserver.com {
device    /dev/drbd0;
disk      /dev/sdb1;
address   10.0.0.101:7789;
meta-disk internal;
}
on passive.yourserver.com {
device    /dev/drbd0;
disk      /dev/sdb1;
address   10.0.0.102:7789;
meta-disk internal;
}
}

Hope  you already umounted the partition  /dev/sdb1 . Let us make it clear using the following command

#  dd if=/dev/zero of= /dev/sdb1 bs=1M count=50

Now create the DRDB partition as follows,

# drbdadm create-md mydrbd

Format the drbd partition /dev/drbd0  with label mydrdb

# mkfs.ext3 -L mydrdb /dev/drbd0

Now let us start DRDB in both servers as follows,

# /etc/init.d/drbd start

Now login to your active server and do the following command , this command will tell the DRDB that current server is primary

# drbdadm –  primary mydrbd

Now you can check the status of drdb either from /proc/drdb or using the command etc/init.d/drbd status. You can see the DRDB started syncing in /proc/drdb

If it is not  working, there will be some issues in your installation procedure. If all ok let us proceed with the next step.

Heartbeat Installation:

You can use yum itself to install heartbeat

# yum -y install heartbeat  heartbeat-pils  heartbeat-stonith

There are 3 main configuration files  and one resource script folders for heartbeat as follows,

/etc/ha.d/ha.cf ->  The heartbeat configuration file
/etc/ha.d/haresources ->  The hearbeat resource file , in which we specify high availability IP and services lists which  need to start automatically by heartbeat
/etc/ha.d/authkeys -> Hearbeat servers authentication keys.
/etc/ha.d/resource.d/ -> This contain a set of init scripts which we use in “haresource” file for managing services

First let us create the heartbeat configuration file , /etc/ha.d/ha.cf , as follows,

# Heartbeat logging configuration
logfacility daemon

# Heartbeat cluster members
node active.yourserver.com
node passive.yourserver.com

# Heartbeat communication timing
keepalive 1
warntime 10
deadtime 30
initdead 120

# Heartbeat communication paths
udpport 694
ucast eth0 10.0.0.101    # make sure this ips are on eth0
ucast eth0  10.0.0.102
baud 19200

#  fail back automatically
auto_failback on

# Monitoring of network connection to default gateway
ping 10.0.0.1   # ping to gate way for network testing
respawn hacluster /usr/lib/heartbeat/ipfail

Now let us create an haresource file as follows,

active.yourserver.com  IPaddr::10.0.0.100/24 drbddisk::mydrdb  Filesystem::/dev/drbd0::/data::ext3 mysqld httpd

Let me explain the above terms,
The first term active.yourserver.com means all the following services must be  available in active server, if that server is available.

IPaddr::10.0.0.100/24 ->  This term will call the init script /etc/ha.d/resource.d/IPaddr  and activate the HA IP 10.0.0.100
drbddisk::mydrdb ->  This term will call the init script  /etc/ha.d/resource.d/drbddisk and make the switching to primary or seconday to drdb disk  labeled mydrdb
Filesystem::/dev/drbd0::/data::ext3 -> This term will call the init script /etc/ha.d/resource.d/Filesystem and which will mount the drdb disk /dev/drbd0 to the folder /data as a file system ext3
mysqld -> This term is pointing to /etc/ha.d/resource.d/mysqld , it is a soft link to  mysql startup script
httpd -> This term is pointing to /etc/ha.d/resource.d/httpd , it is a soft link to  httpd startup script

Now let us make the  soft links for mysqld and httpd init scripts under heartbeat resource folder as follows,
# cd /etc/ha.d/resource.d
# ln -sf /etc/init.d/mysqld ./mysqld
# ln -sf /etc/init.d/httpd  ./httpd

Now we need to add the auth key   /etc/ha.d/authkeys  as follows,
——–
auth 1
1 sha1 PutYourSuperSecretKeyHere

——–
Make it little secure lol

# chmod 600 /etc/ha.d/authkeys

So our heartbeat installation completed.

Testing:

The DRBD is  already  running. Let us start hearbeat service  in both servers.

# /etc/init.d/heartbeat start

You can monitor the log  from /var/log/messages

Within one minute the HA IP will be available in your  active server, also  you can see the drbd partition /dev/drbd0 mounted to /data and mysql and httpd services  are up and running.

Now stop the heartbeat server in active node and you can see the IP is activating in the passive server and it is starting the mysql and httpd services . Also the DRDB partition will be mounted in your passive server.

So now you can put what ever data to the folder /data, after mounting the partition /dev/drbd0 by the heartbeat.  It will be replicated to other sever. This is a block replication method. So if you have a corrupted file in one server, it  will be same in your other server too. So take care with your application.

Conclusion:

You can use the above active/passive high availability cluster for service like atmail , vbulletin , openx, etc,. It is also possible to move the mysql database to the DRBD partition too. But mysql master-master replication cluster is also good.  Also make sure you may meed to connect the NIC with fast switches or cables , to move files faster.
I am not sure you will read this conclusion  lol . If you do so , and you have any questions, please feel free to ask to me from the above contact page.

Popularity: 56%

Jun 16, 2010 Posted Under: Articles, Cluster, Openx   Read More

How to configure ssh key

How to configure ssh key

SSH key is a secure authentication method of openssh server. Let us install ssh key easily between two server.

Source Server:This is the server from which I need to connect.
Destination Server: This is the server into which I am going to connect.
Let us create ssh key for the root user in source server  for accessing a backup user  in destination server.

Create key in Source Server:

Do the following command as root

# ssh-keygen -t rsa

Now hit Enter key until you see the shell prompt again
So now we have two keys private and public in /root/.ssh  . We only need the public key

Copy public key to Destination server:

Copy the content of public key,/root/.ssh/id_rsa.pub,  from source server to the destination server into the files file  ( /home/backupuser/.ssh/authorized_keys  . This is for  ssh user  “backupuser”.
Testing:
Now try ssh from the  Source server to destination server as follows,

# ssh  backupuser@destinationserver

If you are in without password , then  the ssh-key configuration is success. If not, your ssh key is not working, check the error logs in /var/log/secure

Popularity: 11%

Jun 5, 2010 Posted Under: Articles   Read More

Speed up Vbulletin Forum with Memcached

Speed up Vbulletin Forum with Memcached

Memcached is a memory caching system. This will help to increase speed of your vbforum . Vb have default support for integrating memchached. I already wrote a document for using memcached with Openx software. Please see the steps below, to see how you can configure memcached in your server and integrate to vbulletin

Install memcached server

Download the memcached server from http://memcached.org/

# wget -c  http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
# tar -xzf  memcached-1.4.5.tar.gz
# cd memcached-1.4.5/
# yum -y install libevent libevent-devel
# ./configure --prefix=/opt/memcached
# make
# make install

Now install init script . I wrote an init script for redhat and centos servers , you can use it to start/stop memcached.

# wget -c http://downloads.sherin.co.in/memcached.redhar.rc.txt
# mv -f memcached.redhar.rc.txt /etc/init.d/memcached
# chmod 750 /etc/init.d/memcached
# /etc/init.d/memcached start

To start Memcached automatically during reboot add the following lines to /etc/rc.local

# /etc/init.d/memcached start

Next we need to install and configure php-pecl module for memcached.

Install php-pecl memcache

Download the latest stable memcached from http://pecl.php.net/package/memcache

# wget -c http://pecl.php.net/get/memcache-2.2.5.tgz
# tar -xzf  memcache-2.2.5.tgz
# cd memcache-2.2.5/
# phpize
# ./configure
# make
# make install

Now restart apache and create a phpinfo page and test whether the memcache options is showing or not. If it is there then you installed php module . If not you need to check your php.ini settings and enable memcache module

Now we need to configure vbulletin software as follows

Configure Vbulletin

Edit the Vb configuration file includes/config.php and uncomment the following lines

$config['Datastore']['class'] = 'vB_Datastore_Memcached';
$i = 0;
// First Server
$i++;
$config['Misc']['memcacheserver'][$i]           = '127.0.0.1';
$config['Misc']['memcacheport'][$i]                     = 11211;
$config['Misc']['memcachepersistent'][$i]       = true;
$config['Misc']['memcacheweight'][$i]           = 1;
$config['Misc']['memcachetimeout'][$i]          = 1;
$config['Misc']['memcacheretry_interval'][$i] = 15;

Now restart apache server . Your vbulletin now works with memcached. You can see the performance difference within 1 to 2 hours.

Popularity: 19%

Jun 5, 2010 Posted Under: Articles   Read More

GDB for Debugging Linux Software

GDB for  Debugging Linux Software

GDB is a nice tool for debugging linux software and find out its flaws. Let me give an easy way how you can use gdb to debug your application. If you see one of your application crashing or not working well, you can use gdb to debug it and send the result to its developers. The only thing you need to make sure is that , your program must be compiled with the debugger flag ‘-g’ , if not there will be no debugger flags in the software. In general all free and opensource software have gdb feature enabled by default.

Let us take and example here to study GDB . The command is “gedit” . It is an editor in gnome.
Step 1 : Go to shell and start the command with gdb

# gdb  gedit

It will show the following in my box,

sherin@:~$ gdb gedit
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /usr/bin/gedit...(no debugging symbols found)...done.
(gdb)

Step 2 : Run the command from gdb prompt

(gdb) run
Starting program: /usr/bin/gedit

Now gedit will be open and you can type and save a document.
It will show the debugger output in your gdb terminal

Step 3 : To stop execution use the command kill

(gdb) kill

Step 4: To exit from gdb use the command “quit”

These all are basic to know how you work win gdb.

Now if you need to debug an already running program use the flag –pid=PID

# gdb --pid=10345

If you are a developer , here is a good tutorial for you which will help you to debug your applications easily.

Popularity: 7%

Jun 2, 2010 Posted Under: Articles   Read More

Openx Cluster Handbook – 121 cluster Openx High performance simple cluster based on Nginx, lighttpd/apache

Openx Cluster Handbook – 121 cluster Openx High performance simple cluster based on Nginx, lighttpd/apache
Disclaimer : Please notices this document will help you for configuring an simple highperformance cluster for hosting Openx services. This article is licensed under Creative Commons Attribution-No ncommercial 2.5 India .Please don’t copy and paste the configurations to your server if it is not the hardware that mentioned in the hardware requirements.

1. Introduction

1.1 Why the name 121 Cluster?

1.2 Technology

2. System Requirements

2.1 Load Balancer Node
2.2 Web Servers Node
2.3 Database Server Node

3. Install and Configure Load Balancer

4. Install and Configure Webserver

4.1 File system configuration
4.2 Lighttpd installation
4.3 Apache installation

5. Install and Configure Database Server

6. Optimization

Appendix-A About The Author

Appendix-B License


1. Introduction

This document help you to setup a simple cluster for starters. This configuration using the best and popular software configuration for getting better stability and performance. This can be used for Openx cluster platforms and large vbulletin forums. Please not this is not a high availability solution but cluster. You can build this cluster with a minimum of 4 servers.

1.1 Why the name 121 Cluster?

Let me explain 1-2-1 cluster means ,

  • 1 – Load balancer
  • 2 – Werbserver , or multiple of 2
  • 1 – Database server

So this configuration is based on one load balancer , two or multiple of 2′s of webservers and one database server. Here all are servers there is no need to buy external devices. This is the simplest and well optimized cluster that you can build. You can see a graphical representation of this cluster as below,

1.2 Technology

We are here using Nginx webserver as http load balanced Proxy. It is the most popular proxy application and around 6% of high traffic websites in this world usin nginx. Some example sites using nginx are wordpress.com ,rambler.ru,fastmail.fm

Behind these proxies we use lighttpd as webservers for hosting our application. Lighttpd is a fast webserver with light foot print. It can simply handle millions of requests without increasing server load.It is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more) lighttpd is the perfect solution for every server that is suffering load problems.

2. System Requirements

Here we using the best webservers and proxy applications available on industry. It is fully a service based cluster. So no worry about kernel panics and OS corruptions. Also if you have a private LAN across these nodes, it is good to configure it otherwise you need to proxify the access over internet.

2.1 Load Balancer Node

This node is your public node,, That means your Openx/website domain is pointing to this server IP. I recommend to install ubuntu server Operating system/ Centos for your load balanced server. Here in this article I am mentioning the procedure based on ubuntu.

2.2 Web Servers Node

You may need a minimum of two webservers or multiple of 2, beacuse I am configuring GlusterFS between these webservers for file sharing. GlusterFS is one of the top cluster file system which is built on ext3. With 4 webservers you can configure a RAID10 like GlusterFs file system. That mean your cluster will work if 50% of node go down. It have automatic mirroring and scaling capacity. So there is no need to sync your website / openx contents regularly.

You can chose centos/ubuntu Os as operating system in webserver nodes. If you going to install cPanel then you can only use apache as webservers. Also remember the webservers must need same type of hardware configurations.

2.3 Database Server Node

As it is a single cluster we only use one database sever for Mysql. I recommend to use a bigger configuration of for this server as follows,

  • Processor -Dual Quad core AMD/ Xeon
  • RAM - 12 GB
  • HDD - SAS RAID 10

Again Use Centos as operating system in this server

3. Install and Configure Load Balancer

Please see the picture , the top one is load balance. Let us use the same IP as in this example. Download the latest stable version of Nginx from here .I used nginx-0.7.62.tar.gz . Please proceed as follows.

# wget -c http://sysoev.ru/nginx/nginx-0.7.62.tar.gz
# tar -xzf nginx-0.7.62.tar.gz
# cd nginx-0.7.62/
# ./configure --prefix=/opt/nginx
# make
# make install

Please resolve the dependencies before make.Now we installed Nginx here. It is a best webserver eventhough we can use it as load balanced proxy. The Nginx configuration file is /opt/nginx/conf/nginx.conf . Add the following contents to /opt/nginx/conf/nginx.conf

user  nobody;
worker_processes  5;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    worker_connections  4096;
}

http {
    include     mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;

    #gzip  on;

        upstream my_openx_site {
        server 10.0.0.11:80 weight=5;  # this is your webserver www1
        server 10.0.0.12:80 weight=5;  # this is your web server www2
        }

        server {
                 listen 80;
                server_name localhost;
                location / {
                         proxy_pass http://my_openx_site;
                }
        }

}

The above configuration have 5 worker processor and can handle 4096 requests per second. If you need more connections increase the limits.
Now add a user and group

# useradd nobody
# groupadd nobody

Now give suitable permission for log folders.

# chown -R nobody.nobody  /opt/nginx/logs/

Now we need to create a startup script. I have done some modification for the initscript as follows. Remember this is for ubuntu. Please copy the following contents to /etc/init.d/nginx

#! /bin/sh
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: nginx init.d script for Ubuntu 8.10 and lesser versions.
# Description:       nginx init.d script for Ubuntu 8.10 and lesser versions.
### END INIT INFO
#------------------------------------------------------------------------------
# nginx - this script, which starts and stops the nginx daemon for ubuntu.
#
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server.  This \
#               script will manage the initiation of the \
#               server and its process state.
#
# processname: nginx
# config:      /opt/nginx/conf/nginx.conf
# pidfile:     /opt/nginx/logs/nginx.pid
# Provides:    nginx
#                                                                                                                                                                                                                                 

# Notes: nginx init.d script for Ubuntu 8.10 and lesser versions.
 Functions
#------------------------------------------------------------------------------
. /lib/lsb/init-functions                                                                                                                                                                                                         

#------------------------------------------------------------------------------
#                               Consts
#------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx                                                                                                                                                                                                      

NAME=nginx
DESCRIPTION="Nginx Server..."                                                                                                                                                                                                     

PIDSPATH=/opt/nginx/logs
PS=$NAME                                #the process, which happens to be the NAME
PIDFILE=$NAME.pid                       #pid file
RUNAS=root                              #user to run as                                                                                                                                                                           

SCRIPT_OK=0                             #ala error codes
SCRIPT_ERROR=1                          #ala error codes
TRUE=1                                  #boolean
FALSE=0                                 #boolean                                                                                                                                                                                  

lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"                                                                                                                                                                                      

#------------------------------------------------------------------------------
#                               Simple Tests
#------------------------------------------------------------------------------                                                                                                                                                   

#test if nginx is a file and executable
test -x $DAEMON || exit 0                                                                                                                                                                                                         

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi                                                                                                                                                                                                                                

#set exit condition
#set -e                                                                                                                                                                                                                           

#------------------------------------------------------------------------------
#                               Functions
#------------------------------------------------------------------------------                                                                                                                                                   

configtest() {
        $DAEMON -t -c $NGINX_CONF_FILE
}                                                                                                                                                                                                                                 

getPSCount() {
        return `pgrep -f $PS | wc -l`
}                                                                                                                                                                                                                                 

isRunning(){
        pidof_daemon
        PID=$?                                                                                                                                                                                                                    

        if [ $PID -gt 0 ]; then
                return 1
        else
                return 0
        fi
}                                                                                                                                                                                                                                 

status(){
        isRunning
        isAlive=$?                                                                                                                                                                                                                

        if [ "${isAlive}" -eq $TRUE ]; then
                echo "$NAME found running with processes:  `pidof $PS`"
        else
                echo "$NAME is NOT running."
        fi                                                                                                                                                                                                                        

}                                                                                                                                                                                                                                 

removePIDFile(){
        if [ -f $PIDSPATH/$NAME.pid ]; then
                rm $PIDSPATH/$NAME.pid
        fi
}                                                                                                                                                                                                                                 

start() {
        log_daemon_msg "Starting $DESCRIPTION"                                                                                                                                                                                    

        isRunning
        isAlive=$?                                                                                                                                                                                                                

        if [ "${isAlive}" -eq $TRUE ]; then
                log_end_msg $SCRIPT_ERROR
        else
                start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON
                chmod 400 $PIDSPATH/$PIDFILE
                log_end_msg $SCRIPT_OK
        fi
}                                                                                                                                                                                                                                 

stop() {
        log_daemon_msg "Stopping $DESCRIPTION"                                                                                                                                                                                    

        isRunning
        isAlive=$?
        if [ "${isAlive}" -eq $TRUE ]; then
                start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE                                                                                                                                                     

                removePIDFile                                                                                                                                                                                                     

                log_end_msg $SCRIPT_OK
        else
                log_end_msg $SCRIPT_ERROR
        fi
}                                                                                                                                                                                                                                 

reload() {
        configtest || return $?                                                                                                                                                                                                   

        log_daemon_msg "Reloading (via HUP) $DESCRIPTION"                                                                                                                                                                         

        isRunning
        if [ $? -eq $TRUE ]; then
                `killall -HUP $PS` #to be safe                                                                                                                                                                                    

                log_end_msg $SCRIPT_OK
        else
                log_end_msg $SCRIPT_ERROR
        fi
}                                                                                                                                                                                                                                 

terminate() {
        log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"                                                                                                                                                                

        PIDS=`pidof $PS` || true                                                                                                                                                                                                  

        [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`                                                                                                                                                               

        for i in $PIDS; do
                if [ "$i" = "$PIDS2" ]; then
                        kill $i
                        removePIDFile
                fi
        done                                                                                                                                                                                                                      

        log_end_msg $SCRIPT_OK                                                                                                                                                                                                    

}

pidof_daemon() {
    PIDS=`pidof $PS` || true

    [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`

    for i in $PIDS; do
        if [ "$i" = "$PIDS2" ]; then
            return 1
        fi
    done
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|force-reload)
        stop
        start
        ;;
  reload)
        $1
        ;;
  status)
        status
        ;;
  configtest)
        $1
        ;;
  terminate)
        $1
        ;;
  *)
        FULLPATH=/etc/init.d/$NAME
        echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|terminate}"
        exit 1
        ;;
esac

exit 0

Now give execute permission to this script

# chmod 755 /etc/init.d/nginx

This is all about Load balancer configuration. You can start the Load balance, before that you may need to build your webservers as described below,

4. Install and Configure Webserver

Now we need to configure our web servers. All request came to Load balancer will be passed to your webserver. You can use lighttpd or apache2.2.x as webserver . I recommend to you lighttpd as webserver , because it can handle very high traffic websites with zero load. Before that we are going to configure gluster fs file system among the webserver. These file system is very scalable and high available.

4.1 File system configuration

If you don’t need a common file system, please skip this step.Let us use the minimal number of webservers for Glusterfs. If you have 4 webservers, it is easy to setup a RAID10 model cluster file system. Here we use two servers.
Download the latest stable version of glusterfs from http://www.gluster.com/ . I here used version glusterfs-2.0.2

# tar -xzf 	 glusterfs-2.0.2.tar.gz
# cd 	glusterfs-2.0.2/
# ./configure
# make
# make install

Now create the configuration files as follows.

# mkdir /etc/glusterfs/
# touch /etc/glusterfs/glusterfsd.vol

The server itself can act as server and client . The GFS server configuration is /etc/glusterfs/glusterfsd.vol . Now add the following contents to this file.

# file: /etc/glusterfs/glusterfsd.vol
volume posix
  type storage/posix
  option directory /data    # this partition is sharing
end-volume

volume locks
  type features/locks
  subvolumes posix
end-volume

volume brick
  type performance/io-threads
  option thread-count 8
  subvolumes locks
end-volume

volume server
  type protocol/server
  option transport-type tcp
  option auth.addr.brick.allow *
  subvolumes brick
end-volume

Now create the GlusterFS client configuration file /etc/glusterfs/glusterfs-client.vol as follows

# file  /etc/glusterfs/glusterfs-client.vol
volume remote1
  type protocol/client
  option transport-type tcp
  option remote-host 10.0.0.11
  option remote-subvolume brick
end-volume
volume remote2
  type protocol/client
  option transport-type tcp
  option remote-host 10.0.0.12
  option remote-subvolume brick
end-volume
volume distribute
  type cluster/distribute
  subvolumes remote1 remote2
end-volume
volume writebehind
  type performance/write-behind
  option window-size 1MB
  subvolumes distribute
end-volume
volume cache
  type performance/io-cache
  option cache-size 512MB
 subvolumes writebehind
end-volum

So now we have both client and server configuration for the Glusterfs file system. Here the /data partition is sharing around the webservers. You may need to create same configuration in all webservers.
Now start the glusterfs server

# /etc/init.d/glusterfsd  start

Now mount the file system to /home as follows

# glusterfs -f /etc/glusterfs/glusterfs-client.vol /home

Add the above line to rc.local file so during reboot your file system will mount automatically. So now we have a common files system among the webserver nodes.

4.2 Lighttpd installation

Please note either you install lighttpd as webserver or use apache. If you going to chose apache please jump to next step.
Download the lighty from http://www.lighttpd.net/download I used the latest version.

# wget -c http://www.lighttpd.net/download/lighttpd-1.4.23.tar.gz
# tar -xzf lighttpd-1.4.23.tar.gz
# cd lighttpd-1.4.23/
# ./configure --prefix=/opt/lighttpd --enable-fastcgi  --with-openssl
# make
# make install
# mkdir -p /etc/lighttpd/
# cp doc/lighttpd.conf  /etc/lighttpd/
# cp doc/rc.lighttpd.redhat  /etc/init.d/lighttpd
# chmod 755  /etc/init.d/lighttpd

Now edit the init script /etc/init.d/lighttpd and update the following line as given below,

lighttpd="/opt/lighttpd/sbin/lighttpd"

ow we need to configure lighttpd with php. Please install php as fcgi module. It is easy
Download the latest stable php from http://php.net/ and extract it. Now build it as follows,

# /configure --prefix=/usr/local/php5/  \
	--with-config-file-path=/usr/local/php5/etc \
	 --enable-force-cgi-redirect --enable-fastcgi\
	--with-gd --with-jpeg-dir=/usr/local --with-zlib \
	--with-openssl  --with-mysql
# make
# make install
# cp php.ini-dist  /usr/local/php5/etc/php.ini

Now edit /etc/lighttpd/lighttpd.conf as follows.

server.modules              = (
                               "mod_access",
                               "mod_fastcgi",
                               "mod_proxy",
                               "mod_scgi",
                               "mod_simple_vhost",
                               "mod_evhost",
                               "mod_accesslog" ) 

server.document-root        = "/home/openx/public_html"
server.errorlog             = "/var/log/lighttpd/error.log"
index-file.names            = ( "index.php", "index.html",
                               "index.htm", "default.htm" )
mimetype.assign             = (
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jar"          =>      "application/x-java-archive",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  ""              =>      "application/octet-stream",
 )                                                            

accesslog.filename          = "/var/log/lighttpd/access.log"
url.access-deny             = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/local/php5/bin/php",
                     "socket" => "/tmp/php.socket",
                     "max-procs" => 2,
                     "bin-environment" => (
                       "PHP_FCGI_CHILDREN" => "16",
                       "PHP_FCGI_MAX_REQUESTS" => "10000"
                     ),
                     "bin-copy-environment" => (
                       "PATH", "SHELL", "USER"
                     ),
                     "broken-scriptfilename" => "enable"
                 )))

So the above configuration will handle 10000 requests per children per second. You can adjust the factcgi.server options as you wish. Remember it is good all your webservers have same type configuration.

4.3 Apache installation

if you have cpanel or you are going to use apache2.2.x as webserver, please read my previous article to know how to configure it. Openx Hand Book

5. Install and Configure Database Server

Now you can install your mysql server and configure it.

# yum install mysql-server -y

Edit the my.cnf as follows(Remember it depend on your hardware )

[mysqld]
safe-show-database
old-passwords = 1
max_connections =2048
max_user_connections = 1024
key_buffer_size = 2048M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
table_cache = 4000
thread_cache_size = 384
wait_timeout = 20
connect_timeout = 10
tmp_table_size = 2048M
max_heap_table_size = 512M
max_allowed_packet = 64M
net_buffer_length = 16384
max_connect_errors = 10
thread_concurrency = 16
concurrent_insert = 2
table_lock_wait_timeout = 30
read_rnd_buffer_size = 786432
bulk_insert_buffer_size = 8M
query_cache_limit = 7M
query_cache_size = 64M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65536
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 16
long_query_time = 5
skip-name-resolve
skip-locking

[mysqld_safe]
open_files_limit = 8192

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M

Now restart mysql server and create a database as follows

# mysqladmin create openx_db

Now go to mysql command prompt and create a user and password as follows

#mysql>grant all privileges on openx_db.* to 'openx_user'@'%' identified by 'VERYSTRONGPASSWORD';

So now for your openx configuration use host as your mysql serve IP(here 10.0.0.20) and database user and password same as above.

6. Optimization

Now it is time to optimize your servers. Please read my Openx Handbook for optimizations ,

Appendix-A About The Author

My Name : Sherin A
My Web Site : http://www.sherin.co.in/ If you wan’t my designation , you can call me, System Engineer , Security Expert , Software Engineer or a FOSS member.
About me :
1) Founder of vcPanel ( Virtual Private Server Control panel )
2) Founder of FOSS award winner project ffmpegistaller )
3) Founder of FossBlog ( A Free and Open Source Software Blog
My relation with Adds : I am here with adds since 2003. Now providing Openx services for companies US , Canad, UK, Australia, Japan , India ,Germany, Croatia and Russia. Contact Me : All my contacts are available here or send email to me sherinmon[at]gmail[dot]com

Appendix-B License

This article is licensed under Creative Commons Attribution-Noncommercial 2.5 India It means you can share and redistribute it , but give a link back to this original document, because sometimes I will add more tips to this document.

Popularity: 79%

Jun 1, 2010 Posted Under: Articles, Cluster, Openx   Read More
Page 1 of 612345...Last »