readme.fr

Hot opensource news

Apache BalancerMember mod_proxy, try to be smooth

In my devops life, one of my customer ask to have the possibility to update one by one his java workers but without interuption. They are java workers behind an apache. Apache load balance request between the workers with mod proxy ajp.

The goal was to :

  1. Remove one of both tomcat server from the apache balancer proxy.
  2. Do whatever on this tomcat (upgrade code, change parameter, …)
  3. Add again the tomcat

How can we remove/add a worker in the apache proxy mod ? The first ideas was :

  • Stop worker (service tomcat stop) ?
  • Add iptables rules to  ?
  • Edit vhost configuration, remove membre, reload ?

But it is difficult to never interupt a request. So I want share a tip about BalancerMember from apache mod_proxy (and proxy_balancer).

I wrote a little python script to do remove a balancer member from the apache proxy without requetes interruption.

You can find my script here https://github.com/talset/apache-tools

How to

To run that script you need to setup standard python-argparse arg parse package :

apt-get install python-argparse
python-argparse

And then, if you need a specific servername (host) or ip to manage your apache mod proxy, you should edit following lines

#vhost name / header
headers = {"Host": '127.0.0.1' }
#ip to reach apache
url="http://127.0.0.1/balancer-manager"
balancer-manage.py
That it’s :
balancer-manage.py 
usage: balancer-manage.py [-h] [-l] [-a ACTION] [-w WORKER]

optional arguments:
  -h, --help            show this help message and exit
  -l, --list            List Worker member and status
  -a ACTION, --action ACTION
                        "enable" or "disable" the specified Worker
  -w WORKER, --worker WORKER
                        Worker name : example ajp://127.0.0.1:8001
help balancer-manage.py
Now we will look how use it in a real usecase.

Usecase

Context : We need update an application on each webserver without interuption

 

We currently have Apache proxy with 2 members. Each members are running the old version of our customer application.

apache1

 ./balancer-manage.py -l
    Worker                                   | Status     | Elected   
    ajp://10.152.45.1:8001                   | Ok         | 1        
    ajp://10.152.45.2:8001                   | Ok         | 2
balancer members list

We removed the first web 10.152.45.1 to perform an update of the application

apache2

 

./balancer-manage.py -w ajp://10.152.45.1:8001 -a disable
    Worker                                   | Status     | Elected   
    ajp://10.152.45.1:8001                   | Dis        | 0         
    ajp://10.152.45.2:8001                   | Ok         | 0 
Disable web1

Enable the first web 10.152.45.1. At this state we have removed web1 from the balancer and our customer have upgraded his application. Next step : Re enable web1 in the load balancer.

apache5

 

./balancer-manage.py -w ajp://10.152.45.1:8001 -a enable
    Worker                                   | Status     | Elected   
    ajp://10.152.45.1:8001                   | Ok         | 0         
    ajp://10.152.45.2:8001                   | Ok         | 0
enable web1

We now balance between an old version of the application and new at the same time. We have proceed an upgrade on one tomcat without interrupt the service. Next step do the same thing on web2. Remove the second web 10.152.45.2 and upgrade the application

apache3

./balancer-manage.py -w ajp://10.152.45.2:8001 -a disable
    Worker                                   | Status     | Elected   
    ajp://10.152.45.1:8001                   | Ok         | 0         
    ajp://10.152.45.2:8001                   | Dis        | 0
disable web2

The two webs are upgraded, But web2 still remove from the loadbalancer. So finally add the last member into the apache proxy.

apache4

./balancer-manage.py -w ajp://10.152.45.2:8001 -a enable
    Worker                                   | Status     | Elected   
    ajp://10.152.45.1:8001                   | Ok         | 0         
    ajp://10.152.45.2:8001                   | Ok         | 0
enable web2

We just upgraded 2 webs without request interuption. Smooth upgrade 😉

GrumpyCat_HC_FINAL.indd

 

talset
talset on Githubtalset on Linkedin

, , , , ,

3 thoughts on “Apache BalancerMember mod_proxy, try to be smooth

  • DeetSl says:

    Hi there! I simply wish to give a huge thumbs up for the great data you will have right here on this post. I might be coming again to your blog for extra soon.

  • rok says:

    Hello big thank you for posting this content ! moreover i would like to know which tool do you use to create all the illustration and image ? i realy like the way it look , i hope you can help . Thanks

    Cheers

    • gaelL says:

      Hi,

      Sorry for this verrrrrry late answer. But we are using inkscape for all schema.

      It’s kind of manual draw based on quite lot of free svg images that you can find for example here : freevector.co

      We change little bit colors and sometime add sofrware logo on it.

Leave a Reply to rok Cancel reply

Your email address will not be published. Required fields are marked *