平常運維命令 iostat、free、ps aux、netstat -lnp、tcpdump等命令用法

10月24日任務linux

10.6 監控io性能ios

10.7 free命令ubuntu

10.8 ps命令centos

10.9 查看網絡狀態緩存

10.10 linux下抓包bash

 

10.6 、監控io性能
監控系統狀態
  • iostat -x  查看磁盤使用
  • iotop  查看磁盤使用(動態顯示)
 
  • free   查看內存使用狀況
  • free -m / -g / -h 
  • buffer/cache 區別
  • 公式: total=used+free+buff/cache
  • avaliable包含free和buffer/cache剩餘部分
 
#iostat -x 命令,最重要關注的指標%util, 表示io等待,磁盤使用佔用cpu等待io時間比,超過百分之五十就很是忙。
[root@centos6 ~]# iostat -x
Linux 2.6.32-642.el6.x86_64 (centos6.8)     10/24/2018     _x86_64_    (1 CPU)
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00    0.00    0.00  100.00
Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.02    0.01    0.01     0.33     0.28    37.95     0.00    1.08    1.96    0.57   0.75   0.00
dm-0              0.00     0.00    0.01    0.03     0.32     0.28    14.59     0.00    1.70    3.61    1.36   0.29   0.00

#  iotop命令

[root@centos6 ~]# yum install -y iotop
[root@centos6 ~]# iotop
Total DISK READ: 0.00 B/s | Total DISK WRITE: 0.00 B/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND   
  256 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [mpt_poll_0]
    1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init
    2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
    3 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [migration/0]
    4 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
    5 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [stopper/0]
    6 rt/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [watchdog/0]
    7 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [events/0]
    8 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [events/0]
    9 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [events_long/0]
   10 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [events_power_ef]
 
10.7 、free命令  查看內存使用狀況       buffers   緩衝  cached  緩存
 
[root@centos6 ~]# free
             total       used       free     shared    buffers     cached
