如何处理数据库崩溃(Glassfish / MySQL)? [英] How to handle database crashes (Glassfish/MySQL)?

查看:202
本文介绍了如何处理数据库崩溃(Glassfish / MySQL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3层应用程序与Glassfish 3.1.2.2,MySQL数据库和一个Swing客户端应用程序。是否可以处理数据库服务器崩溃?



我在应用程序运行期间尝试停止MySQL服务。然后我每次尝试通过我的一个外部会话bean访问数据库时,得到javax.ejb.EJBAccessException异常。



我想通知用户数据库当前下。此外,我想将我的应用程序设置为睡眠模式,直到数据库启动并再次运行。



什么是好的(可能容易)感谢您的帮助!

解决方案

A)确保配置Glassfish连接池以进行自动恢复/重新连接



在Glassfish JDBC连接池配置中,设置值for:




  • 属性: is-connection-validation-required,validate-atmost-once-period-in-秒,connection-creation-retry-attempts,connection-validation-method,connection-creation-retry-interval-in-seconds,ping



Glassfish配置jdbc-connection-pool属性

Glassfish Admin - create-jdbc-connection-pool子命令



步骤:


  1. 假设Glassfish运行(例如启动服务器在Netbeans服务选项卡中,打开服务器并右键单击Glassfish),然后您应该运行域管理服务器

  2. 在Web浏览器中打开管理控制台: http:// localhost:4848 (或使用您在安装期间指定的任何端口。

  3. 在左侧,在常用任务菜单下,打开资源 - > JDBC,然后单击在JDBC连接池上

  4. 单击您的连接池POOL NAME(或通过单击新建按钮创建一个新的按钮)

  5. 选择高级选项卡并输入:

  6. 最多验证:(例如60)(秒)

  7. 创建重试尝试(例如3)

  8. 重试间隔:(例如10)以秒为单位

  9. 连接验证:(Tick)必需

  10. 验证方法:(例如自动提交)

  11. 其他要求的高级属性

  12. 选择常规选项卡并输入:

  13. Ping(Tick) / li>
  14. 其他希望的一般属性

B)实施应用程序错误处理/数据库监控&警报


  1. 强制性:陷阱基础架构级的致命用户错误和警报支持人员。



    创建一个简单的JMX类来发送通知&在发生致命错误时调用其方法
    发送的JMX MBean类通知的。您可以使用JMX监视器控制台观察服务器的状态 - 其中一些控制台发送电子邮件警报(例如JManage和RHQ),并且有从HTTP / AJAX或其他语言访问的桥梁(例如 Jolokia 可以使用javascript / perl / java API来访问JMX通知)。



    使用 Google Calendar API 发送错误msg以支持员工的Google日历(将来1或2分钟)。然后配置谷歌日历发送电子邮件/短信通知 - 将提供错误警报直接支持员工近实时。这受到Google使用限制(每天允许10,000次查询的限制,因此请确保您的应用程序不是超级错误,并使用逻辑来限制每小时/天/周发送的邮件数量)


  2. 期望:监控数据库(&可能的应用服务器)和警报支持人员的中断




    • Zabbix开源已经建立了mySQL监视和警报 - 是轻量级的,但需要安装&配置

    • Hyperic开源具有mySQL监控和内置警报的扩展插件 - 重量级,可以复杂的设置和配置

    • Nagois开源是* nix操作系统的默认设置 - 重量很大,可以复杂设置和配置



    在所有情况下,安装程序不会立即发生 - 最佳实现为独立的迷你项目&如果这些超出范围,则创建自己的简单监视器:




    • 一个EJB计时器,用于对您的数据库运行安排的简单测试查询 - 如果发送失败,则发送警报(通过JMX / Google Calendar / Java Mail / SMS网关API)。或者使用Quartz开源调度程序来做同样的工作



I have a 3-tiered application with Glassfish 3.1.2.2, MySQL database and a Swing client application. Is it somehow possible to handle a database server crash?

I tried to stop the MySQL service during my application is running. Then I get javax.ejb.EJBAccessException exceptions everytime I try to access the database through one of my facade session beans.

I want to notify the user that the database is currently down. furthermore i want to set my application in kind of a "sleep-mode" until the database is up and running again.

What would be a good (and possibly easy) approach to handle such a scenario?

Thanks for your help in advance!

解决方案

A) Ensure you configure Glassfish Connection Pool for automatic recovery/reconnection

In the Glassfish JDBC connection pool configuration, set the values for:

  • Attributes: is-connection-validation-required, validate-atmost-once-period-in-seconds, connection-creation-retry-attempts, connection-validation-method, connection-creation-retry-interval-in-seconds, ping

Glassfish Configuration jdbc-connection-pool Properties
Glassfish Admin - create-jdbc-connection-pool subcommand

Steps:

  1. Assuming Glassfish is running (e.g. start server in Netbeans Services Tab, by opening Servers and right-clicking Glassfish), then you should have the Domain Admin Server running
  2. Open Admin Console in web browser: http://localhost:4848 (or use whatever port you specified during install.
  3. On left, under Common Tasks menu, open Resources -> JDBC and click on JDBC Connection Pools
  4. Click on your connection pool POOL NAME (or create a new one by clicking New button)
  5. Select Advanced Tab & Enter:
  6. Validate At Most Once: (e.g. 60) in seconds
  7. Creation Retry Attempts: (e.g. 3)
  8. Retry Interval: (e.g. 10) in seconds
  9. Connection Validation: (Tick) Required
  10. Validation Method: (e.g. auto-commit)
  11. Other Advanced Properties as Desired
  12. Select General Tab & Enter:
  13. Ping (Tick)
  14. Other General Properties as Desired

B) Implement Application Error Handling / DB Monitoring & Alerts

  1. Mandatory: trap "infrastructure-level" fatal user errors and alert support staff.

    Create a simple JMX class to send a notification & call its method when a fatal error occurs JMX MBean Class which sends notifications. You can use a JMX monitor console to observe state of servers - some of these consoles send email alerts (e.g. JManage and RHQ) and there are bridges for access from HTTP/AJax or other languages (e.g. Jolokia can use javascript/perl/java API to access JMX notifications).

    Use Google Calendar API to send the error msg to support staff's google calendar (1 or 2 mins into future). Then configure google calendar to send email/sms notifications - will give error alert straight to support staff in near-realtime. This is subject to Google usage restrictions (a courtesy limit of 10,000 queries per day, so make sure your apps not super buggy and use logic to limit the number of messages sent in an hour/day/week)

  2. Desirable: monitor DB (& probably app server) and alert support staff of outages

    • Zabbix open source has inbuilt mySQL monitoring and alerting - is lightweight but requires setup & configuration
    • Hyperic open source has extension plug-ins for mySQL monitoring and inbuilt alerting - is heavy-weight, can be complex to setup & configure
    • Nagois open source is the default for *nix OSes - is heavy weight, can be complex to setup and configure

    In all cases, setup will not happen instantly - best to implement as a separate mini project & do it right - best to have support staff involved in this.

    If these are "out of scope", then create your own simple monitor:

    • An EJB timer to run scheduled simple test query against your DB - if it fails send an alert (via JMX/Google Calendar/Java Mail/ SMS gateway API). Or use Quartz open source scheduler to do the same job

这篇关于如何处理数据库崩溃(Glassfish / MySQL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