監控MYSQL服務是否異常

來源:互聯網
上載者:User

標籤:mysql   監控   服務   

問題描述:監控MYSQL服務是否正常啟動,如果未正常啟動,就啟動MYSQL

判斷mysql的方法:

1)連接埠判斷

[[email protected] ~]# netstat -lntup | grep 3306tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2288/mysqld

2)進程判斷

[[email protected] ~]# ps -ef | grep mysqld      mysql     2071     1  0 11:32 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usrmysql     2288  2071  0 11:32 ?        00:00:24 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sockroot     10097  6962  0 17:27 pts/1    00:00:00 grep --color=auto mysqld

3)傳回值判斷

[[email protected] ~]# mysql -uroot -proot -e "select version();" &>/dev/null [[email protected] ~]# echo $?0

法一:實現思路是過濾出MYSQL連接埠3306進行判斷:

#!/bin/bashport=`netstat -lnt|grep 3306|wc-l`if [ $port -ne 1 ]then  /etc/init.d/mysql startelse    echo "MySQL is running."fi執行結果:[[email protected] ~]# sh mysql1.sh  MySQL is running.


法二:實現思路是通過MYSQL進程進行判斷:

#!/bin/bashportcess=`ps -ef|grep mysql|grep -v grep|wc -l`if [ $portcess -ne 2 ]then  /etc/init.d/mysqld startelse  echo "MySQL is running."fi執行結果:[[email protected] ~]# sh mysql1.sh  MySQL is running.注意:過濾的字串‘mysql’不要在指令碼名字出現,如果出現則不準

法三:實現思路是通過web串連傳回值判斷:

#!/bin/bashmysql -uroot -proot -e "select version();" &>/dev/nullif [ $? -ne 0 ]then  /etc/init.d/mysqld startelse  echo "MySQL is running."fi執行結果:[[email protected] ~]# sh mysql1.sh  MySQL is running.


小結:web服務監控手段:

  1. 連接埠(本地或者遠程)

  2. 本地進程

  3. header(httpd code)

  4. URL(wget,curl

本文出自 “小菜鳥” 部落格,請務必保留此出處http://baishuchao.blog.51cto.com/12918589/1942148

監控MYSQL服務是否異常

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.