如何以编程方式调整mod_jk负载均衡器配置中的disable指令?

时间:2021-06-21 16:52:24

We have a setup where we have one httpd (apache) with mod_jk talking in a load balance setup to three tomcat servers. We have to recycle each tomcat instance envery three hours. So tomcat1 will restart at 1, and tomcat2 at 2 and ... until tomcat1 recycles again at 4.

我们有一个设置,我们有一个httpd(apache),mod_jk在负载平衡设置中与三个tomcat服务器通信。我们必须在三个小时内回收每个tomcat实例。因此tomcat1将在1处重新启动,而tomcat2将在2处重新启动......直到tomcat1再次在4处再循环。

We want to configure a script or a type of program to disable the worker node that is going through a recylce to minimize session errors at the user using our application.

我们希望配置一个脚本或一种程序来禁用正在进行重新计算的工作节点,以最大限度地减少使用我们的应用程序的用户的会话错误。

Any suggestions.

3 个解决方案

#1


mod_jk re-reads workers.properties on an "apachectl graceful", so you if your workers.properties looks like this:

mod_jk在“apachectl graceful”上重新读取workers.properties,所以如果你的workers.properties看起来像这样:

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2, tomcat3

... 

You could just write a script which replaces the balanced_workers list with the ones you want, and then graceful's apache

你可以写一个脚本,用你想要的那个替换balanced_workers列表,然后是graceful的apache

Update here's a script to do just that, which I cobbled together from some bits I had lying around. I wouldn't suggest using it in production, but it might give you some ideas for your own version.

更新这里是一个脚本来做到这一点,我拼凑了一些我躺在周围的位。我不建议在生产中使用它,但它可能会为您自己的版本提供一些想法。

#!/bin/bash

# set some paths
WORKERS_PROPERTIES="./workers.properties"
APACHECTL="/usr/sbin/apache2ctl"

# what does the loadbalancer config line look like?
WORKER_LINE_START="worker.loadbalancer.balanced_workers="
# full list of workers
ALL_WORKERS="tomcat1 tomcat2 tomcat3"

# first command line arg is the worker to remove. 
remove=$1

# build up the new line listing the active workers
worker_line=$WORKER_LINE_START
sep=""
for worker in $ALL_WORKERS
do
  if [ ${remove} != ${worker} ]
  then
     worker_line="${worker_line}$sep $worker"
     sep=","
  fi
done

# sed hackery to replace the current line with the one we just built.
# needs gnu sed (or another one that supports in-place editing)
sed -i.bak "s/^$WORKER_LINE_START.*$/$worker_line/" $WORKERS_PROPERTIES

# restart apache
$APACHECTL graceful

#2


Chris thanks or your answer. I am sure it will work, but I wanted to trigger the change at run time, even though the graceful restart is very similar. I was able to accomplish my describe task the following way.

克里斯谢谢你的回答。我确信它会工作,但我想在运行时触发更改,即使正常重启非常相似。我能够通过以下方式完成我的描述任务。

In your httpd.conf file you should add the following lines to enable the jkmanager for mod_jk module.

在httpd.conf文件中,您应该添加以下行以启用mod_jk模块的jkmanager。

<Location /jkmanager/>
JkMount jkstatus
order deny,allow
allow from <your ip address>
allow from 127.0.0.1
deny from all
</Location>

