Friday, April 15, 2011

Linux Virtual Server (LVS)

yum -y install ipvsadm.x86_64
yum -y install perl-Authen-Radius.noarch
yum -y install perl-Compress-Zlib.x86_64
yum -y install perl-Convert-ASN1.noarch
yum -y install perl-Crypt-SSLeay.x86_64
yum -y install perl-Data-HexDump.noarch
yum -y install perl-Digest-HMAC.noarch
yum -y install perl-Digest-SHA1.x86_64
yum -y install perl-HTML-Parser.x86_64
yum -y install perl-IO-Socket-SSL.noarch
yum -y install perl-LDAP.noarch
yum -y install perl-Mail-POP3Client.noarch
yum -y install perl-MailTools.noarch
yum -y install perl-Net-DNS.x86_64
yum -y install perl-Net-IMAP-Simple.noarch
yum -y install perl-Net-IMAP-Simple-SSL.noarch
yum -y install perl-Net-IP.noarch
yum -y install perl-Net-SSLeay.x86_64
yum -y install perl-TimeDate.noarch
yum -y install perl-XML-NamespaceSupport.noarch
yum -y install perl-XML-SAX.noarch
yum -y install perl-libwww-perl.noarch
yum -y install heartbeat-ldirectord
yum -y install perl-DBI.x86_64
yum -y install perl-DBD-MySQL.x86_64
yum -y install heartbeat.x86_64

#### Create /etc/ha.d/ldirectord.cf

vi /etc/ha.d/ldirectord.cf

checktimeout=10
checkinterval=5
autoreload=no
logfile="/var/log/ldirectord.log" ####touch /var/log/ldirectord.log
emailalert="abc@xyz.com"
emailalertstatus=all
quiescent=yes

###### Add HTTP Service #############
virtual =192.168.250.1:80
real=192.168.1.1:80 masq 10
real=192.168.1.2:80 masq 10
service=http
scheduler=wlc
netmask=255.255.0.0
protocol=tcp
checktype=negotiate
##### Add Mysql Service #############
virtual =192.168.250.2:3306
real=192.168.1.21:3306 masq 10
real=192.168.1.22:3306 masq 10
service=mysql
scheduler=wlc
netmask=255.255.0.0
protocol=tcp
checktype=negotiate
login="test"
passwd="test"
database="test"
request="SELECT 1;"

### Run following on LVS directors add in /etc/rc.local

echo "1" >/proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects ## if bonding then use bond0
echo "1" > /proc/sys/net/ipv4/vs/expire_quiescent_template


### On real server change gateway to virtual ip
## Add default gateway as LVS VIP server & below line in rc.local

/sbin/route del -net 192.168.0.0 netmask 255.255.0.0 dev eth0

################ Configure Heartbeat #################################################

yum -y install heartbeat

vi /etc/ha.d/ha.cf
######################################
#logfacility daemon # This is deprecated
keepalive 3
deadtime 10
warntime 5
initdead 60
mcast eth0 229.0.0.1 777 1 0
node hostname1.com ## Please enter proper hostname
node hostname2.com ## Please enter proper hostname
logfile /var/log/hb.log # Heartbeat logfile.
debugfile /var/log/heartbeat-debug.log # Debugging logfile.
auto_failback no
uuidfrom nodename
####################################

touch /var/log/hb.log
touch /var/log/heartbeat-debug.log
touch /var/log/ldirectord.log

vi /etc/ha.d/haresources ## please specify other redundant servers hostname

hostname2.com IPaddr::192.168.250.1/16/eth0 ldirectord ##

vi /etc/ha.d/authkeys
auth 4
4 md5 MySecret

chmod 600 /etc/ha.d/authkeys

service heartbeart start

chkconfig ldirectord off
chkconfig sendmail on


##########################################################################

Temprorary remove server & down the service of single VIP

### timely remove the server from LVS

ipvsadm -d -t 192.168.250.1:80 -r 192.168.1.1:80

### add again

ipvsadm -a -t 192.168.250.1:80 -r 192.168.1.1:80 -m -w 10

### if u want to make down one VIp only
ifconfig eth0:xx down

No comments: