命令行
连通性
curl ip.cn
curl ipinfo.io
curl -s attacker.club/getip #查看出口ip
ping 114.114.114.114 |awk '{print $0"\t" strftime("%H:%M:%S",systime())}'
# 连续ping检测
系统基础命令
top --> m #内存
top --> 1 #cpu
top -Hp pid # 看具体线程负载
pstree -ap # 查看详细进程列表
uptime --> #负载
dstat -ndy --top-mem
dstat -ndy --top-cpu
dstat -ndy --top-io
dstat -ndy --top-mem --top-cpu --top-io -t
#查看关键性能io
system:int、csw
系统级IO监控
iostat -xdm1
# %util代表磁盘繁忙程度。100% 表示磁盘繁忙, 0%表示磁盘空闲
# argrq-sz 提交给驱动层的IO请求大小,一般不小于4K,可判断io模式越大代表顺序,越小代表随机
进程级IO监控
iotop
pidstat -d 1
# 展示I/O统计,每秒更新一次( sysstat rpm包)
网站页面响应
curl -o /dev/null -s -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total} http://www.baidu.com
# 0.004:0.031:0.269:0.269
# 解析 建立连接 传输 总
系统并发连接查看
netstat -an | awk '/^tcp/ {print $6}'|sort |uniq -c|sort -n
ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}'
#查看当前TCP连接状态;ss更快
ss -an|awk '{print $5}'|awk -F: '{print $1}'|sort|egrep -o '[0-9]{1,3}(\.[0-9]{1,3}){3}'|uniq -c|sort -nr|head -n 10
#查看并发最多的独立IP,取其前10个;sort排序 参数nr中n是按照排序大小,r是反向排序。uniq -c计数显示
netstat -n|grep TIME_WAIT|awk '{print $5}'|awk -F: '{print $1}' |sort|uniq -c|sort -rn|head -n5
#查看后端TIME_WAIT主机
tail -1000 /var/log/httpd/access_log |awk '{print $NF}'|sort |uniq -c|sort -n
#sort -k1n,k1是第一列;列出1000行域名出现次数
web访问统计
watch 'netstat -an | egrep -w "80|443"|grep ESTABLISHED |wc -l'
# 服务并发连接
awk '$4 >="[04/Apr/2017:12:25:00" && $4 <="[04/Apr/2017:12:26:00"' blog.log
#过滤第四列的项,输出大于等于25分,小于等于26分的访问日志
故障定位
网络抓包
tcpdump -n host [目标IP]
# -n 是显示IP和端口,也就是不解析主机名
tcpdump -i eth0 host 43.225.180.226 tcp port 8888 -vv -c 3 -w result.pcap #-vv 屏幕显示 -c 抓包次数 -w 写入数据到本地
tcpdump -Z root -r src.pcap "tcp port 22 and (tcp[tcpflags] & tcp-fin != 0)" -w dst.pcap #过滤出端口为22, 且含有 FIN 标记的数据包
tcpdump -i eth0 -s 0 -l -w out.log port 3306 | strings #在数据库服务器是通过tcpdump抓sql语句
OOM
全称“Out Of Memory”;内存用完了
内存泄露:申请使用完的内存没有释放,导致虚拟机不能再次使用该内存,此时这段内存就泄露了,因为申请者不用了,而又不能被虚拟机分配给别人用。
内存溢出:申请的内存超出了JVM能提供的内存大小,此时称之为溢出。
grep "Out of memory" /var/log/messages
grep -ir 'killed process' /var/log
dmesg |grep "Out of memory"
jmap -heap java_pid #java查看资源使用
快速查看磁盘满了inode 100%
df -i
# 查看inode使用情况
for i in /home/*; do echo $i; find $i | wc -l; done
# 指定路径查看inode信息
for i in `ls -1A | grep -v "\.\./" | grep -v "\./"`; do echo "`find $i | sort -u | wc -l` $i"; done | sort -rn | head -5
# 在当前目录,层层查看inode数量
文件或文件夹过多无法删除问题
cd del_dir
time perl -e 'for(<*>){((stat)<(unlink))}' # 删除目录下所有文件
mkdir null
time rsync -a --delete null/ del_dir # 同步方式清空文件和文件夹
卡住问题
主机上有挂载NFS,du -h时卡住
strace df -h
#查看卡在哪个位置;如果是nfs共享umount掉。
mount |grep misc
#查看是否有mount
systemctl restart proc-sys-fs-binfmt_misc.automount
# 重启mount点
yum 安装失败卡住
rm -f /var/lib/rpm/__db.00*
# 删除rpm数据文件
rpm -vv --rebuilddb
# 重建rpm数据文件
yum clean all
yum makecache
# 清空缓存后再重新缓存
强制重启
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
reboot -nf
# 重启时可以指定跳过 init 的处理和 sync 操作,这样可以避免大多数情况下的问题。