新聞中心
(一)簡述
每天都收到磁盤iowait告警信息,尤其是日志服務器在進行大量的讀寫操作過程中,從而造成系統(tǒng)處于崩潰邊緣,為查找磁盤iowait由于什么原因造成的以及后續(xù)的系統(tǒng)的優(yōu)化點。centos有許多查找問題的工具,也有高級的。

成都創(chuàng)新互聯(lián)專注于扎賚諾爾網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供扎賚諾爾營銷型網站建設,扎賚諾爾網站制作、扎賚諾爾網頁設計、扎賚諾爾網站官網定制、小程序開發(fā)服務,打造扎賚諾爾網絡公司原創(chuàng)品牌,更為您提供扎賚諾爾網站排名全網營銷落地服務。
I/O Wait 就是一個需要使用高級的工具來debug的問題,當然也有許多基本工具的高級用法。I/O wait的問題難以定位的原因 是因為我們有很多工具可以告訴你說I/O 受限了,但是并沒有告訴你具體是哪些進程們引起的。
具體的思路如下:top 。查看由cpu一行浪費在iowait上的cpu百分比 =>iostat -x 2 5 查看某塊磁盤正在被寫入 => iotop 查找最高的磁盤I/O對應的進程 => lsof -p pid 查看通過一個進程打開所有文件或打開一個文件的所有進程。
(二)具體步驟如下:
(1)通過top命令來確認是否是I/O導致系統(tǒng)緩慢。
[root@iZ23iod5vslZ ~]# top
top - 15:38:32 up 40 days, 5:59, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 128 total, 1 running, 127 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.4 us, 0.2 sy, 0.0 ni, 99.2 id, 98 wa, 0.0 hi, 0.0 si, 0.1 st
KiB Mem: 32520424 total, 31492136 used, 1028288 free, 412772 buffers
KiB Swap: 0 total, 0 used, 0 free. 25902892 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18988 root 20 0 11.647g 3.611g 7896 S 2.7 11.6 507:57.30 java
28 root 20 0 0 0 0 S 0.3 0.0 6:43.31 rcuos/3
1 root 20 0 49556 3412 1912 S 0.0 0.0 0:14.60 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:48.28 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.83 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.00 rcuob/0
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/1
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/2
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/3
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/4
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/5
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/6
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/7
從Cpu一行我們可以看到浪費在I/O Wait上的CPU百分比;這個數字越高說明越多的CPU資源在等待I/O權限.具體的解釋如下:
0.4% us 用戶空間占用CPU的百分比。
0.2% sy 內核空間占用CPU的百分比。
0.0% ni 改變過優(yōu)先級的進程占用CPU的百分比
2% id 空閑CPU百分比
98% wa IO等待占用CPU的百分比
0.0% hi 硬中斷(Hardware IRQ)占用CPU的百分比
0.0% si 軟中斷(Software Interrupts)占用CPU的百分比
在這里CPU的使用比率和windows概念不同,如果你不理解用戶空間和內核空間,需要充充電了
(2)通過iostat -x 3 3 查看那塊磁盤正在被寫入。
[root@iZ23iod5vslZ ~]# iostat -x 3 3
Linux 3.10.0-123.9.3.el7.x86_64 (iZ23iod5vslZ) 08/14/2017 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.70 0.00 0.16 0.75 0.05 98.34
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 21.18 0.32 18.33 9.94 195.06 21.98 0.08 4.11 11.44 3.98 1.54 2.88
xvdb 0.00 15.21 1.23 1.98 38.41 68.76 66.70 0.08 25.48 3.59 39.10 1.09 0.35
xvdc 0.00 0.07 0.00 0.91 0.00 36.25 79.43 0.10 106.88 12.53 106.92 1.33 0.12
avg-cpu: %user %nice %system %iowait %steal %idle
0.75 0.00 0.17 0.08 0.08 98.91
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 2.33 0.00 0.67 0.00 12.00 36.00 0.00 5.50 0.00 5.50 5.50 0.37
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
0.75 0.00 0.17 0.00 0.00 99.08
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 3.33 0.00 1.67 0.00 34.67 41.60 0.01 3.00 0.00 3.00 1.60 100.27
xvdb 0.00 9.00 0.00 1.67 0.00 42.67 51.20 0.01 5.40 0.00 5.40 1.80 0.30
xvdc 0.00 0.33 0.00 0.67 0.00 4.00 12.00 0.00 2.00 0.00 2.00 2.00 0.13
每隔三秒更新一次,一共打印了三次。 -x時打印出擴展選項。第一次打印的信息可以被忽略,剩下的報告,都是基于上一次間隔的時間打印出來。
上述的列子中xvda的 %util(利用率)是100.27%,有進程往磁盤中寫入數據。
(3)通過iotop查找高I/O對應的進程
[root@iZ23iod5vslZ ~]# iotop
Total DISK READ : 0.00 B/s | Total DISK WRITE : 15.67 K/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
18793 be/4 root 0.00 B/s 3.92 K/s 0.00 % 0.00 % java -Djava.util.logging.config.file=/usr/to~p org.apache.catalina.startup.Bootstrap start
18987 be/4 root 0.00 B/s 3.92 K/s 0.00 % 0.00 % cronolog /guojinbao/tomcat/logs/catalina.%Y-%m-%d.out
18796 be/4 root 0.00 B/s 3.92 K/s 0.00 % 0.00 % java -Djava.util.logging.config.file=/usr/to~p org.apache.catalina.startup.Bootstrap start
13193 be/4 root 0.00 B/s 3.92 K/s 0.00 % 0.00 % java -Djava.util.logging.config.file=/usr/to~p org.apache.catalina.startup.Bootstrap start
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 22
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]
16388 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % AliYunDun
5 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]
16390 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % AliYunDun
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 % [rcuob/0]
10 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcuob/1]
11 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcuob/2]
從上述的例子中可以看出進程號為cronolog18987占用了大量的磁盤IO
(4)通過lsof -p pid查找由那個文件引起的IOwait
[root@iZ23iod5vslZ ~]# lsof -p 18987
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cronolog 18987 root cwd DIR 202,17 20480 2400258 /guojinbao/tomcat/logs
cronolog 18987 root rtd DIR 202,1 4096 2 /
cronolog 18987 root txt REG 202,1 48627 152798 /usr/local/sbin/cronolog
cronolog 18987 root mem REG 202,1 2107600 132826 /usr/lib64/libc-2.17.so
cronolog 18987 root mem REG 202,1 160240 132819 /usr/lib64/ld-2.17.so
cronolog 18987 root 0r FIFO 0,8 0t0 42614018 pipe
cronolog 18987 root 1w CHR 1,3 0t0 1028 /dev/null
cronolog 18987 root 2u CHR 136,0 0t0 3 /dev/pts/0 (deleted)
cronolog 18987 root 3w REG 202,17 5704875979 2400280 /guojinbao/tomcat/logs/catalina.2017-08-14.out
lsof 命令可以展示一個進程打開的所有文件,或者打開一個文件的所有進程。從這個列表中,我們可以找到具體是什么文件被寫入,根據文件的大小和/proc中io文件的具體數據.
為了確認我們的懷疑,我們可以使用 /proc文件系統(tǒng),每個進程目錄下都有一個叫io的文件,里邊保存這和iotop類似的信息
[root@iZ23iod5vslZ ~]# cat /proc/18987/io
rchar: 58891582418
wchar: 58891579778
syscr: 46556085
syscw: 46556077
read_bytes: 212992
write_bytes: 59580235776
cancelled_write_bytes: 0
read_bytes和write_bytes是這個進程從磁盤讀寫的字節(jié)數。這個例子中cronolog讀取了212992byte(0.2M)數據,寫入了59580235776bytes(55.4G)數據到磁盤上。
(5)通過df -h /guojinbao來查看服務器那塊磁盤的根目錄
[root@iZ23iod5vslZ ~]# df -h /guojinbao/
Filesystem Size Used Avail Use% Mounted on
/dev/xvdb1 45G 38G 4.7G 89% /guojinbao
最后,通過以上的信息我們可以放心的說lsof的結果就是我們要查找的文件
文章標題:CentOS7.2中磁盤iowait過高解決
URL網址:http://m.fisionsoft.com.cn/article/cojssch.html


咨詢
建站咨詢
