本文共 16493 字,大约阅读时间需要 54 分钟。
[root@aminglinux-01 ~]# iostat -xLinux 3.10.0-514.el7.x86_64 (aminglinux-01) 2017年11月27日 _x86_64_ (1 CPU)avg-cpu: %user %nice %system %iowait %steal %idle 0.05 0.00 0.11 0.00 0.00 99.84Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %utilsda 0.00 0.00 0.03 0.03 1.17 0.53 60.11 0.00 3.50 2.43 4.69 0.91 0.01sdb 0.00 0.00 0.00 0.00 0.01 0.00 12.35 0.00 0.07 0.07 0.00 0.05 0.00scd0 0.00 0.00 0.00 0.00 0.00 0.00 8.00 0.00 2.09 2.09 0.00 2.00 0.00dm-0 0.00 0.00 0.00 0.00 0.00 0.00 15.20 0.00 0.07 0.07 0.00 0.07 0.00
说明:%util这列就是表示磁盘io百分比,如果百分比很大,那就会导致读与写也很大,会影响磁盘性能。
使用yum install -y iotop安装
输入iotop,查看磁盘io,动态显示。
Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/sActual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 21 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.38 % [kworker/0:1] 1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 21 2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd] 3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0] 517 be/4 polkitd 0.00 B/s 0.00 B/s 0.00 % 0.00 % polkitd --no-debug [JS GC Helper] 518 be/4 polkitd 0.00 B/s 0.00 B/s 0.00 % 0.00 % polkitd --no-debug [JS Sour~ Thread] 7 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0] 8 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh] 9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched] 10 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/0] 12 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khelper] 13 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kdevtmpfs] 14 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [netns] 15 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khungtaskd] 16 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [writeback] 17 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kintegrityd] 18 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [bioset] 19 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kblockd] 20 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [md] 535 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % NetworkManager --no-daemon 26 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kswapd0] 27 be/5 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksmd] 28 be/7 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [khugepaged] 29 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [fsnotify_mark] 30 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [crypto]
free命令可以查看当前系统的总内存大小以及使用内存的情况。
示例如下:
[root@aminglinux-01 ~]# free total used free shared buff/cache availableMem: 999940 126608 541660 6808 331672 682536Swap: 2097148 0 2097148[root@aminglinux-01 ~]# free -m total used free shared buff/cache availableMem: 976 123 528 6 323 666Swap: 2047 0 2047[root@aminglinux-01 ~]# free -h total used free shared buff/cache availableMem: 976M 123M 528M 6.6M 323M 666MSwap: 2.0G 0B 2.0G[root@aminglinux-01 ~]# free -g total used free shared buff/cache availableMem: 0 0 0 0 0 0Swap: 1 0 1
解释:
总结:
ps aux或ps -elf都是查看系统进程命令
[root@aminglinux-01 ~]# ps aux //查看所有系统进程USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.6 128104 6708 ? Ss 11月25 0:04 /usr/lib/systemd/systemd --switched-root --system --droot 2 0.0 0.0 0 0 ? S 11月25 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 11月25 0:16 [ksoftirqd/0]root 7 0.0 0.0 0 0 ? S 11月25 0:00 [migration/0]root 8 0.0 0.0 0 0 ? S 11月25 0:00 [rcu_bh]root 9 0.0 0.0 0 0 ? R 11月25 1:41 [rcu_sched]root 10 0.0 0.0 0 0 ? S 11月25 0:04 [watchdog/0]root 12 0.0 0.0 0 0 ? S< 11月25 0:00 [khelper]root 13 0.0 0.0 0 0 ? S 11月25 0:00 [kdevtmpfs]root 14 0.0 0.0 0 0 ? S< 11月25 0:00 [netns]root 15 0.0 0.0 0 0 ? S 11月25 0:00 [khungtaskd]root 16 0.0 0.0 0 0 ? S< 11月25 0:00 [writeback]root 17 0.0 0.0 0 0 ? S< 11月25 0:00 [kintegrityd]root 18 0.0 0.0 0 0 ? S< 11月25 0:00 [bioset]root 19 0.0 0.0 0 0 ? S< 11月25 0:00 [kblockd][root@aminglinux-01 ~]# ps aux |grep nginx //查看nginx服务进程是否存在root 5821 0.0 0.0 112676 976 pts/0 R+ 19:33 0:00 grep --color=auto nginx
解释说明:
示例如下:
[root@aminglinux-01 ~]# ps aux |grep -c sshd3[root@aminglinux-01 ~]# ps aux |grep sshdroot 867 0.0 0.1 82480 1372 ? Ss 11月25 0:00 /usr/sbin/sshdroot 3542 0.0 0.5 143104 5180 ? Ss 11月27 1:21 sshd: root@pts/0root 5835 0.0 0.0 112676 976 pts/0 S+ 19:47 0:00 grep --color=auto sshd
上例中的3不准确,需要减掉1,因为使用grep命令时,grep命令本身也算一个进程。
netstat命令用来打印网络连接状况、系统所开放端口、路由表等信息。
常用的命令有如下:
示例如下:
[root@aminglinux-01 ~]# netstatActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 52 aminglinux-01:ssh 192.168.4.84:51554 ESTABLISHEDudp 0 0 aminglinux-01:41402 leontp.ccgs.wa.edu.:ntp ESTABLISHEDActive UNIX domain sockets (w/o servers)Proto RefCnt Flags Type State I-Node Pathunix 2 [ ] DGRAM 12652 /run/systemd/shutdowndunix 2 [ ] DGRAM 8332 /run/systemd/notifyunix 2 [ ] DGRAM 8334 /run/systemd/cgroups-agentunix 5 [ ] DGRAM 8355 /run/systemd/journal/socketunix 12 [ ] DGRAM 8357 /dev/logunix 3 [ ] STREAM CONNECTED 15304 /var/run/dbus/system_bus_socketunix 2 [ ] DGRAM 15259 unix 3 [ ] DGRAM 13529 unix 2 [ ] DGRAM 367481 unix 2 [ ] DGRAM 19035 unix 3 [ ] STREAM CONNECTED 15199 /run/systemd/journal/stdoutunix 3 [ ] STREAM CONNECTED 19144 unix 2 [ ] DGRAM 13508 ....省略[root@aminglinux-01 ~]# netstat -lnpActive 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 867/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1277/master tcp6 0 0 :::22 :::* LISTEN 867/sshd tcp6 0 0 ::1:25 :::* LISTEN 1277/master udp 0 0 127.0.0.1:323 0.0.0.0:* 503/chronyd udp6 0 0 ::1:323 :::* 503/chronyd raw6 0 0 :::58 :::* 7 535/NetworkManager Active UNIX domain sockets (only servers)Proto RefCnt Flags Type State I-Node PID/Program name Pathunix 2 [ ACC ] STREAM LISTENING 14863 1/systemd /var/run/dbus/system_bus_socketunix 2 [ ACC ] STREAM LISTENING 19087 1277/master private/rewriteunix 2 [ ACC ] STREAM LISTENING 19090 1277/master private/bounceunix 2 [ ACC ] STREAM LISTENING 19084 1277/master private/tlsmgrunix 2 [ ACC ] STREAM LISTENING 19094 1277/master private/deferunix 2 [ ACC ] STREAM LISTENING 19097 1277/master private/traceunix 2 [ ACC ] STREAM LISTENING 19100 1277/master private/verifyunix 2 [ ACC ] STREAM LISTENING 19106 1277/master private/proxymapunix 2 [ ACC ] STREAM LISTENING 19109 1277/master private/proxywriteunix 2 [ ACC ] STREAM LISTENING 19112 1277/master private/smtp.....省略[root@aminglinux-01 ~]# netstat -lntpActive 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 867/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1277/master tcp6 0 0 :::22 :::* LISTEN 867/sshd tcp6 0 0 ::1:25 :::* LISTEN 1277/master [root@aminglinux-01 ~]# ss -anNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port nl UNCONN 0 0 0:0 * nl UNCONN 0 0 0:-46136809 * nl UNCONN 0 0 0:-46136809 * nl UNCONN 768 0 4:0 * nl UNCONN 4352 0 4:5885 * nl UNCONN 0 0 6:0 * nl UNCONN 0 0 7:1 * nl UNCONN 0 0 7:500 * nl UNCONN 0 0 7:0 * nl UNCONN 0 0 7:500 * nl UNCONN 0 0 7:1 *
可以查看所有状态的数字,使用命令:netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
示例命令如下:
[root@aminglinux-01 ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'LISTEN 4ESTABLISHED 1
备注:如果你管理是一台提供Web服务(80端口)的服务器,那么就可以使用命令netstat -an |grep 80来查看当前连接Web服务的有哪些IP。
安装命令yum install -y tcpdump
用法:tcpdump -nn -i ens33
示例如下:
[root@aminglinux-01 ~]# tcpdump -nn //由于网卡关系找不到tcpdump: packet printing is not supported for link type NFLOG: use -w[root@aminglinux-01 ~]# ifconfig //查看网卡ens33: flags=4163mtu 1500 inet 192.168.1.185 netmask 255.255.0.0 broadcast 192.168.255.255 inet6 fe80::1ffb:cde1:5f3e:5778 prefixlen 64 scopeid 0x20 ether 00:0c:29:09:e5:58 txqueuelen 1000 (Ethernet) RX packets 2616938 bytes 240569555 (229.4 MiB) RX errors 0 dropped 832 overruns 0 frame 0 TX packets 101017 bytes 21050800 (20.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 12 bytes 1020 (1020.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1020 (1020.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@aminglinux-01 ~]# tcpdump -nn -i ens33 //正确用法20:19:58.421641 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 158748:158928, ack 1, win 340, length 18020:19:58.422758 IP 192.168.4.84.51554 > 192.168.1.185.22: Flags [.], ack 158928, win 25374, length 020:19:58.425049 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 158928:159204, ack 1, win 340, length 27620:19:58.426438 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 159204:159384, ack 1, win 340, length 18020:19:58.426978 IP 192.168.4.84.51554 > 192.168.1.185.22: Flags [.], ack 159384, win 25260, length 020:19:58.427349 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 159384:159660, ack 1, win 340, length 27620:19:58.427693 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 159660:159840, ack 1, win 340, length 18020:19:58.428668 IP 192.168.4.84.51554 > 192.168.1.185.22: Flags [.], ack 159840, win 25146, length 020:19:58.428879 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 159840:160116, ack 1, win 340, length 27620:19:58.429372 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 160116:160296, ack 1, win 340, length 18020:19:58.429621 IP 192.168.4.84.51554 > 192.168.1.185.22: Flags [.], ack 160296, win 25032, length 020:19:58.429787 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 160296:160572, ack 1, win 340, length 27620:19:58.430281 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 160572:160752, ack 1, win 340, length 18020:19:58.430596 IP 192.168.4.84.51554 > 192.168.1.185.22: Flags [.], ack 160752, win 24918, length 020:19:58.432366 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 160752:161028, ack 1, win 340, length 27620:19:58.432823 IP 192.168.1.185.22 > 192.168.4.84.51554: Flags [P.], seq 161028:161208, ack 1, win 340, length 180...省略
其它用法:
安装命令yum install -y wireshark
下面这条命令可以查看指定网卡80端口的一个web访问的情况,如果服务器没有提供web服务,没有任何的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"
转载于:https://blog.51cto.com/taoxie/2045427