gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:59:00 26 4
gpt4 key购买 nike

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

我们想要配置一个脚本或一种程序来禁用正在经历回收的工作节点,以最大限度地减少用户使用我们的应用程序时的 session 错误。

任何建议。

最佳答案

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

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

...

您可以编写一个脚本,将 balanced_workers 列表替换为您想要的列表,然后是 graceful 的 apache

更新 这是一个用于执行此操作的脚本,它是我从周围的一些位中拼凑而成的。我不建议在生产中使用它,但它可能会给你一些关于你自己的版本的想法。

#!/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

关于java - 如何以编程方式调整 mod_jk 负载均衡器配置中的禁用指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/766891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com