查看当前访问日志
1 | tail -f /logs/access.log |
查看某个IP的访问日志
1 | tail -f /logs/access.log | grep 127.0.0.1 |
查看HTTP返回状态为502的日志
1 | tail -f /logs/access.log | grep 'HTTP/1.1" 502' |
查看当前错误日志
1 | tail -f /logs/error.log |
查看error.log里面的error级别信息
1 | tail -f /logs/error.log | grep error |
查看当前nginx配置文件
1 | vi nginx/conf/nginx.conf |
查看当前某个网站的配置信息
1 | vi nginx/conf/sites-enabled/www.abc.com |
查看当前modsecurity的配置文件
1 | vi nginx/conf/modsecurity.conf |
重启nginx程序
1 | nginx/sbin/nginx -s reload # 重新加载配置文件 |
或者执行
1 | nginx/sbin/nginx -s stop # 停止nginx |
或者执行
1 | killall nginx # 一直执行killall,直到提示 nginx: no process found |
统计某段时间内,访问的IP、网站
1、比如我要查看16:55~16:59之内的所有记录,其中$2是填写时,$3是填写分
1 | awk -F':' '{if($2 == 16 && $3 >= 55 && $3 <= 59){print $0}}' /logs/access.log |
这样就可以得出我们想要的记录了,如果想统计个数,在加个 wc -l。
然后比如我要统计这段时间内,IP的访问次数
1 | awk -F':' '{if($2 == 16 && $3 >= 55 && $3 <= 59){print $0}}' /logs/access.log | awk '{a[$2]+=1;}END{for(i in a){print a[i]" " i;}}' | sort -g |
然后比如我要统计这段时间内,网站的请求次数(1个网站可能有多个请求)
1 | awk -F':' '{if($2 == 16 && $3 >= 55 && $3 <= 59){print $0}}' /logs/access.log | awk '{a[$1]+=1;}END{for(i in a){print a[i]" " i;}}' | sort -g |
然后比如我要统计这段时间内,指定网站的IP的请求次数
1 | awk -F':' '{if($2 == 16 && $3 >= 0 && $3 <= 59){print $0}}' /logs/access.log | awk '{if($1=="www.gbiac.net"){a[$2]+=1;}} END{for(i in a){print a[i]" " i;}}' | sort -g |
然后比如我要统计出现502的次数
统计访问日志中相同IP的访问次数
1 | awk '{a[$2]+=1;}END{for(i in a){print a[i]" " i;}}' /logs/access.log | sort -g |
统计所有访问的状态码
1 | awk '{print $10}' access.log |sort |uniq -c |
统计某个网站某天的访问日志中相同IP的访问次数
1 | cd /data/syslog/logs/access/www.gbiac.net\ /201702/ |
1 | awk '{print $10}' testmobile.log | sort | uniq -c |
Linux 系统
查看系统性能状态的命令
1 | top |
查看内存使用情况(默认是KB为单位,-m指定为MB为单位,-g指定为GB为单位)
1 | free |
查看磁盘的使用情况
1 | df -h |
查看网络流量
1 | nload |
查看网络连接
1 | netstat -anp |
查看当前TCP连接的状态和对应的连接数量
1 | netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' |
查看查看当前目录总共占的容量,而不单独列出各子项占用的容量
1 | du -sh |
查看当前目录下一级子文件和子目录占用的磁盘容量
1 | du -lh --max-depth=1 |
查找文件
1 | find / -name abc.txt |
查找大小超过1G的文件
1 | find / -type f -size +1G |
查找文件夹是否包含某个名字为abc的文件
1 | grep -R * abc |
网站查询
使用traceroute追踪地址
1 | traceroute -m 60 210.76.70.128 # -m |
指定跳数
查询网站DNS记录
1 | dig www.baidu.com |
1 | nslookup www.baidu.com |
查询域名的注册信息
1 | whois baidu.com |
查看网站服务器是否正常提供http服务
1 | telnet 114.114.114.114 80 |
如果连接上了,可以发送http请求
1 | GET/ HTTP/1.0 |
查看https的网站
1 | openssl s_client -connect www.duocai100.com:443 -CApath /etc/ca-certificates |
连接上了可以发送https请求
1 | GET / HTTP/1.1 |
(需要首先安装CA证书 apt-get install ca-certificates)