巧用Nagios指令碼監控Oracle串連

來源:互聯網
上載者:User

情境:

程式修改完成後,上傳到應用伺服器tomcat,重啟tomcat後,發現啟動異常!前端nginx負載平衡出現504錯誤,網站無法開啟!

排查:

經過排查tomcat日誌,發現串連資料庫異常;登陸資料庫後以"conn /as sysdba"方式登陸正常,資料庫輕載,無壓力;於是檢查資料庫的監聽器,輸入"lsntctl services"命令,卡住,半天不出結果…

故障處理:

輸入"lsntctl stop" 或者"lsntctl reload"命令,卡住,半天不出結果,於是輸入service network restart命令,一樣沒有效果!於是出必殺技,輸入"netstat -ntpl|grep :1521"命令找出監聽器的進程號,kill -9結束掉,然後重啟監聽器,再啟動tomcat正常,網站訪問暢通無阻!

原因分析:

可能由於資料庫bug的原因,出現監聽器卡住的情況,導致資料庫連接失敗!參見:

後期維護:

為了盡量避免這種問題,想到去寫一個監控指令碼配合nagios監控,當資料庫連接異常的時候,可以第一時間收到警示簡訊;java程式串連資料庫使用串連池,所以不一定會及時暴露出問題!

寫一個指令碼放任務計劃中運行,定期去串連下資料庫,查詢下系統時間和資料庫的狀態,spool輸出到臨時檔案上

  1. [root@server199 ~]# crontab -l  
  2. */5  *    *             *  *  /usr/local/nagios/libexec/connect_Oracle.sh  
  3. [root@server199 ~]# cat /usr/local/nagios/libexec/connect_oracle.sh
    #!/bin/sh
    #functions: connect oracle server test
    #author:lw.yang
    #modify_date: 2012-02-22
  4. rm -rf /tmp/check_oracle.log
    export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1/
    $ORACLE_HOME/bin/sqlplus username/password@ip:1521/services_name <<EOF
    set echo off
    set feedback off
    spool /tmp/check_oracle.log
    alter session set nls_date_format='YYYY-MM-DD:HH24:MI:SS';
    select sysdate from dual;
    select name,open_mode from v\$database;
    spool off
    set echo on
    set feedback on
    EOF
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.