10月23日任務centos
10.1 使用w查看系統負載網絡
10.2 vmstat命令ssh
10.3 top命令ui
10.4 sar命令centos7
10.5 nload命令spa
# 第一行:當前系統時間,系統啓動時間,登陸的用戶,系統負載:1分鐘內,5分鐘內,15分鐘內 [root@centos7 ~]# w 20:54:14 up 5 min, 1 user, load average: 0.01, 0.14, 0.09 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 19:49 2.00s 0.04s 0.00s w root pts/0 192.168.65.1 20:50 6.00s 0.07s 0.03s w
tty[1-7]:物理機終端; pts:虛擬終端(經過ssh遠程鏈接)code
關於系統負載的值:單位時間內使用cpu的活動的平均進程數。最佳的值爲系統邏輯cpu的個數,大於該值對cpu有壓力,小於該值表示cpu空閒。排序
# 查看當前系統的cpu個數(+1) [root@centos7 ~]# grep "processor" /proc/cpuinfo | tail -n 1 processor : 1 # 上面的代碼表示系統的cpu個數爲2
# 顯示內容至關於w命令的首行 [root@centos7 ~]# uptime 21:03:14 up 14 min, 1 user, load average: 0.00, 0.03, 0.05
# 統計每隔1s的系統狀態,共統計5次(後面的5不加,會一直統計下去,除非用ctrl+c打斷) [root@centos7 ~]# vmstat 1 5 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 736764 2076 135812 0 0 34 4 59 57 0 0 98 1 0 1 0 0 736764 2076 135812 0 0 0 0 60 49 0 1 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 42 33 0 0 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 53 44 0 0 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 41 36 0 0 100 0 0
符號 | 說明 |
---|---|
r(run) | 當前運行的進程數 |
b(block) | 當前系統等待的進程數(被網絡、磁盤阻斷) |
swpd | 內存不足時交換分區纔會變化,需注意 |
free | 內存剩餘大小 |
si | 數據從swap寫入內存 |
so | 數據從內存寫入swap |
bi | 磁盤->內存:讀的數據量 |
bo | 內存->磁盤:寫的數據量 |
us | 用戶級別生成的進程所佔用的cpu資源百分比(長時間大於50,資源可能不夠) |
sy | 系統級別生成的進程、服務所佔用的cpu資源百分比 |
id | 空閒資源佔用cpu資源百分比(us+sy+id=100) |
wa | 等待cpu的百分比(值大cpu可能不足) |
查看進程使用資源狀況(動態,每3秒刷新一次)進程
[root@centos7 ~]# top top - 21:27:28 up 38 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999720 total, 732700 free, 125816 used, 141204 buff/cache KiB Swap: 4194300 total, 4194300 free, 0 used. 711064 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 128164 6816 4048 S 0.0 0.7 0:02.61 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd+ 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0+ 6 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kworker/u+ 7 root rt 0 0 0 0 S 0.0 0.0 0:00.03 migration+ 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 0:00.45 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/1
top - 21:27:28 up 38 min, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 999720 total, 732700 free, 125816 used, 141204 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 711064 avail Mem
顯示效果切換內存
top -c 顯示各具體進程命令使用資源狀況
[root@centos7 ~]# top -c top - 21:47:42 up 58 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.2 us, 0.3 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999720 total, 706460 free, 138408 used, 154852 buff/cache KiB Swap: 4194300 total, 4194300 free, 0 used. 690712 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 525 root 20 0 305296 6292 4920 S 0.3 0.6 0:05.09 /usr/bin/vmtoolsd 1273 root 20 0 157612 2192 1592 R 0.3 0.2 0:00.10 top -c 1 root 20 0 128164 6816 4048 S 0.0 0.7 0:02.63 /usr/lib/systemd/systemd --switched-root --system --deserializ+ 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kthreadd] 3 root 20 0 0 0 0 S 0.0 0.0 0:00.03 [ksoftirqd/0] 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H] 6 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kworker/u256:0] 7 root rt 0 0 0 0 S 0.0 0.0 0:00.03 [migration/0] 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh] 9 root 20 0 0 0 0 S 0.0 0.0 0:00.53 [rcu_sched] 10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 [watchdog/0] 11 root rt 0 0 0 0 S 0.0 0.0 0:00.02 [watchdog/1] 12 root rt 0 0 0 0 S 0.0 0.0 0:00.01 [migration/1] 13 root 20 0 0 0 0 S 0.0 0.0 0:00.04 [ksoftirqd/1] 15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0H] 17 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kdevtmpfs] 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [netns] 19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [khungtaskd] 20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [writeback] 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kintegrityd]
top -bn1
一次性顯示所有信息,適合腳本使用
安裝
yum install -y epel-release yum install -y sysstat
每隔10分鐘會將系統的狀態存儲在/var/log/sa/目錄下,默認sar命令不加參數會調用/var/log/sa/目錄下的歷史文件。這些歷史文件沒法使用cat讀取!是一些二進制文件!
查看網卡流量 -n DEV
# 每隔1s輸出一次,顯示4次 [root@centos7 ~]# sar -n DEV 1 4 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22時07分26秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時07分27秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時07分27秒 ens33 1.00 0.00 0.06 0.00 0.00 0.00 0.00 22時07分27秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時07分28秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時07分28秒 ens33 2.00 1.00 0.12 0.40 0.00 0.00 0.00 22時07分28秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時07分29秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時07分29秒 ens33 2.00 1.00 0.12 0.40 0.00 0.00 0.00 22時07分29秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時07分30秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時07分30秒 ens33 1.00 1.00 0.06 0.40 0.00 0.00 0.00 平均時間: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 平均時間: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均時間: ens33 1.50 0.75 0.09 0.30 0.00 0.00 0.00
說明:
接收的數據包在某段時間內異常增多,可能被攻擊,須要注意!
查看歷史數據(只保存1個月的歷史文件)
-f /var/log/sa/saDD(DD爲文件日期的天)
[root@centos7 ~]# sar -n DEV -f /var/log/sa/sa08 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22時00分01秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時10分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時10分01秒 ens33 0.44 0.14 0.03 0.02 0.00 0.00 0.00 平均時間: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均時間: ens33 0.44 0.14 0.03 0.02 0.00 0.00 0.00 [root@centos7 ~]# sar -q -f /var/log/sa/sa08 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22時00分01秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 22時10分01秒 0 110 0.02 0.02 0.05 0 平均時間: 0 110 0.02 0.02 0.05 0
查看磁盤信息
[root@centos7 ~]# sar -b 1 5 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22時16分03秒 tps rtps wtps bread/s bwrtn/s 22時16分04秒 0.00 0.00 0.00 0.00 0.00 22時16分05秒 0.00 0.00 0.00 0.00 0.00 22時16分06秒 0.00 0.00 0.00 0.00 0.00 22時16分07秒 0.00 0.00 0.00 0.00 0.00 22時16分08秒 0.00 0.00 0.00 0.00 0.00 平均時間: 0.00 0.00 0.00 0.00 0.00
安裝
yum install -y epel-release yum install -y nload
使用左右方向鍵盤切換顯示系統的各網卡;nload命令會動態顯示網卡的IO流量,以便了解當前系統流量狀態。