Monday, July 21, 2008

EC2 Load Balancing

Re: Feature Guide: Amazon EC2 Elastic IP Addresses

Posted: Mar 27, 2008 2:06 PM PDT

Load balancing is not really a problem, assuming you do not object torunning a separate small instance to accomplish this task. This wouldessentially replace a dedicated hardware load balancer in a dedicatedhosting environment. I have made myself a build using Ubuntu 7.10(Gutsy) and HAProxy, using a standard Amazon supplied API, and it worksgreat.

Here are the specifics if you want to try it out.

------------------------------------------------------------------------------------------------------

Starting with clean Linux Load of Ubuntu 7.10

apt-get update

apt-get upgrade

apt-get dist-upgrade

apt-get install joe

joe /etc/apt/sources.list

change all GUTSY to HARDY

apt-get update

apt-get install haproxy keepalived

joe /etc/apt/sources.list

change all HARDY back to GUTSY

apt-get update

cp /etc/haproxy.cfg /etc/haproxy.cfg_orig

cat /dev/null > /etc/haproxy.cfg

joe /etc/haproxy.cfg

adduser yourusername

adduser yourusername haproxy

adduser yourusername root

global

log 127.0.0.1 local0

log 127.0.0.1 local1 notice

#log loghost local0 info

maxconn 8192

#debug

#quiet

user haproxy

group haproxy

defaults

log global

mode http

option httplog

option dontlognull

retries 3

redispatch

maxconn 8192

contimeout 5000

clitimeout 50000

srvtimeout 50000

listen WebFarm *:80 #HAPROXY listens to ALL IP's Port 80

mode http

stats enable

stats auth yourusername:yourusernamespassword

balance roundrobin

cookie JSESSIONID prefix

option httpclose

option forwardfor

option httpchk *

server WebApp01 192.168.0.102:80 cookie A check #External IP Server 1

server WebApp02 192.168.0.103:80 cookie B check #External IP Server 2

joe /etc/default/haproxy

ENABLED=1 (change from 0)

joe /etc/sysctl.conf

net.ipv4.ip_nonlocal_bind=1

sysctl -p

ip addr sh eth0

killall apache2 #Just in case you did not start with a fresh build

/etc/init.d/haproxy stop

/etc/init.d/haproxy start

-------------------------------------------------------------------

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

Voila! You have a working load balancer in Amazon!

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

-------------------------------------------------------------------

To use:

-------------------- to run (assuming 67.202.17.173 is Amazon external ip address

http://67.202.17.173 # SHOWS WEBSITE

http://67.202.17.173/haproxy?stats # SHOWS HAPROXY STATS

user: yourusername

Pass: yourusernamepassword

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

Youcan now configure HAProxy to load balance by one of severalmethodologies, and can monitor its effectiveness from your browser.

Hope this helps somebody out there!

Message was edited by: pivotaveracity

Sunday, July 20, 2008

Resize LVM volumes (in use)

Boot with rescue CD.
This will Resize Volume LogVol00 in VolGroup VolGroup00 to 10 Gigs


# lvm vgchange -a y
# e2fsck -f /dev/VolGroup00/LogVol00
# resize2fs -f /dev/VolGroup00/LogVol00 10G
# lvm lvreduce -L10G /dev/VolGroup00/LogVol00