1. 程式人生 > >7.12 10.6-10.10

7.12 10.6-10.10

存在 圖片 tcp6 pts only ali tps proto sed

10.6 監控io性能

iostat

sar同屬一個包

[root@hyc-01-01 ~]# iostat 顯示信息類似sar –b

Linux 3.10.0-693.el7.x86_64 (hyc-01-01) 20180711 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle

0.06 0.00 0.15 0.00 0.00 99.79

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

sda 0.18 2.95 1.89 227609 146156

[root@hyc-01-01 ~]# iostat 1 每秒顯示一次

[root@hyc-01-01 ~]# iostat -x

Linux 3.10.0-693.el7.x86_64 (hyc-01-01) 20180711 _x86_64_ (1 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle

0.06 0.00 0.15 0.00 0.00 99.79

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.01 0.11 0.08 2.91 1.87 52.67 0.00 1.60 0.99 2.44 0.60 0.01

%util:單位時間內cpu等待io所用時間占比,該值過大說明磁盤io較差

rkB/swkB/s較小但%util仍較大則說明磁盤可能存在故障;

iotop命令

[root@hyc-01-01 ~]# yum install -y iotop 安裝

iotop命令

[root@hyc-01-01 ~]# iotop 查看進程對磁盤使用情況

Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s

Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s

TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND

1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --s~serialize 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]

5 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]

7 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0]

IO> 單位時間內進程占用IO的百分比

10.7 free命令

用於查看內存使用情況

[root@hyc-01-01 ~]# free

total used free shared buff/cache available

Mem: 1008152 132904 507340 6888 367908 691460

Swap: 2097148 0 2097148

mem 內存 swap 交換分區

默認單位為KB

[root@hyc-01-01 ~]# free –m 將信息以MB為單位顯示

total used free shared buff/cache available

Mem: 984 129 495 6 359 675

Swap: 2047 0 2047

[root@hyc-01-01 ~]# free –h 在具體數字後加上單位

total used free shared buff/cache available

Mem: 984M 129M 495M 6.7M 359M 675M

Swap: 2.0G 0B 2.0G

buffercache

Linux操作系統會將內存預分配一部分給buffercache

cache:磁盤裏的數據要到cpu去處理,數據會先被從磁盤讀入內存的cache中,再從cachecpu

buffercpu中處理完的數據寫入磁盤時會先被放到內存的buffer中,再從buffer寫入磁盤

available=free+未被使用的buffer/cache

total=used+free+buffer/cache

查看剩余內存時通常關註available

swap:

swapused過多可能因為內存不充足導致內存與交換分區發生數據交換

也有可能是內存泄露導致內存被占滿導致需要使用swap分區將暫時不用的數據交換出內存

10.8 ps命令

ps 查看系統進程

[root@hyc-01-01 ~]# ps

PID TTY TIME CMD

5249 pts/0 00:00:00 bash

5268 pts/0 00:00:00 ps

[root@hyc-01-01 ~]# ps aux

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

root 1 0.0 0.6 128208 6856 ? Ss 711 0:03 /usr/lib/systemd/s

root 2 0.0 0.0 0 0 ? S 711 0:00 [kthreadd]

root 3 0.0 0.0 0 0 ? S 711 0:00 [ksoftirqd/0]

root 5 0.0 0.0 0 0 ? S< 711 0:00 [kworker/0:0H]

root 7 0.0 0.0 0 0 ? S 711 0:00 [migration/0]

[root@hyc-01-01 ~]# 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 - 32052 ep_pol 711 ? 00:00:03 /usr/lib/

1 S root 2 0 0 80 0 - 0 kthrea 711 ? 00:00:00 [kthreadd

1 S root 3 2 0 80 0 - 0 smpboo 711 ? 00:00:00 [ksoftirq

1 S root 5 2 0 60 -20 - 0 worker 711 ? 00:00:00 [kworker/

1 S root 7 2 0 -40 - - 0 smpboo 711 ? 00:00:00 [migratio

1 S root 8 2 0 80 0 - 0 rcu_gp 711 ? 00:00:00 [rcu_bh]

1 R root 9 2 0 80 0 - 0 - 711 ? 00:00:01 [rcu_sche

5 S root 10 2 0 -40 - - 0 smpboo 711 ? 00:00:01 [watchdog

5 S root 12 2 0 80 0 - 0 devtmp 711 ? 00:00:00 [kdevtmpf

技術分享圖片

10.9 查看網絡狀態

[root@hyc-01-01 ~]# netstat

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

[root@hyc-01-01 ~]# 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 854/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 957/master

tcp6 0 0 :::22 :::* LISTEN 854/sshd

tcp 0 52 hyc-01-01:ssh 192.168.31.1:49749 ESTABLISHED

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags Type State I-Node Path

unix 2 [ ] DGRAM 11850 /run/systemd/shutdownd

unix 2 [ ] DGRAM 14727 /var/run/chrony/chronyd.sock

[root@hyc-01-01 ~]# 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:22 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN

tcp 0 52 192.168.31.129:22 192.168.31.1:49749 ESTABLISHED

tcp6 0 0 :::22 :::* LISTEN

tcp6 0 0 ::1:25 :::* LISTEN

udp 0 0 127.0.0.1:323 0.0.0.0:*

udp6 0 0 ::1:323 :::*

raw6 0 0 :::58 :::* 7

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags Type State I-Node Path

unix 2 [ ACC ] STREAM LISTENING 17933 public/qmgr

unix 2 [ ACC ] STREAM LISTENING 17970 public/showq

unix 2 [ ACC ] STREAM LISTENING 17955 public/flush

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

LISTEN 4

ESTABLISHED

10.10 linux下抓包

[root@hyc-01-01 ~]# yum install -y tcpdump 安裝tcpdump相關的包

[root@hyc-01-01 ~]# tcpdump -nn -i ens33

[root@hyc-01-01 ~]# tcpdump -nn -c 100 -w 1.cap

tcpdump: listening on nflog, link-type NFLOG (Linux netfilter log messages), capture size 262144 bytes


7.12 10.6-10.10