Thursday, January 5, 2012

Lighttp as a Load Balancer

Environments: 
There are three servers. One has been installed lighttp (192.168.152.142, here). The other two servers (192.168.152.140, 192.168.152.143) have been install tomcat server (here).

Scenario:
The http request be submitted to lighttp server, then we take lighttpd server as a load balancer to assign this request to one of tomcat servers equally.

Configuration Lighttp (Linux)
1. Add the sentence (include "conf.d/proxy.conf")  into lighttp.conf (/etc/lighttpd/lighttpd.conf).
2. Add the sentence ("mod_proxy") into module.conf (/etc/lighttpd/modules.conf) server.modules section, as follows:
server.modules = (
  "mod_access",
  "mod_proxy",
#  "mod_alias",
#  "mod_auth",
#  "mod_evasive",
#  "mod_redirect",
#  "mod_rewrite",
#  "mod_setenv",
#  "mod_usertrack",
)

3. Add the following paragraph into proxy.conf (/etc/lighttpd/conf.d/proxy.conf)
  • $HTTP["url"] =~ "^/examples/" {
  • proxy.balance = "hash"
  •     proxy.server = (
  •         "" => (
  •                   ("host" => "192.168.152.140", "port" => 8080),
  •                   ("host" => "192.168.152.143", "port" => 8080)
  •               )
  •     )
  • }
where "examples" is your project name, you can even use ^ symbol to represent all projects.
4. restart your lighttpd
# service lighttpd restart 

Configuration Lighttp (Windows) 

1. uncomment "mod_proxy" in lighttpd-inc.conf (C:\Program Files (x86)\LightTPD\conf\lighttpd-inc.conf) at server.modules section, as follows:

server.modules              = (
                                "mod_access",
                                "mod_accesslog",
                                "mod_alias",
#                               "mod_auth",
#                               "mod_cgi",
#                               "mod_cml",
#                               "mod_compress",
#                               "mod_dirlisting",
#                               "mod_evasive",
#                               "mod_evhost",
#                               "mod_expire",
#                               "mod_extforward",
#                               "mod_fastcgi",
#                               "mod_flv_streaming",
#                               "mod_indexfile",
#                               "mod_magnet",
#                               "mod_mysql_vhost",
        "mod_proxy",
}

2. modify the content about your proxy location in lighttpd-inc.conf (C:\Program Files (x86)\LightTPD\conf\lighttpd-inc.conf), as follows:

proxy.server               = ( ".jsp" =>
                               ( "localhost" =>
                                 ("host" => "192.168.152.140","port" => 8080),
("host" => "192.168.152.143","port" => 8080)
                               )
                             )


3. restart your lighttd server. 



No comments:

Post a Comment