您的位置:首页 > 理论基础 > 计算机网络

10.6 监控io性能 10.7 free命令 10.8 ps命令 10.9 查看网络状态 10.10 linux下抓包

2018-01-23 22:54 996 查看

iostat

sysstat 包里面包括 sar 和 iostat

[root@centos7 ~]# iostat

Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle

0.41 0.00 0.27 0.01 0.00 99.31

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

vda 0.25 2.04 2.25 1348209 1490248

iostat 1 一直循环显示磁盘信息

iostat -x 磁盘使用

[root@centos7 ~]# iostat -x

Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle

0.41 0.00 0.27 0.01 0.00 99.31

Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util

vda 0.00 0.07 0.04 0.21 2.04 2.25 34.40 0.00 11.22 15.07 10.48 0.46 0.01

Device: sda,sdb,vda 磁盘

rkB/s wkB/s 读写速度

一个重要的指标:%util

%util 表示等待磁盘io百分比

iotop 查看哪一个进程在读写磁盘

yum install -y iotop

iotop 磁盘使用

[root@centos7 ~]# iotop

Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s

Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s

TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND

1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 21

free

free查看内存使用情况

[root@centos7 ~]# free -h

total used free shared buff/cache available

Mem: 1.8G 530M 140M 14M 1.1G 1.1G

Swap: 0B 0B 0B

Mem 物理内存

swap交换分区

total :总共内存大小

used:使用的内存

free:剩余内存大小

buff:缓冲

cache : 缓存

buffer /cache区别:

从 磁盘读数据 ---> 内存 (cahche缓存)-----> cpu

cpu处理好的数据 ---> 内存 (buffer缓冲)----->磁盘

free -m / -g / -h

free -m (MB)

free -h(具体数据加上单位)

free -g(GB)

内存总大小公式:total = used + free + buff /cache

avaliable 包含free和buffer/cache剩余部分

ps

ps查看系统进程

(ps意思是报告系统进程快照)

用法:ps aux、ps -elf

ps aux 显示系统进程

[root@centos7 ~]# ps aux

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.0 0.2 43388 3824 ? Ss 1月15 0:03 /usr/lib/systemd/systemd --switched

root 2 0.0 0.0 0 0 ? S 1月15 0:00 [kthreadd]

root 3 0.0 0.0 0 0 ? S 1月15 0:10 [ksoftirqd/0]

....

ps aux |grep nginx 列出当前系统进程中的nginx进程

[root@centos7 ~]# ps aux |grep nginx

root 11881 0.0 0.0 112676 984 pts/0 R+ 17:55 0:00 grep --color=auto nginx

root 28467 0.0 0.1 122908 2268 ? Ss 1月20 0:00 nginx: master process nginx

nginx 28468 0.0 0.1 123296 3588 ? S 1月20 0:00 nginx: worker process

kill pid 杀死某个进程

PID 是进程号

查看进程从哪里启动的

ls /proc/进程号(每一个进程都有一个目录)/

ls /proc/505/

STAT部分说明

D不能中断的进程

R run状态的进程

S sleep状态的进程

T 暂停的进程

Z 僵尸进程

< 高优先级进程

N 低优先级进程

L 内存中被锁了内存分页

S 主进程

| 多线程进程

+ 前台进程

什么原因产生僵尸进程?

当父进程被意外中断,单独留下子进程,这些子进程被称为僵尸进程。

多线程进程:

进程是程序的一次运行,一个进程包含多个线程。

暂停进程

[root@centos7 ~]# vmstat 1

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

3 0 0 141648 52672 1144972 0 0 2 2 41 30 0 0 99 0 0

0 0 0 141648 52672 1144972 0 0 0 0 176 345 0 1 99 0 0

0 0 0 141648 52672 1144972 0 0 0 8 171 336 1 0 99 0 0

0 0 0 141260 52672 1144972 0 0 0 0 168 352 0 0 100 0 0

0 0 0 141248 52672 1144972 0 0 0 0 162 368 0 0 100 0 0

^Z

[1]+ 已停止 vmstat 1

[root@centos7 ~]# ps aux |grep vmstat

root 21417 0.0 0.0 148316 1376 pts/0 T 19:13 0:00 vmstat 1

netstat 查看网络状态

netstat -lnp 查看监听端口

netstat -ltnp 只查看tcp端口

netstat -ltunp 只查看tcp,udp端口

netstat -an 查看系统的网络连接状况

netstat -lntp 只看tcp的,不包含socket

ss -an 和netstat 异曲同工

技巧:

netstat -an |awk '/^tcp/{++sta[$NF]}END{for(key in sta) print key,"\t",sta[key]}'

[root@centos7 ~]# netstat -an |awk '/^tcp/{++sta[$NF]}END{for(key in sta) print key,"\t",sta[key]}'

LISTEN 3

ESTABLISHED 3

tcpdump

安装yum install -y tcpdump

抓包工具:tcpdump

用法:tcpdump -nn

第一个n 表示用ip显示出来,如果不加n,就会显示主机名

监听指定网卡

tcpdump -nn -i eth0

[root@centos7 ~]# tcpdump -nn -i eth0

监听指定端口

监听80 web 端口

[root@centos7 ~]# tcpdump -nn port 80

监听网卡eth0 端口80

[root@centos7 ~]# tcpdump -nn -i eth0 port 80

不监听22端口的

tcpdump -nn -i etho not port 22

指定某个IP的包,不包括22端口

tcpdump -nn -i eth0 not port 22 and host 192.168.1.1

抓100个包放到/tmp/1.cap里面

tcpdump -nn -i eth0 -c 100 -w /tmp/1.cap

[root@centos7 ~]# tcpdump -nn -i eth0 -c 100 -w /tmp/1.cap

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes

100 packets captured

102 packets received by filter

0 packets dropped by kernel

读取抓取保存的包文件1.cap

[root@centos7 ~]# tcpdump -r /tmp/1.cap

Wire shark抓包

[root@centos7 ~]# yum install -y wireshark

wireshark里面的tshark命令

可以清楚的看到哪个IP来访问我的网站,访问我网站里面什么内容。

tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e

"http.host" -e "http.request.method" -e "http.request.uri"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