Mem:       1020024     228504     791520        164      15476     139472
-/+ buffers/cache:      73556     946468
Swap:      4194300          0    4194300
[root@centos6 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          996M       223M       773M       164K        15M       136M
-/+ buffers/cache:        71M       924M
Swap:         4.0G         0B       4.0G
[root@centos6 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           996        223        773          0         15        136
-/+ buffers/cache:         71        924
Swap:         4095          0       4095
#什麼是緩衝和緩存
緩存:   0000(磁盤)  -->  內存(cache)-->  CPU
 緩衝:   CPU(000)-->  內存(buffer)--> 磁盤
 
 
10.8 、ps命令
ps 查看系統進程命令
用法: ps aux 、ps -elf
  • STAT部分說明
  • D 不能中斷的進程
  • R run狀態的進程
  • S sleep狀態的進程
  • T 暫停的進程
  • Z 殭屍進程
  • <  高優先級進程
  • N 低優先級進程
  • L  內存中被鎖了內存分頁
  • s  主進程
  • l   多線程進程
  • +  前臺進程
 
[root@centos6 ~]# ps aux
[root@centos6 ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  19232  1496 ?        Ss   Oct16   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Oct16   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Oct16   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Oct16   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Oct16   0:00 [stopper/0]
root         6  0.0  0.0      0     0 ?        S    Oct16   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Oct16   3:28 [events/0]
root         8  0.0  0.0      0     0 ?        S    Oct16   0:00 [events/0]
root         9  0.0  0.0      0     0 ?        S    Oct16   0:00 [events_long/0]
root        10  0.0  0.0      0     0 ?        S    Oct16   0:00 [events_power_ef]
root        11  0.0  0.0      0     0 ?        S    Oct16   0:00 [cgroup]
root        12  0.0  0.0      0     0 ?        S    Oct16   0:00 [khelper]
root        13  0.0  0.0      0     0 ?        S    Oct16   0:00 [netns]
root        14  0.0  0.0      0     0 ?        S    Oct16   0:00 [async/mgr]
root        15  0.0  0.0      0     0 ?        S    Oct16   0:00 [pm]
root        16  0.0  0.0      0     0 ?        S    Oct16   0:01 [sync_supers]
root        17  0.0  0.0      0     0 ?        S    Oct16   0:01 [bdi-default]
root        18  0.0  0.0      0     0 ?        S    Oct16   0:00 [kintegrityd/0]
root        19  0.0  0.0      0     0 ?        S    Oct16   0:00 [kblockd/0]
root        20  0.0  0.0      0     0 ?        S    Oct16   0:00 [kacpid]
root        21  0.0  0.0      0     0 ?        S    Oct16   0:00 [kacpi_notify]
root        22  0.0  0.0      0     0 ?        S    Oct16   0:00 [kacpi_hotplug]
root        23  0.0  0.0      0     0 ?        S    Oct16   0:00 [ata_aux]
root        24  0.0  0.0      0     0 ?        S    Oct16   0:00 [ata_sff/0]
root        25  0.0  0.0      0     0 ?        S    Oct16   0:00 [ksuspend_usbd]
root        26  0.0  0.0      0     0 ?        S    Oct16   0:00 [khubd]
root        27  0.0  0.0      0     0 ?        S    Oct16   0:00 [kseriod]
root        28  0.0  0.0      0     0 ?        S    Oct16   0:00 [md/0]
root        29  0.0  0.0      0     0 ?        S    Oct16   0:00 [md_misc/0]
root        30  0.0  0.0      0     0 ?        S    Oct16   0:00 [linkwatch]
root        33  0.0  0.0      0     0 ?        S    Oct16   0:00 [khungtaskd]
root        34  0.0  0.0      0     0 ?        S    Oct16   0:00 [kswapd0]
root        35  0.0  0.0      0     0 ?        SN   Oct16   0:00 [ksmd]
root        36  0.0  0.0      0     0 ?        SN   Oct16   0:00 [khugepaged]
root        37  0.0  0.0      0     0 ?        S    Oct16   0:00 [aio/0]
root        38  0.0  0.0      0     0 ?        S    Oct16   0:00 [crypto/0]
root        45  0.0  0.0      0     0 ?        S    Oct16   0:00 [kthrotld/0]
root        46  0.0  0.0      0     0 ?        S    Oct16   0:00 [pciehpd]
root        48  0.0  0.0      0     0 ?        S    Oct16   0:00 [kpsmoused]
root        49  0.0  0.0      0     0 ?        S    Oct16   0:00 [usbhid_resumer]
root        50  0.0  0.0      0     0 ?        S    Oct16   0:00 [deferwq]
root        82  0.0  0.0      0     0 ?        S    Oct16   0:00 [kdmremove]
root        83  0.0  0.0      0     0 ?        S    Oct16   0:00 [kstriped]
root       114  0.0  0.0      0     0 ?        S    Oct16   0:00 [ttm_swap]
root       247  0.0  0.0      0     0 ?        S    Oct16   0:00 [scsi_eh_0]
root       249  0.0  0.0      0     0 ?        S    Oct16   0:00 [scsi_eh_1]
root       256  0.0  0.0      0     0 ?        S    Oct16   0:08 [mpt_poll_0]
root       257  0.0  0.0      0     0 ?        S    Oct16   0:00 [mpt/0]
root       258  0.0  0.0      0     0 ?        S    Oct16   0:00 [scsi_eh_2]
root       356  0.0  0.0      0     0 ?        S    Oct16   0:00 [kdmflush]
root       417  0.0  0.0      0     0 ?        S    Oct16   0:00 [jbd2/dm-0-8]
root       418  0.0  0.0      0     0 ?        S    Oct16   0:00 [ext4-dio-unwrit]
root       493  0.0  0.0  10848   960 ?        S<s  Oct16   0:00 /sbin/udevd -d
root       603  0.0  0.0      0     0 ?        S    Oct16   0:10 [vmmemctl]
root       754  0.0  0.0  10848   980 ?        S<   Oct16   0:00 /sbin/udevd -d
root       762  0.0  0.0  10780   912 ?        S<   Oct16   0:00 /sbin/udevd -d
root       786  0.0  0.0      0     0 ?        S    Oct16   0:00 [jbd2/sda1-8]
root       787  0.0  0.0      0     0 ?        S    Oct16   0:00 [ext4-dio-unwrit]
root       820  0.0  0.0      0     0 ?        S    Oct16   0:00 [kauditd]
root      1067  0.0  0.0  27596   848 ?        S<sl Oct16   0:00 auditd
root      1089  0.0  0.1 249088  1764 ?        Sl   Oct16   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
root      1165  0.0  0.1  66240  1200 ?        Ss   Oct16   0:00 /usr/sbin/sshd
ntp       1176  0.0  0.2  30740  2152 ?        Ss   Oct16   0:01 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root      1201  0.0  0.1 116908  1304 ?        Ss   Oct16   0:02 crond
root      1214  0.0  0.0   4064   592 tty1     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty1
root      1216  0.0  0.0   4064   592 tty2     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty2
root      1218  0.0  0.0   4064   592 tty3     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty3
root      1220  0.0  0.0   4064   592 tty4     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty4
root      1222  0.0  0.0   4064   592 tty5     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty5
root      1224  0.0  0.0   4064   588 tty6     Ss+  Oct16   0:00 /sbin/mingetty /dev/tty6
root      6066  0.0  0.0      0     0 ?        S    16:00   0:00 [flush-253:0]
root      6107  0.0  0.4 102548  4500 ?        Ss   16:06   0:00 sshd: root@pts/0
root      6109  0.0  0.3 109756  3408 pts/0    Ss   16:06   0:00 -bash
root      6128  0.0  0.1 110244  1172 pts/0    R+   16:08   0:00 ps aux


[root@centos6 ~]# 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
0  0      0 784840  16564 142408    0    0     0     0    7    7  0  0 100  0  0   
0  0      0 784824  16564 142408    0    0     0     0   18   16  0  0 100  0  0   
^Z
[1]+  Stopped                 vmstat 1
[root@centos6 ~]# ps aux |grep vmstat
root      6155  0.0  0.0   6260   692 pts/0    T    16:32   0:00 vmstat 1
root      6157  0.0  0.0 103312   876 pts/0    S+   16:33   0:00 grep --color=auto vmstat
 
 
 
10.9 、查看網絡狀態
nestat  查看網絡狀態
netstat -lnp 查看監聽端口
netstat -an  查看系統的網絡連接情況
netstat -lntp  只看出tcp的 ,不包含socket
ss -an 和nestat殊途同歸
分享一個小技巧
netstat -an |awk '/^tcp/{++sta[$NF]} END {for (key in sta) print key,"\t",sta[key]}'
 
[root@centos6 ~]# 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:22                  0.0.0.0:*                   LISTEN      1165/sshd          
tcp        0      0 :::22                       :::*                        LISTEN      1165/sshd          
udp        0      0 172.16.5.235:123            0.0.0.0:*                               1176/ntpd          
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1176/ntpd          
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1176/ntpd          
udp        0      0 fe80::250:56ff:fea4:3d92:123 :::*                                    1176/ntpd           
udp        0      0 ::1:123                     :::*                                    1176/ntpd           
udp        0      0 :::123                      :::*                                    1176/ntpd           
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     7095   1/init              @/com/ubuntu/upstart
 
 
10.10 、linux抓包
  • 抓包工具  tcpdump
  • 用法  : tcpdump -nn
  • tcpdump -nn -i ens33
  • tcpdump -nn port 80
  • tcpdump -nn not port 22 and host 192.168.0.100
  • tcpump -nn -c 100 -w 1.cap
  • tshark -n -t a -R http.request -T fields -e "feame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
  • yum install -y wireshark
相關文章
相關標籤/搜索