2017-11-28 7周2次课 linux系统日常管理(二)

监控io性能

iostat -x  磁盘使用

iotop    磁盘使用

[root@node69 ~]# iostat
Linux 3.10.0-514.el7.x86_64 (node69) 	2017年11月29日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           5.10    0.06    1.83    0.67    0.00   92.33

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.91        80.84         9.81     590553      71686
sdb               0.04         0.27         0.00       1948          0
scd0              0.00         0.01         0.00         66          0
dm-0              0.01         0.06         0.00        456          0


[root@node69 ~]# iostat -x
Linux 3.10.0-514.el7.x86_64 (node69) 	2017年11月29日 	_x86_64_	(1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           4.94    0.06    1.76    0.63    0.00   92.61

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.07    1.96    0.78    75.69     9.43    62.02     0.11   38.69   28.13   65.25   9.75   2.68
sdb               0.00     0.00    0.04    0.00     0.25     0.00    12.45     0.00    5.70    5.70    0.00   4.27   0.02
scd0              0.00     0.00    0.00    0.00     0.01     0.00     6.00     0.00   18.00   18.00    0.00  18.00   0.01
dm-0              0.00     0.00    0.01    0.00     0.06     0.00    15.20     0.00    2.22    2.22    0.00   2.10   0.00

[root@node69 ~]# yum install -y iotop

iotop 动态显示


free 查看内存使用情况

[root@node69 ~]# free
              total        used        free      shared  buff/cache   available
Mem:        1867264      552384      645152       10400      669728     1095004
Swap:       2097148           0     2097148
[root@node69 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1823         539         629          10         654        1069
Swap:          2047           0        2047
[root@node69 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        539M        629M         10M        654M        1.0G
Swap:          2.0G          0B        2.0G

ps 查看系统进程 
ps aux / ps -elf
PID :进程的id,这个id很有用,在linux中内核管理进程就得靠pid来识别和管理某一个程,比如我想终止某一个进程,则用 ‘kill  进程的pid’ 有时并不能杀掉,则需要加一个-9选项了 kill  -9  进程pid
STAT :表示进程的状态,进程状态分为以下几种
D 不能中断的进程(通常为IO)
R 正在运行中的进程
S 已经中断的进程,系统中大部分进程都是这个状态
T 已经停止或者暂停的进程,如果我们正在运行一个命令,比如说 sleep 10 如果我们按一下ctrl -z 让他暂停,那么我们用ps查看就会显示T这个状态

Z 僵尸进程,杀不掉,打不死的垃圾进程,占系统一小点资源,不过没有关系。如果太多,就有问题了。
< 高优先级进程
N 低优先级进程
[root@node69 ~]# ps -elf
F S UID         PID   PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root          1      0  0  80   0 - 31338 ep_pol 06:23 ?        00:00:06 /usr/lib/s
1 S root          2      0  0  80   0 -     0 kthrea 06:23 ?        00:00:00 [kthreadd]
1 S root          3      2  0  80   0 -     0 smpboo 06:23 ?        00:00:01 [ksoftirqd
1 S root          7      2  0 -40   - -     0 smpboo 06:23 ?        00:00:00 [migration
1 S root          8      2  0  80   0 -     0 rcu_gp 06:23 ?        00:00:00 [rcu_bh]
1 R root          9      2  0  80   0 -     0 -      06:23 ?        00:00:05 [rcu_sched
5 S root         10      2  0 -40   - -     0 smpboo 06:23 ?        00:00:00 [watchdog/
1 S root         12      2  0  60 -20 -     0 rescue 06:23 ?        00:00:00 [khelper]
5 S root         13      2  0  80   0 -     0 devtmp 06:23 ?        00:00:00 [kdevtmpfs
1 S root         14      2  0  60 -20 -     0 rescue 06:23 ?        00:00:00 [netns]
1 S root         15      2  0  80   0 -     0 watchd 06:23 ?        00:0


L 在内存中被锁了内存分页
s 主进程
l 多线程进程
+ 在前台的进程
[root@node69 ~]# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.2 125352  3912 ?        Ss   06:23   0:06 /usr/lib/systemd/syst
root          2  0.0  0.0      0     0 ?        S    06:23   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    06:23   0:01 [ksoftirqd/0]
root          7  0.0  0.0      0     0 ?        S    06:23   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    06:23   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        R    06:23   0:05 [rcu_sched]
root         10  0.0  0.0      0     0 ?        S    06:23   0:00 [watchdog/0]
root         12  0.0  0.0      0     0 ?        S<   06:23   0:00 [khelper]
root         13  0.0  0.0      0     0 ?        S    06:23   0:00 [kdevtmpfs]
root         14  0.0  0.0      0     0 ?        S<   06:23   0:00 [netns]
root         15  0.0  0.0      0     0 ?        S    06:23   0:00 [khungtaskd]
root         16  0.0  0.0      0     0 ?        S<   06:23   0:00 [writeback]
root         17  0.0  0.0      0     0 ?        S<   06:23   0:00 [kintegrityd]


netstat 查看网络状况

netstat -lnp  查看当前系统开启的端口以及socket
netstat -an  查看当前系统所有的连接

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

 

[root@node69 ~]# netstat -lnp
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      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2197/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1044/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      915/cupsd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1652/master         
tcp6       0      0 :::111                  :::*                    LISTEN      1/
[root@node69 ~]# netstat -an
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     
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 192.168.161.128:37103   51.15.41.135:123        ESTABLISHED

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

Linux抓包工具

如果没有tcpdump 这个命令,需要用 yum install -y tcpdump 命令去安装一下

抓包工具tcpdump

tcpdump -nn

[root@node69 ~]# tcpdump -nn -i ens33
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 65535 bytes
09:44:35.635215 ARP, Request who-has 192.168.161.128 tell 192.168.161.2, length 46
09:44:35.635378 ARP, Reply 192.168.161.128 is-at 00:0c:29:a1:a0:a3, length 28
09:44:35.635532 IP 51.15.41.135.123 > 192.168.161.128.54637: NTPv4, Server, length 48
09:44:49.188985 IP 192.168.161.128.57335 > 85.199.214.100.123: NTPv4, Client, length 48
09:44:50.202346 IP 85.199.214.100.123 > 192.168.161.128.57335: NTPv4, Server, length 48
09:44:54.201297 ARP, Request who-has 192.168.161.2 tell 192.168.161.128, length 28
09:44:54.201465 ARP, Reply 192.168.161.2 is-at 00:50:56:fd:f3:1b, length 46
^C
[root@node69 ~]# tcpdump -nn port 80

[root@node69 ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 65535 bytes
10 packets captured
10 packets received by filter
0 packets dropped by kernel


wireshark 在linux下也可以安装 yum install -y wireshark
抓包分析http请求: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"




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值