Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

docker-http-withmodjk

Apache http server with mod_jk and dynamic loadbalacing of new containers

An apache http server that demonstrates how new tomcat instances are included into mod_jk loadbalancing on the fly.
Apache has a virtual host that is bound to a tomcat cluster via mod_jk.
The cluster is defined in a workers.properties file. This file is refreshed, if new tomcat instances for that cluster are stopped or started.

The apache server relies on a running consul instance and the registrator from progrium.

A tomcat instance are started with additional information so that registrator is able to store this information in consul.

  1. To identify a new container as a member of the tomcat-cluster the container is started with -e "SERVICE_TAGS=tomcat-service" (convenience script provided).

  2. The name of the container is set with --name $JVM\_ROUTE. Where JVM_ROUTE = "tomcat_HOSTNAME_PORT".

  3. Tomcat is started with -e "SERVICE_NAME=${CLUSTER\_NAME}".
    This identifies to which service this instance belongs. Tomcat instances of one service are load balanced.

  4. tomcats jvm route is set with -e TOMCAT\_JVM\_ROUTE=$JVM_ROUTE.

Registrator picks up this information when a new container starts and adds the information to consul.
The apache container start a go program that reads the information of the new tomcat instance from consul, updates its workers.properties file and restarts the webserver.

This is a very simple loadbalancing solution for docker and you can achieve much more sophisticated solutions with kubernates, mesos, ....

But if you´d like to have a look at how little code is neccessary to listen to events and adopt the workers.properties file, please check out
https://github.com/christianwoehrle/docker-modjk-bridge

To start experimenting:

  1. Run ./create-dockercompose.sh
    This substitutes the Placeholder HOST_IP and CURDIR in the file docker-compose.yml-template with your real hostip and current Path (necessary for the registrator to find the consul instance.
    I haven´t been able to find a better solution, I would greatly appreciate any suggestion for impovement.
  2. Run docker-compose up if you have docker-compose installed (TODO, write a script to start the containers with bash)
  3. Point your Browser to http://YOURIP:49132/jkstatus where YOURIP could be 127.0.0.1 when running linux or the IP of your docker daemon if you are running boot2docker.
    You should see an empty jkstatus page, as no tomcat isntances have been started yet.
  4. Run ./runTomcatInstance.sh a few time to start a new tomcat instances in a docker container. The tomcat instances are started with a sample web-application that displays the container ip and allows to create/destroy a session.
  5. Reload http://YOURIP:49132/jkstatus in your browser to see how the modjk loadbalancer has dynamically included the new instances into the loadbalancing.
  6. Enter the url http://YOURIP:49132/Dude/DudeServlet in your browser to access the webapplication.
    As long as you don´t login, reloading or pressing the noop button should direct you to different servers in a round robin fashion (at least if you have created >1 tomcat instances). Creating more tomcat instances increases the range of servers, that will display their ip address.
    As soon as you login, you should stick to one server if you reload the page or press the noop-button.
    If you logout, the browser still sends the JSESSIONID-header and unfortunately, you are stuck with the server you worked with. If you delete the cookie in the browser, round robin works again.
Docker Pull Command
Owner
christianwoehrle

Comments (0)