<IfModule mod_jk.c>
...
JkMount  /jkmanager/* jkstatus
...
</IfModule>

The changes on the "workers.properties" file are:

“workers.properties”文件的更改是:

 worker.list=router,tomcat1,tomcat2,...,tomcatn,jkstatus
 worker.jkstatus.type=status

After these changes are done, you are able to see the jkmanager by typing your url followed by /jkmanager/ at the end. You should get something similar to the following picture.

完成这些更改后,您可以通过键入您的网址,然后输入/ jkmanager /来查看jkmanager。您应该得到类似下图的内容。

jkmanager screenshot http://r2c.images.s3.amazonaws.com/blog/articles/TomcatLoadBalancing/readytocloud-4-20-2009-000.png

jkmanager截图http://r2c.images.s3.amazonaws.com/blog/articles/TomcatLoadBalancing/readytocloud-4-20-2009-000.png

In order to disable workers at run time just run the following URLs against the jkmanger. You can even read status in an xml format.

为了在运行时禁用worker,只需针对jkmanger运行以下URL。您甚至可以以xml格式读取状态。

To disable tomcat1 just hit:

要禁用tomcat1,只需按下:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=1&val1=0&val2=0  

To enable tomcat1 back hit:

要启用tomcat1返回命中:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=0&val1=0&val2=0

I posted a complete article in my blog explaining the setup in case someone needs to know.

我在我的博客中发布了一篇完整的文章,解释了有人需要知道的设置。

Cloud Computing Blog

云计算博客

#3


gkiragiannis, you answer was interesting, but doesn't seem to work for me. I wanted to only disable one of my subworkers at a time.

gkiragiannis,你回答很有意思,但似乎对我不起作用。我想一次只禁用一个我的子工作者。

Lets assume we are working with the 'agent-lb' load balancer.

让我们假设我们正在使用'agent-lb'负载均衡器。

To view the worker status using this url:

要使用此URL查看工作人员状态:

server-name/jkmanager/?cmd=list&w=agent-lb

To disable the 'agent-n1' sub worker use this url:

要禁用'agent-n1'子工作程序,请使用以下URL:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=1

To ensure that the worker is disabled wait for the redirect to the worker status page, and look in the 'Act' field for the sub worker, 'agent-n1'

要确保工作人员被禁用,请等待重定向到工作人员状态页面,并查看子工作人员的“行动”字段,'agent-n1'

To enable the 'agent-n1' sub worker use this url:

要启用'agent-n1'子工作程序,请使用以下URL:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=0

#1


mod_jk re-reads workers.properties on an "apachectl graceful", so you if your workers.properties looks like this:

mod_jk在“apachectl graceful”上重新读取workers.properties,所以如果你的workers.properties看起来像这样:

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2, tomcat3

... 

You could just write a script which replaces the balanced_workers list with the ones you want, and then graceful's apache

你可以写一个脚本,用你想要的那个替换balanced_workers列表,然后是graceful的apache

Update here's a script to do just that, which I cobbled together from some bits I had lying around. I wouldn't suggest using it in production, but it might give you some ideas for your own version.

更新这里是一个脚本来做到这一点,我拼凑了一些我躺在周围的位。我不建议在生产中使用它,但它可能会为您自己的版本提供一些想法。

#!/bin/bash

# set some paths
WORKERS_PROPERTIES="./workers.properties"
APACHECTL="/usr/sbin/apache2ctl"

# what does the loadbalancer config line look like?
WORKER_LINE_START="worker.loadbalancer.balanced_workers="
# full list of workers
ALL_WORKERS="tomcat1 tomcat2 tomcat3"

# first command line arg is the worker to remove. 
remove=$1

# build up the new line listing the active workers
worker_line=$WORKER_LINE_START
sep=""
for worker in $ALL_WORKERS
do
  if [ ${remove} != ${worker} ]
  then
     worker_line="${worker_line}$sep $worker"
     sep=","
  fi
done

# sed hackery to replace the current line with the one we just built.
# needs gnu sed (or another one that supports in-place editing)
sed -i.bak "s/^$WORKER_LINE_START.*$/$worker_line/" $WORKERS_PROPERTIES

# restart apache
$APACHECTL graceful

#2


Chris thanks or your answer. I am sure it will work, but I wanted to trigger the change at run time, even though the graceful restart is very similar. I was able to accomplish my describe task the following way.

克里斯谢谢你的回答。我确信它会工作,但我想在运行时触发更改,即使正常重启非常相似。我能够通过以下方式完成我的描述任务。

In your httpd.conf file you should add the following lines to enable the jkmanager for mod_jk module.

在httpd.conf文件中,您应该添加以下行以启用mod_jk模块的jkmanager。

<Location /jkmanager/>
JkMount jkstatus
order deny,allow
allow from <your ip address>
allow from 127.0.0.1
deny from all
</Location>

<IfModule mod_jk.c>
...
JkMount  /jkmanager/* jkstatus
...
</IfModule>

The changes on the "workers.properties" file are:

“workers.properties”文件的更改是:

 worker.list=router,tomcat1,tomcat2,...,tomcatn,jkstatus
 worker.jkstatus.type=status

After these changes are done, you are able to see the jkmanager by typing your url followed by /jkmanager/ at the end. You should get something similar to the following picture.

完成这些更改后,您可以通过键入您的网址,然后输入/ jkmanager /来查看jkmanager。您应该得到类似下图的内容。

jkmanager screenshot http://r2c.images.s3.amazonaws.com/blog/articles/TomcatLoadBalancing/readytocloud-4-20-2009-000.png

jkmanager截图http://r2c.images.s3.amazonaws.com/blog/articles/TomcatLoadBalancing/readytocloud-4-20-2009-000.png

In order to disable workers at run time just run the following URLs against the jkmanger. You can even read status in an xml format.

为了在运行时禁用worker,只需针对jkmanger运行以下URL。您甚至可以以xml格式读取状态。

To disable tomcat1 just hit:

要禁用tomcat1,只需按下:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=1&val1=0&val2=0  

To enable tomcat1 back hit:

要启用tomcat1返回命中:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=0&val1=0&val2=0

I posted a complete article in my blog explaining the setup in case someone needs to know.

我在我的博客中发布了一篇完整的文章,解释了有人需要知道的设置。

Cloud Computing Blog

云计算博客

#3


gkiragiannis, you answer was interesting, but doesn't seem to work for me. I wanted to only disable one of my subworkers at a time.

gkiragiannis,你回答很有意思,但似乎对我不起作用。我想一次只禁用一个我的子工作者。

Lets assume we are working with the 'agent-lb' load balancer.

让我们假设我们正在使用'agent-lb'负载均衡器。

To view the worker status using this url:

要使用此URL查看工作人员状态:

server-name/jkmanager/?cmd=list&w=agent-lb

To disable the 'agent-n1' sub worker use this url:

要禁用'agent-n1'子工作程序,请使用以下URL:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=1

To ensure that the worker is disabled wait for the redirect to the worker status page, and look in the 'Act' field for the sub worker, 'agent-n1'

要确保工作人员被禁用,请等待重定向到工作人员状态页面,并查看子工作人员的“行动”字段,'agent-n1'

To enable the 'agent-n1' sub worker use this url:

要启用'agent-n1'子工作程序,请使用以下URL:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=0