Whether MySQL and nginx services are properly monitored scripts

Source: Internet
Author: User

A. Monitor Web server and MySQL methods

1. monitoring port (nginx is same )

1.1 Local monitoring

Netstat-tunlp|grep 3306|wc-l

Ss-tunlp|grep 3306|wc-l

1.2 Remote Monitoring

Nmap 10.117.33.98-p 3306|grep open|wc-l

Echo-e "\ n" |telnet 10.117.33.98 3306 2>/dev/null |grep connected|wc-l

2. monitoring process (nginx )

Ps-ef |grep mysql|grep-v grep|wc-l

3.wget,Curl

wget--spider--timeout=10--tries=2 www.baidu.com &>/dev/null

echo $? a return value of 0 indicates success or failure

Note:--spider simulated crawl,--timeout timeout time --tries test two times

Wget-t 10-q--spider http://www.baidu.com &>/dev/null

echo $? a return value of 0 indicates success or failure

Note:-T timeout time - q Quiet mode, this method is the same as above


curl-s-o/dev/null http://www.baidu.com

echo $? a return value of 0 indicates success or failure

Note:-S Quiet mode - o redirection

two. Examples of monitoring scripts

1. monitor mysql startup example:

[email protected] ~]# cat testmysql.sh

#!/sbin/bash

#if [' netstat-tunlpa|grep mysqld|wc-l '-gt 0] Local monitoring

[' Rpm-qa nmap|wc-l '-lt 1] && yum install-y nmap &>/dev/null Remote Monitoring

if [' Nmap 10.117.33.130-p 3306|grep open|wc-l '-gt 0] Remote Monitoring

Then

echo "MySQL is running!"

Else

echo "MySQL is stoped"

# /etc/init.d/mysqld Start Local Boot

Fi

2. monitor mysql connection is normal

Cat testmysql.php writing a php connection script

<?php

$link _id=mysql_connect (' localhost ', ' root ', ' Oldboy ') or mysql_error ();

if ($link _id) {

echo "MySQL successful by Oldboy ! ";

}

else{

Echo Mysql_error ();

}

?>

PHP testmysql.php execute the script, but make sure that PHP is installed

MySQL Successful by oldboy! through grep Filter Out Keywords

3. Monitor The nginx server through the port is normal

[email protected] ~]# cat testnginx.sh

#!/sbin/bash

#if [' netstat-tunlpa|grep nginx|wc-l '-gt 0] Local

[' Rpm-qa nmap|wc-l '-lt 1] && yum install-y nmap &>/dev/null Remote

if [' Nmap 10.117.33.130-p 80|grep open|wc-l '-gt 0] Remote

Then

echo "Nginx is running!"

Else

echo "Nginx is stoped"

Fi

4. using Curl to monitor The Nginx server is normal

[email protected] ~]# cat curlnginx.sh

#!/sbin/bash

If [' Curl-i http://10.117.33.130 2>/dev/null |head-1|egrep ' 200|302|301 ' |wc-l '-eq 1]

Then

echo "Nginx is running!"

Else

echo "Nginx is stoped!"

Fi


This article is from the "Feng" blog, make sure to keep this source http://fengxiaoli.blog.51cto.com/12104465/1949514

Whether MySQL and nginx services are properly monitored scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.