衆所周知,生病了需要去醫院看病,大夫會問哪裏不舒服,然後通過觀察和自己的經驗,大體上就能判斷我們得的什麼病。linux 不會說話,它不會主動告訴我們哪裏出現了問題,需要我們自己去觀察。那麼如何評估系統運行狀態是否良好呢?下面就來一一介紹。
使用 w 命令查看當前系統的負載
[root@evan-01 ~]# w
10:45:48 up 0 min, 1 user, load average: 0.39, 0.13, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.94.1 10:45 4.00s 0.07s 0.03s w
[root@evan-01 ~]#
第一行從左到右分別是:時間、系統運行時間、用戶登錄數、平均負載。
從第二行開始的所有行都是告訴我們:當前登錄的用戶名、登錄的終端、登錄地址、登錄時間、空閒了多長時間…
這個部分是非常重要的
load average: 0.39, 0.13, 0.05
第 1 個數值表示 1 分鐘內系統的平均負載值,第 2 個數值表示 5 分鐘內系統的平均負載值,第 3 個數值表示 15 分鐘內系統的平均負載值。我們着重看第 1 個值,它表示單位時間段內使用 CPU 的活動進程數(在這裏其實也就是 1 分鐘內)值越大說明服務器壓力越大。一般情況下,這個值只要不超過服務器的 CPU 數量就沒有關係。如果服務器的 CPU 數量爲 8 ,那麼值小於 8 就說明當前服務器沒有壓力;否則就要關注一下了
查看 CPU 信息
[root@evan-01 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
stepping : 9
microcode : 0x8e
cpu MHz : 2800.000
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm 3dnowprefetch epb fsgsbase smep xsaveopt xsavec xgetbv1 dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 5616.00
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
[root@evan-01 ~]#
processor 如果是 0 就代表有一顆 CPU(邏輯CPU)
使用 uptime 這個命令也可以查看3個時間段的負載數值
[root@evan-01 ~]# uptime
10:50:27 up 5 min, 1 user, load average: 0.01, 0.06, 0.05
[root@evan-01 ~]#