2

我相信这个任务没有太大的异国情调,但由于缺乏集群经验,我觉得很难找到答案。
我们的网络应用程序按计划执行一些后台操作(数据查询和传输)。现在,运行它的 Tomcat 服务器已集群化。我们只需要集群中的一个实例来执行这些后台操作,而不是全部。
我看到以下选项:

  • 理想的解决方案是集群的主/从模型,其中 Tomcat 的从属实例使我们的应用程序处于非活动状态(未部署)。如果从机成为主机,应用程序将被部署并开始工作。可能吗 ?

  • 如果没有,那么我们需要一些可以实现监听器的通知/事件,以便知道某个节点何时启动/关闭。然后,我们将以编程方式使第一个提升节点中的应用程序成为主节点,并阻止其他(从)节点中不需要的进程。此外,我们将监听来自节点的启动/关闭事件,以始终保持一个活动的主节点。我一直在 Tomcat 中寻找这样的事件 API,但到目前为止还没有运气。

有没有人有这样的任务经验?你是怎么解决的?
谢谢你。

4

1 回答 1

0

I don't know if there is a master/slave behavior setting in a Tomcat cluster, because I think all nodes need to be equal. But what about using the Quartz Clustering with JDBC-JobStore? You can define the tasks within a shared database and if a task is triggered, the first available node will execute it. So all nodes in your cluster will have the same behavior while only a singe node will execute the same task at a time:

"Only one node will fire the job for each firing. ... It won't necessarily be the same node each time - it will more or less be random which node runs it. The load balancing mechanism is near-random for busy schedulers (lots of triggers) but favors the same node for non-busy (e.g. few triggers) schedulers."

If a node fails while executing a task the next available node will retry:

"Fail-over occurs when one of the nodes fails while in the midst of executing one or more jobs. When a node fails, the other nodes detect the condition and identify the jobs in the database that were in progress within the failed node."

于 2013-05-31T16:05:26.077 回答