I am considering using an architecture with just one server which will be Tomcat (as opposed to Apache with Tomcat).
If Tomcat goes down or gets out of memory, what can I do to?
- Alert me of this in the fastest way?
- Make sure there is still some professional looking page when users try to access t开发者_开发百科he application
- If possible, give myself some period of time to fix what happened without the users finding out?
To check the service availability I recommend you to use Nagios.
Nagios have plugins that constantly checks for the state of the configured services, and emit alerts if there is a service interruption. Alerts could be sms, mails etc.
- Regarding monitoring I agree with the other poster's suggestion of Nagios. However, Hyperic is a much more sophisticated solution to monitor Java programs, it comes preconfigured for Tomcat (look here) and hundreds of other programs so it's definitely worth a look. Hyperic can also mail you before the server OOMs, by monitoring the memory pools by the way.
- For 2 and 3 I'd put a reverse proxy/load balancer in front of several instances of Tomcat with your application (see clustering). Have a look at Pound for a nice, lightweight solution that can also do https wrapping, sticky sessions and more.
If Tomcat is the only thing on the server that is handling HTTP requests (which your question seems to indicate) then you won't be able to show a page -- what would serve up the page?
I suppose you could write some sort of watchdog program that could periodically hit a URL on the Tomcat server and if it doesn't get a response do a number of things:
- Send you an email.
- Fire up a simple server that only serves static HTML
- Restarts tomcat
And of course you could use an external monitoring facility to check if Tomcat is alive and alert you if it is not.
To serve a page a server must be running. So the typical solution is to load balance in some way. You can use dedicated load balancers, or software load balancing. Either way, the idea is that the load balancer keeps track of your servers and forwards users appropriately. In the case you describe, the balancer would not send users to the "down" server. It would send users to the remaining available servers in the cluster. If all of the servers in your cluster are offline, the balancer would send the users to a "hot spare" that would be serving out your "unavailable" page.
Tomcat >=5.5 has support for basic load balancing, called "clustering." You can read about it elsewhere. But it wouldn't get you the hot spare functionality. A popular software solution is Nginx. Personally, I would prefer to use Lighttpd as a software balancer, but it doesn't support sticky sessions (yet).
精彩评论