load balancing with mod_proxy_balancer

1.

$ a2enmod proxy

$ a2enmod proxy_balancer # provides three algorithms for scheduling requests [ default = “byrequest” algorithm ]

$ a2enmod proxy_http # for HTTP-aware proxying of requests.
$ a2enmod status # for getting the status of the backend servers.

$ a2enmod rewrite # require by mod_proxy to do reverse proxying ( Client thinks the proxy server is serving its request, but in fact the proxy is forwarding the request to a different backend server )

2. config loadbalancing

$ cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default_orig

edit /etc/apache2/sites-available/default

NameVirtualHost *
<VirtualHost *>
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/
ProxyRequests Off
# This is sets up access for proxy forwading.
# This configuration allows all request to be forwarded.
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# If the url includes /balancer-manager,
# The server will not proxy the request
ProxyPass /balancer-manager !
# This maintains session across the different backend servers
ProxyPass / balancer://mycluster/ stickysession=BALANCEID nofailover=On
# The following allows every request to be forwared to the given servers
ProxyPassReverse / http://192.41.170.42/
ProxyPassReverse / http://192.41.170.41/
# Next the backend web servers and the scheduling algorithm are defined
<Proxy balancer://mycluster>
BalancerMember http://192.41.170.42 route=http1
BalancerMember http://192.41.170.41 route=http2
ProxySet lbmethod=byrequests
</Proxy>
# Balancer-manager Web app allows configuration of routes
<Location /balancer-manager>
SetHandler balancer-manager
Order deny,allow
Allow from all
</Location>
</VirtualHost>

ref : http://www.howtoforge.com/load_balancing_apache_mod_proxy_balancer


http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for more on reverse proxying and the necessary URL rewriting

Advertisements

load balancing with pound

1.

$ apt-get install pound

2. edit /etc/pound/pound.cfg

ListenHTTP
Address 127.0.0.1  # ip เครื่องเรา
Port    80 # port เครื่องเรา

## allow PUT and DELETE also (by default only GET, POST and HEAD)?:
xHTTP           0   # 0 คือ ทั้งหมด

Service
BackEnd
Address 127.0.0.1  # address ที่ให้ redirect ไป ( ใส่เปง DNS ก็ได้ เช่น google.com )
Port    80
End
End
End

NOTE : Service ใส่ลงไปหลายๆอันก็ได้นะ

หรือ อาจจะใช้ matching urls ให้ static file วิ่งไปอีกเครื่องก็ได้

Service
    URL ".*.(jpg|gif|png|js|css|jpeg|html|txt)"
    BackEnd
        Address 127.0.0.1
        Port    8000
    End
End

หรือ เอา

checkURL “.*.(jpg|gif|png|js|css|jpeg|html|txt)”

ไปใส่ไว้นอก Service ก็ได้

3. edit /etc/default/pound

startup=1
4.

$ sudo /etc/init.d/pound start