温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

shell监控web服务的多种方案

发布时间:2020-08-01 14:44:28 来源:网络 阅读:234 作者:baishuchao 栏目:开发技术

1.端口

本地:ss.netstat,lsof

远程:telnet,nmap.nc

2.本地进程数

3.header(http,curl),模拟用户的方式

4.URL(wget,curl).模拟用户的方式

5.php,java写监控的程序,模拟用户的方式(让开发提供)



范例判断条件

[root@XCN ~]# lsof -i :80|wc -l    #本地端口  
2
[root@XCN ~]# nmap 127.0.0.1 -p 80    #远程端口

Starting Nmap 5.51 ( http://nmap.org ) at 2017-06-28 14:13 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000080s latency).
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
[root@XCN ~]# nmap 127.0.0.1 -p 80|wc -l
8
[root@XCN ~]# nmap 127.0.0.1 -p 80|grep open|wc -l  
1
[root@XCN ~]# ps -ef|grep nginx |wc -l    #进程
12
[root@XCN ~]# culr -I -s -w "%{http_code}" -o /dev/null 127.0.0.1
200      #curl
[root@XCN ~]# wget --spider --timeout=10 --tries=2 127.0.0.1 &>/dev/null
[root@XCN ~]# echo $?     #wget看返回值
0

案例shell

#!/bin/bash
http_code=`culr -I -s -w "%{http_code}" -o /dev/null 127.0.0.1`
if [ $http_code -ne 200 ]
then
  echo "web is erro"
else
  echo "web is ok"
fi

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI