10.6监控io性能
iostat -x:监控磁盘的使用情况(注意%util的那一列 yum install -y sysstat)
iostat -x 1:监控磁盘的使用情况,每妙更新一次(注意%util的那一列yun install -y sysstat)
iotop 动态健康磁盘的使用(yum install -y iotop(和top命令类似))
%util:工作时间或者繁忙时间占总时间的百分比。
rrqms:每秒合并并读操作的次数
wrqm/s:每秒合并鞋操作的次数
r/s:每秒读操作的次数
rMB/s:每秒读取的MB字节数
wMB/s:每秒写入的MB字节数
avgrq-sz:每个IO的平均扇区数,即所有请求的平均大小,以扇区(512字节)为单位
await:平均每个IO所需要的时间,包括在队列的时间,也包括磁盘控制器处理本次请求的有效时间
10.7 free命令:查看当前系统总内存大小和内存的使用情况
[root@bogon ~]# free total used free shared buff/cache available Mem: 997956 201848 339484 8184 456624 595260 Swap: 4194300 0 4194300
10.8 ps命令:可以查看系统的进程
[root@bogon ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.4 125496 4048 ? Ss 7月10 0:03 /usr/lib/syst root 2 0.0 0.0 0 0 ? S 7月10 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 7月10 0:01 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 7月10 0:00 [kworker/0:0H root 6 0.0 0.0 0 0 ? S 7月10 0:02 [kworker/u256 root 7 0.0 0.0 0 0 ? S 7月10 0:01 [migration/0] root 8 0.0 0.0 0 0 ? S 7月10 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? R 7月10 0:01 [rcu_sched] root 10 0.0 0.0 0 0 ? S< 7月10 0:00 [lru-add-drai root 11 0.0 0.0 0 0 ? S 7月10 0:00 [watchdog/0] root 13 0.0 0.0 0 0 ? S 7月10 0:00 [kdevtmpfs]
[root@bogon ~]# ps aux |grep -c sshd 3 [root@bogon ~]# ps aux |grep sshd root 1008 0.0 0.4 112812 4284 ? Ss 7月10 0:00 /usr/sbin/ssh -D root 10707 0.0 0.6 167828 6588 ? Ss 15:43 0:00 sshd: root@pts/0 root 11180 0.0 0.0 112720 984 pts/0 R+ 16:19 0:00 grep --color=auto sshd
10.9 netstat查看网络状态
netstat:这个命令可以打印出网络的连接状况、系统开放的端口、路由表的相关信息。
[root@bogon ~]# netstat -lnp |head -n 30 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 552/rpcbind tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1388/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1008/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1007/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1122/master tcp6 0 0 :::111 :::* LISTEN 552/rpcbind tcp6 0 0 :::22 :::* LISTEN 1008/sshd tcp6 0 0 ::1:631 :::* LISTEN
[root@bogon ~]# netstat -an |head -n 20 Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 64 192.168.193.128:22 192.168.193.1:57884 ESTABLISHED tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:631 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN udp 0 0 0.0.0.0:5353 0.0.0.0:* udp 0 0 127.0.0.1:323 0.0.0.0:* udp 0 0 192.168.122.1:53 0.0.0.0:* udp 0 0 0.0.0.0:67 0.0.0.0:* udp 0 0 0.0.0.0:111 0.0.0.0:* udp 0 0 0.0.0.0:36033 0.0.0.0:* udp 0 0 0.0.0.0:722 0.0.0.0:* udp6 0 0 ::1:323 :::*
请记住以下这个命令:
netstat -an|awk '/^tcp/{++sta[$NF]}END {for(key in sta)print key,"\t",sta[key]}'
[root@bogon ~]# netstat -an|awk '/^tcp/{++sta[$NF]}END {for(key in sta)print key,"\t",sta[key]}' LISTEN 9 ESTABLISHED 1 [root@bogon ~]# netstat -an |grep 80 unix 3 [ ] STREAM CONNECTED 14580 unix 3 [ ] STREAM CONNECTED 24780
10.10 linux下抓包
tcpdump抓包:将网络中传送的数据包完全截获下来提供分析。它支持针对网络层、协议、主机、网络或者端口的过滤,并提供and、or、not等逻辑语句帮你去掉一些没用的信息。常用参数:
-nn:直接以 IP 及 port number 显示,而非主机名与服务名称
-i :后面接要『监听』的网络接口,例如 eth0, lo, ppp0 等等的界面;
-c :监听的封包数,如果抓到满足条件的包数,则停止;否则 tcpdump 会持续不断的 监听, 直到使用者输入 [ctrl]-c 为止.。
-w :如果你要将监听所得的封包数据储存下来,用这个参数就对了!后面接档名
84496, win 254, length 0 16:27:29.796821 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 17184496:17184688, ack 252321, win 320, length 192 16:27:29.796979 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 17184688:17184976, ack 252321, win 320, length 288 16:27:29.797131 IP 192.168.193.1.57884 > 192.168.193.128.22: Flags [.], ack 17184976, win 252, length 0 16:27:29.797154 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 17184976:17185168, ack 252321, win 320, length 192 16:27:29.797316 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 17185168:17185456, ack 252321, win 320, length 288 16:27:29.797413 IP 192.168.193.1.57884 > 192.168.193.128.22: Flags [P.], seq 252321:252385, ack 17185168, win 252, length 64 16:27:29.797429 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 17185456:17185648, ack 252385, win 320, length 192 ^C 108878 packets captured 108878 packets received by filter 0 packets dropped by kernel
18:04:55.396860 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 13328:13600, ack 321, win 366, length 272 18:04:55.397099 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 13600:13776, ack 321, win 366, length 176 18:04:55.397194 IP 192.168.193.1.57884 > 192.168.193.128.22: Flags [.], ack 13776, win 253, length 0 18:04:55.397344 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 13776:14048, ack 321, win 366, length 272 18:04:55.397581 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 14048:14224, ack 321, win 366, length 176 18:04:55.397720 IP 192.168.193.1.57884 > 192.168.193.128.22: Flags [.], ack 14224, win 251, length 0 18:04:55.397890 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 14224:14496, ack 321, win 366, length 272 18:04:55.398151 IP 192.168.193.128.22 > 192.168.193.1.57884: Flags [P.], seq 14496:14672, ack 321, win 366, length 176 18:04:55.398257 IP 192.168.193.1.57884 > 192.168.193.128.22: Flags [.], ack 14672, win 256, length 0 100 packets captured 100 packets received by filter 0 packets dropped by kernel
上例是
[root@bogon ~]# tcpdump -nn -i ens33 -c 100输出的结果
***这个命令比较重要:
tshark -n -ta -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri
先执行安装命令:yum install -y wireshark