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

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

2018-01-23 17:21 796 查看
扩展:
tcp三次握手四次挥手
http://www.doc88.com/p-9913773324388.html
tshark几个用法:
http://www.aminglinux.com/bbs/thread-995-1-1.html
10.6 监控io性能
安装iostat命令(也是安装这个包) :
[root@hao-01 ~]# yum install -y sysstat
1. (监控)查看 磁盘io使用情况:iostat -x
重要关注:%util 值 表示io磁盘使用多少占用cpu的!
[root@hao-01 ~]# iostat -x
[root@hao-01 ~]# iostat -x 1



2. 安装iotop命令 :
[root@hao-01 ~]# yum install -y iotop
3. (监控)查看 进程使用磁盘io百分比(哪个进程使用磁盘比较大) :iotop
重要关注:IO> 下的值(数值越大,排名越前)
[root@hao-01 ~]# iotop



10.7 free命令
1. 查看内容使用情况(默认单位:kb):free
[root@hao-01 ~]# free
2. 查看内容使用情况(指定单位:mb):free -m
[root@hao-01 ~]# free -m
3. 查看内容使用情况(直观单位):free -h
[root@hao-01 ~]# free -h



Mem(内存使用):total used free shared buff/cache
total(内存总大小)
used(使用内存)
free(剩余内存)
shared(共享内存)
buff/cache(缓冲/缓存)
磁盘读出来的数据——经过内存(cache缓存)——到CPU处理
CPU处理完的数据——经过内存(buffer缓冲)——放到磁盘里
公式:total=used+free+buff/cache
avaliable包含free和buff/cache剩余部分
Swap(交换分区):如果Swap不足了,需要考虑增加内存了(或者是内存泄漏程序有bug需要排查了)!
10.8 ps命令
1. 查看系统当前所有进程:ps -elf
列出系统当前所有进程 :ps aux
[root@hao-01 ~]# ps aux





USER(运行用户名称)
PID(进程id号)
%CPU(使用cpu百分比)
%MEM(使用磁盘百分比)
STAT部分说明:
D 不能中断的进程
R run状态的进程(某一个时间段内使用cpu的)
S sleep状态的进程(自动停止暂停,自动激活启动的)
T 暂停的进程(Ctrl c 的进程)
Z 僵尸进程(系统比较多僵尸进程,需要杀死)
< 高优先级进程
N 低优先级进程
L 内存中被锁了内存分页(极少见)
s 主进程
l 多线程进程
+ 前台进程
2. 查看指定进程是否运行: ps aux |grep 指定进程名称
[root@hao-01 ~]# ps aux |grep mysql
[root@hao-01 ~]# ps aux |grep nginx
3. 杀死指定进程(不要随意杀死进程哦):
[root@hao-01 ~]# kill 进程Pid



ps aux |grep ps aux
4. 查看进程是在哪个文件启动的 :ls -l /proc/进程Pdi/
[root@hao-01 ~]# ls -l /proc/3406/
10.9 查看网络状态
1. 查看网络状态: netstat
[root@hao-01 ~]# netstat
2. 查看监听端口 :netstat -lnp
[root@hao-01 ~]# netstat -lnp
3. 只查看tcp的监听端口(不包含socket):
[root@hao-01 ~]# netstat -lntp
4. 查看tcp和udp的监听端口(不包含socket):
[root@hao-01 ~]# netstat -lntup
5. 查看系统的网络连接状态(无法显示进程名字):ss -an
查看系统的网络连接状态:netstat -an
[root@hao-01 ~]# netstat -an
tcp三次握手四次挥手(重要,需了解,面试可能会问到)
http://www.doc88.com/p-9913773324388.html
6. 查看所有状态的数字:
[root@hao-01 ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'



ESTABLISHED:客户端和服务端在通信数量(1000以内都是正常的)
10.10 Linux下抓包
1. 安装tcpdump抓包命令:
[root@hao-01 ~]# yum install -y tcpdump
2. 抓包: tcpdump -nn -i 网卡名称
[root@hao-01 ~]# tcpdump -nn -i ens33
原本地ip地址原端口号 >到 数据包ip 数据包ip端口



3. 抓包 指定端口:tcpdump -nn -i 网卡名称 port 端口号
[root@hao-01 ~]# tcpdump -nn -i ens33 port 22
4. 抓包 排除指定端口:tcpdump -nn -i 网卡名称 ont port 端口号
[root@hao-01 ~]# tcpdump -nn -i ens33 not port 22
5. 抓包 排除指定端口,并指定ip的数据包:
tcpdump -nn -i 网卡名称 ont port 端口号 and host 指定ip
[root@hao-01 ~]# tcpdump -nn -i ens33 not port 22 and host 192.168.47.1
6. 指定抓包数量,并保存到指定文件内:
tcpdump -nn -i 网卡名称 -c 抓包数量 -w 存放文件地址
[root@hao-01 ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap
7. 安装tshark抓包命令:
[root@hao-01 ~]# yum install -y wireshark
8. tshark 查看指定网卡,80端口的访问情况:
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"
tshark几个用法:http://www.aminglinux.com/bbs/thread-995-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 抓包 free
相关文章推荐