企业oa系统搭建潍坊关键词优化排名
参考我的博客文章《Centos安装nginx》,先来安装下nginx。我按照该文档操作了一遍,还是很快就能安装好nginx的。
确认可以安装成功:
[root@vm1 sbin]# netstat -atunlp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 21573/nginx: master[root@vm1 html]# echo changchunhua > index.html
[root@vm1 html]#
[root@vm1 html]# curl http://localhost
changchunhua
1、端口
本地:netstat ss lsof
[root@vm1 scripts]# netstat -atunlp |grep -w 80 |wc -l
1
[root@vm1 scripts]# netstat -lntup |grep nginx | wc -l
1[root@vm1 scripts]# ss -atunlp |grep -w 80 | wc -l
1
[root@vm1 scripts]# ss -atunlp |grep nginx | wc -l
1[root@vm1 scripts]# lsof -i tcp:80 | wc -l
3
远程:telnet nmap nc
[root@vm1 scripts]# nmap localhost -p 80Starting Nmap 6.40 ( http://nmap.org ) at 2023-08-02 00:17 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000040s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT STATE SERVICE
80/tcp open httpNmap done: 1 IP address (1 host up) scanned in 0.23 seconds
[root@vm1 scripts]# nmap 127.0.0.1 -p 80 |grep open | wc -l
1
[root@vm1 scripts]# echo -e "\n" | telnet 127.0.0.1 80 2>/dev/null
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
[root@vm1 scripts]# echo -e "\n" | telnet 127.0.0.1 80 2>/dev/null |grep Connected | wc -l
1
[root@vm1 scripts]# nc -z -v 127.0.0.1 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:80.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.[root@vm1 scripts]# nc -z -v 127.0.0.1 80 &>/dev/null
[root@vm1 scripts]# echo $?
0
2、本地进程数:
[root@vm1 scripts]# ps -ef |grep nginx |grep -v grep
root 21573 1 0 00:01 ? 00:00:00 nginx: master process ./nginx
nobody 21574 21573 0 00:01 ? 00:00:00 nginx: worker process
[root@vm1 scripts]# ps -ef |grep nginx |grep -v grep | wc -l
2
3、header(http code) curl -I
4、URL(wget curl)
客户端模拟用户访问的监控方式,先通过wget和curl命令进行测试,执行wget和curl命令之后,再看返回值$?,为0,则为成功。
[root@vm1 scripts]# wget --spider --timeout=10 --tries=2 http://127.0.0.1 &>/dev/null
[root@vm1 scripts]# echo $?
0
获取字符串的方式:
[root@vm1 scripts]# curl http://127.0.0.1
changchunhua
根据HTTP响应header的结果进行判断:
[root@vm1 scripts]# curl -I -s -w "%{http_code}\n" -o /dev/null http://127.0.0.1
200
然后我们可以写出脚本:
示例1:
[root@vm1 scripts]# cat nginx_monitor1.sh
#!/bin/bash
#if [ `netstat -auntlp |grep nginx | wc -l` -gt 0 ]thenecho "nginx is running."
elseecho "Nginx is stopped."/usr/local/nginx/sbin/nginx
fi
[root@vm1 scripts]# sh nginx_monitor1.sh
nginx is running.
[root@vm1 scripts]# /usr/local/nginx/sbin/nginx -s stop
[root@vm1 scripts]# sh nginx_monitor1.sh
Nginx is stopped.
[root@vm1 scripts]# sh nginx_monitor1.sh
nginx is running.
[root@vm1 scripts]#
示例2:
[root@vm1 scripts]# cat nginx_monitor2.sh
#!/bin/bash
#if [ `lsof -i:80 | wc -l` -gt 0 ]thenecho "nginx is running."
elseecho "Nginx is stopped."/usr/local/nginx/sbin/nginx
fi[root@vm1 scripts]# sh nginx_monitor2.sh
nginx is running.
[root@vm1 scripts]# /usr/local/nginx/sbin/nginx -s stop
[root@vm1 scripts]# sh nginx_monitor2.sh
Nginx is stopped.
[root@vm1 scripts]# sh nginx_monitor2.sh
nginx is running.
[root@vm1 scripts]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 21771 root 6u IPv4 37072 0t0 TCP *:http (LISTEN)
nginx 21772 nobody 6u IPv4 37072 0t0 TCP *:http (LISTEN)
示例3:
[root@vm1 scripts]# cat nginx_monitor3.sh
#!/bin/bash
#if [ `ps -ef |grep nginx | grep -v grep | wc -l` -gt 2 ]thenecho "nginx is running."
elseecho "Nginx is stopped."/usr/local/nginx/sbin/nginx
fi
说明:
1)为什么要进程数要大于2呢?
在调试的过程中只有改成-gt 2才能启动nginx。过滤进程方式,排除自身。