Setup Load-Balancing Cluster with LVS and Piranha on Centos 6

Published December 3, 2013 by Siva


piranha – This is a package that provides a configuration interface for setting up LVS.

ipvs The name of the module that allows a load-balancing on Linux.

ipvsadm – A package (and a command) that makes administrating ipvs possible. Be aware, you either user piranha-gui or /etc/sysconfig/ipvsadm to configure ipvs.

LVS Linux Virtual Server – the project name of all tools used in this document.

pulse – A service (/etc/init.d/pulse) that runs on both active and backup machine and opens a port to make checking possible. piranha-gui configures everything, pulse actually activates all configurations.

nanny A process started by pulse to monitor the realservers.

nat – Network Address Translation. A common combination with LVS. In case NAT is uses, the loadbalancer/director/LVS accepts traffic on one the VIP and sends traffic to the realservers. Be aware, the current implementation of ipvsadm does not properly use Source NAT, it currently does not rewrite the source address.

direct routing – A method of routing available in LVS. Traffic is received on the VIP, sent through to the realservers. The realservers receive the traffic as if it was sent to the VIP, so the VIP must be configured on the realservers. To avoid arp-caches to register the wrong MAC-address-IP-address combination, a few “tricks” must be done.

wlc – Weighted Least Connections, an algorithm to balance load to realservers.

VIP Virtual IP. – The IP-address the service is configured on.

RIP Real server IP. – The IP-address of a real-server.

realserver – The server providing the actual service. This can be Linux, Windows, whatever.

This setup guide is about building web cluster with a pair of Linux loadbalancers as frontend.
It uses Linux Virtual Server(LVS) and Piranha. Piranha is a web-based gui installed in LVS Routers primarily to generating a valid /etc/ file.

Start by installing LVS on LVS Router.

[root@lvsrouter ~]# yum groupinstall “Load Balancer”
Package Arch Version Repository Size
ipvsadm x86_64 1.25-10.el6 base 41 k
piranha x86_64 0.8.6-2.el6_4.1 updates 623 k
Installing for dependencies:
libedit x86_64 2.11-4.20080712cvs.1.el6 base 74 k
libnl x86_64 1.1-14.el6 base 121 k
php x86_64 5.3.3-22.el6 base 1.1 M
php-cli x86_64 5.3.3-22.el6 base 2.2 M
php-common x86_64 5.3.3-22.el6 base 524 k

Transaction Summary
Install 7 Package(s)

Total download size: 4.7 M
Installed size: 18 M
Is this ok [y/N]: y

Start piranha and pulse services on reboot.

chkconfig piranha-gui on
chkconfig pulse on

Set a password for piranha web


Allow ports in iptables

vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3636 -j ACCEPT

Edit piranha config

vi /etc/sysconfig/ha/conf/httpd.conf

Start the piranha gui service

service piranha-gui start

For LVS router to forward network packets properly to real servers, each LVS router node must have IP forwarding turned on. Turn on packet forwarding by editing sysctl.conf:

vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

Reload sysctl

sysctl -p /etc/sysctl.conf

Start http services on the Real Servers

service httpd start

On the LVS Router, log in to the Piranha web ui to begin configuration.

Enter Primary Router’s IP address in “Global Settings”->”Primary server public IP:”.
CENTOS Piranha Global Settings

Enter Redundant Router’s IP address in “Redundancy”->”Redundant server public IP:”.
CENTOS Piranha Redundancy

Enter Virtual Server settings in “Virtual Servers”->”Virtual Server”.
CENTOS Piranha Virtual Servers

Include Real Server settings in “Virtual Servers”->”Real Server”.
CENTOS Piranha Real Server

On each time the Piranha Gui was changed, have to sync the settings to Backup Routers,
and restart the pulse service on both routers.

service pulse restart

To see the virtual server’s statistics, use “watch ipvsadm”.

[root@lvsrouter ~]# watch ipvsadm

Courtesy :

Setup sSMTP configuration , Sending email without smtp service

Published December 3, 2013 by Siva

Follow the below steps on terminal…

# yum -y install ssmtp

If you have Sendmail installed, you need to run the following command below to change your default Mail Transfer Agent (MTA): –

# alternatives –config mta

There are 2 programs which provide ‘mta’.

Selection Command
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number: 2

You can verify the sendmail binaries by running the command below: –

# sendmail -V
sSMTP 2.61 (Not sendmail at all)

Now, sSMTP is installed and we will configure the mail server info to relay outgoing email. We going to create new configuration files as below: –

# mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.orig
# touch /etc/ssmtp/ssmtp.conf
# mv /etc/ssmtp/revaliases /etc/ssmtp/revaliases.orig
# touch /etc/ssmtp/revaliases

Next, we will configure sSMTP to forward email to any shared hosting server either running CPanel or DirectAdmin.

Include the following below in /etc/ssmtp/ssmtp.conf file: –


Include the following below in /etc/ssmtp/revaliases file: –

If you an option to forward email to Gmail server, you can configure using steps below.

Replace previous configuration to below in /etc/ssmtp/ssmtp.conf file: –


Replace previous configuration to below in /etc/ssmtp/revaliases file: –

Next, you can start sending email using your preferred email server using command below: –

# echo “Testing outgoing email” | mutt -s “Testing”

Finally, with all the configuration above I hope you are able to use and enjoy your sSMTP to send an email.

Thank you.

grub normal.mod not found – Error Fix on Ubuntu

Published December 3, 2013 by Siva

Dear All,

After long time, I am back…As I bit busy with office work, I dont have time to spent.

Recently i faced on issue on ubuntu desktop 12.10. When i boot the system , I got grub normal.mod not found.

To follow the below steps

1) Boot Live CD or USB (Try ubuntu option)
2) It will automatically connect the internet, else please configure network settings as per your infrastructure
3) open terminal > sudo add-apt-repository -y ppa:yannubuntu/boot-repair && sudo apt-get update
4) apt-get install -y boot-repair && boot-repair
Press Enter. That’s it, the Boot-Repair window will appear!
5) Select recommended repair option, it will take 5 – 10 mins , then reboot,

Problem resolved.

Import CSV file Into MYSQL DB

Published September 18, 2012 by Siva

System administrators sometime automate CSV file in to MYSQL DB with requested structure.

Login into mysql as root user, And execute the Follwing query with correct your path & tour fileds.
load data local infile ‘/tmp/file.csv’ into table mytable fields terminated by ‘, ‘
lines terminated by ‘\n’

The query load the data from file to mysql talble called mytable.
I assume csv file contain , seperated. For Eg
# cat /tmp/file.csv

Once everything done use cron to automate. to write simple script for automate this.

Kickstart With PXEboot

Published May 17, 2012 by Siva

Kickstart With PXEboot

I have used Centos 5.5, please read the below steps (I have used)

Centos 5.5 Media
Creating Kickstart file(ks.cfg)
Setup NFS server
Installing PXE boot loader
Setup TFTp Server
Setup DHCP server

1. Copy the Centos DVD media files to my NFS server.

#cp -fr /mnt/media /share/centos5.5
#mkisofs –J –r –T –o RHEL-disc1.iso /share/centos5.5

Create a customized kickstart configuration file by using “ Applications -> Systems Tools -> Kickstart”. Save this file to /share/centos5.5 directory.

#vi /share/centos5.5/ks.cfg

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth –useshadow –enablemd5
key –skip
# System bootloader configuration
bootloader –location=mbr
# Partition clearing information
clearpart –all –initlabel
# Use graphical install
# Firewall configuration
firewall –disabled
# Run the Setup Agent on first boot
firstboot –disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging –level=info
# Use NFS installation media
nfs –server= –dir=/data/install/ISO
# Network information
network –bootproto=dhcp –device=eth0 –onboot=on
#Root password
rootpw admin123

# SELinux configuration
selinux –disabled
# System timezone
timezone Asia/Calcutta
# Install OS instead of upgrade
# X Window System configuration information
xconfig –defaultdesktop=GNOME –depth=8 –resolution=800×600
# Disk partitioning information
part /boot –bytes-per-inode=4096 –fstype=”ext3″ –size=100
part / –bytes-per-inode=4096 –fstype=”ext3″ –size=10000
part swap –bytes-per-inode=4096 –fstype=”swap” –size=512
@GNOME Desktop Environment
@Text-based Internet
@Development Tools
@FTP Server
@Administration Tools

3. Setup the NFS server
vim /etc/exports
/share/centos5.5 *(ro)

#/etc/init.d/nfs restart
#/etc/init.d/portmap restart

4. TFTP Configuration

yum install syslinux
cp /usr/lib/syslinux/pxelinux.0 /tftpboot

Create the pxelinux.cfg directory in /tftpboot and edit the default file:

# You can have multiple Kickstart file having multiple versions
default linux
label linux
kernel vmlinuz
append ksdevice=eth0 load_ramdisk=1 initrd=initrd.img network ks=nfs:

Configure the TFTP server by editing /etc/xinetd.conf/tftp file:

#service xinetd restart

5. DHCP Configuration


i added the following block

host mysys {
hardware ethernet 00:ab:cd:df:11:12;
filename “pxelinux.0”;
#service dhcpd restart

6. Client Side

Please boot via network card (it should support network booting), It will fetch the IP from my DHCP server, start the installation.. 🙂

Disable Directory Browsing in Linux Apache Server

Published May 14, 2011 by Siva

Disable directory browsing using .htaccess:-
Open your .htacces file

Look for Options Indexes
If Options Indexes exists modify it to Options -Indexes or else add Options -Indexes as a new line
The directory browsing feature should be disable by now

Disable directory browsing using httpd.conf:-

Open your httpd.conf, normally it’s located at /usr/local/apache/conf or /etc/httpd.conf
Go to your own Virtual Host settings and look for “Options Indexes”
Change the Indexes to -Indexes if Option Indexes exists or else add the Options -Indexes line
Restart your apache web server.

The directory browsing feature should be disable by now

Disable directory browsing in CPanel Share Hosting enviroment:-

Login to your CPanel
Click on Index Manager
Directory will be list down. Click on the directory name which you want to disable the directory browsing
Select No Index and click Save

The directory browsing feature should be disable by now
Once you disable directory browsing, visitor will not able to browse your directory by accessing the directory directly (if there is no index.html file).
This will protect your files from exposing to the public.