Several ways to determine if MySQL is normal
#################################
Method 1: Look at the port
Netstat-lntup|grep 3306|wc-l
Lsof-i: 3306 |wc-l
Remote:
/telnet/nc/nmap
#################################
Method 2: See the process
Ps-ef |grep Mysqld|wc-l
#################################
Method 3: Go to MySQL to see the version
[Email protected] ~]# mysql-uroot-e "select version ();"
+-----------+
| Version () |
+-----------+
| 5.1.72 |
+-----------+
[[email protected] ~]# echo $?
0
[Email protected] ~]#
MYSQL-UROOT-E "select version (); &>1 >>/dev/null; echo $?
#################################
Method 4: Let the development write Java or PHP and other programs to monitor
#################################
Method 5: Use the combination of the monitoring methods above 4
######################################
######################################
Script 1
[email protected] script]# cat mysqlif.sh
#!/bin/sh
port= ' Netstat-lnt|grep 3306|wc-l '
If [$port-ne 1]
Then
echo "MySQL isn ' t running."
/etc/init.d/mysqld start
echo "MySQL is running."
Else
echo "MySQL is running."
Fi
[Email protected] script]#
######################################
######################################
Script 2
[email protected] script]# cat mysqlif.sh
#!/bin/sh
#port = ' Netstat-lnt|grep 3306|wc-l '
Proc= ' Ps-ef |grep mysqld|grep-v grep |wc-l '
If [$proc-lt 1]
Then
echo "MySQL isn ' t running."
/etc/init.d/mysqld start
echo "MySQL is running."
Else
echo "MySQL is running."
Fi
[Email protected] script]#
######################################
######################################
Script 3 Recommended methods
[email protected] script]# cat mysqlif.sh
#!/bin/sh
#port = ' Netstat-lnt|grep 3306|wc-l '
#proc = ' Ps-ef |grep mysqld|grep-v grep |wc-l '
MYSQL-UROOT-E "select version (); &>1 >>/dev/null
#mysql-uroot-ppassword-e "select version (); &>1 >>/dev/null
Num= ' echo $? '
If [$num-ne 0]
Then
echo "MySQL isn ' t running."
/etc/init.d/mysqld start
echo "MySQL is running."
Else
echo "MySQL is running."
Fi
[Email protected] script]#
######################################
######################################
Script 4
[email protected] script]# cat mysqlif.sh
#!/bin/sh
Pidfile=/application/mysql5.1.72/data/lamp.pid
Mysql_path=/application/mysql5.1.72/bin
Datadir=/application/mysql5.1.72/data
if [!-F $pidfile]
Then
$mysql _path/mysqld_safe--datadir= $datadir--pid-file= $pidfile & 2>&1/dev/null
Else
echo "MySQL is running."
Fi
[Email protected] script]#
#################### ###############
Monitoring other services can refer to the above several monitoring methods
Means of monitoring Web services
1. Local: ss, Netstat, lsof
Remote: Telnet, Nmap, NC
2. Number of local processes
Ps-ef |grep XXX
3.curl-s-I see if the return value is 200
Wget
This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1701047
Multiple ways to monitor MySQL