Java高可用框架
我正在编写一个小型代理应用程序,该应用程序应该是冗余的,例如主代理将在一台服务器上运行,而冗余代理将在另一台服务器上运行。是否有一个简单的高可用性框架可以用来实现这种冗余?例如,此 HA 框架会在实例之间发送 ping,并在第一个实例出现故障时在另一个实例上引发某种异常或通知。
I am writing a small proxy application which should be redundant, e.g. primary proxy will be running on one server and the redundant one will run on a separate server. Is there a simple high-availability framework which I can use to implement this redundancy? For example, this HA framework would send pings between instances and raise some sort of exception or notification on the other instance when the first one goes down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
建立这样一个系统是我近年来的日常工作。我找到了 jgroups
一个非常有用的工具来接收和处理此类分组事件。如果您想构建自己的 HA 基础设施,就是这种情况。我不知道,但也许在您的情况下,只需一个简单的反向代理(例如 HAProxy)就足够了。
Building such a system has been my routine job in recent years. I have found jgroups
a very usable tools to receive and handle such kind of grouping events. This is the case if you want to build your own HA infrastructure. I don't know, but maybe in your case just a simple reverse proxy such as HAProxy can be enough.
如果您想要轻松实现 HA,只需使用一些具有 HA 功能的负载均衡器,例如 Ultramonkey、LVS 与 keepalived 等。
在 HA 配置中,您通常希望使用虚拟 IP,因此即使您将此 ping/通知功能作为框架,您仍然需要做一些事情(开始响应对虚拟 IP(一旦其他实例失败)。因此,除非您正在寻找学习机会,否则我建议您使用中间件,而不是使用框架自己编写代码。
您可以为这些中间件配置多种运行状况检查。例如,简单的运行状况检查可能会向您的应用程序发出 GET 请求。定期并在响应中查找特定字符串(例如“XXX running。”)以确保您的应用程序。运行良好。
If you want HA without hassle, just use some load balancer with HA capability e.g. Ultramonkey, LVS with keepalived etc.
In a HA configuration, you'd typically want to use virtual IP, so even if you'd have this ping/notify functionality as a framework, you'll still have stuff to do (start responding to requests to the virtual IP once the other instance has failed). So unless you are looking for a learning occasion, I'd advice using a middleware instead of coding this yourself using frameworks.
There are number of health-checks that you can configure for these middlewares. A simple healthcheck might for example, fire a GET request to your app. periodically and look for a specific string (e.g. "XXX running.") in the response to make sure your app. is running fine.
您没有提供有关应用程序所做工作的太多详细信息,因此取决于它的状态如何,是否可以容忍轻微的数据丢失,是否对时间至关重要,您是否重视开发人员时间而不是机器时间,您可以有不同的范围的解决方案。
上面有一些很好的建议,我想补充一下:看看 JMS 和持久消息传递。通常,这些使恢复变得非常简单,但代价是延迟(除非您使用商业产品并很好地学习它或付费给供应商来调整您的应用程序)。使用 JMS 队列,您可以实现主动-主动处理,并免去故障检测的麻烦。
另一个值得关注的方向是分布式状态管理/集群框架,如 Gigaspaces、Coherence、Gemstone、Infinispan、Gridgain 和 Teracotta。这些可以复制您的数据并保证不同的服务质量水平。它们大多数都带有某种类型的故障检测和分布式管理机制。
You don't provide much details about the work your application does, so depending on how stateful it is, whether it can tolerate minor dataloss, is it time-critical, do you value developer time over machine time, you can have a varying spectrum of solutions.
There are some good suggestions above, I'd add: take a look at JMS and persistent messaging. Usually these make recovery quite trivial, but at the cost of latency hit (unless you byu a commercial product and learn it well or pay the vendor to tune your application). With JMS queues you can implement active-active processing and save yourself the headache of failure detection.
Another direction to look at is distributed state management/clustering framework like Gigaspaces, Coherence, Gemstone, Infinispan, Gridgain and Teracotta. These can replicate your data and guarantee varying quality of services levels. Most of them come with some type of failure detection and distributed management mechanism.
hadoop 是一个很好的起点
hadoop is a good place to start