centos磁盘占用(centos7卸载软件命令)

大家好,感谢邀请,今天来为大家分享一下centos磁盘占用的问题,以及和centos7卸载软件命令的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!

解决centos7.2中磁盘iowait过高(centos7启动后盘符错位问题)

(一)简述

每天都收到磁盘iowait告警信息,尤其是日志服务器在进行大量的读写操作过程中,从而造成系统处于崩溃边缘,为查找磁盘iowait由于什么原因造成的以及后续的系统的优化点。centos有许多查找问题的工具,也有高级的。

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导致系统缓慢。

[root@iZ23iod5vslZ~]# toptop- 15:38:32 up 40 days, 5:59, 3 users, load average: 0.00, 0.01, 0.05Tasks: 128 total, 1 running, 127 sleeping, 0 stopped, 0 zombieCpu(s): 0.4 us, 0.2 sy, 0.0 ni, 99.2 id, 98 wa, 0.0 hi, 0.0 si, 0.1 stKiB Mem: 32520424 total, 31492136 used, 1028288 free, 412772 buffersKiB 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改变过优先级的进程占用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 3Linux 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.34Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm utilxvda 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.88xvdb 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.35xvdc 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.12avg-cpu: user nice system iowait steal idle 0.75 0.00 0.17 0.08 0.08 98.91Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm utilxvda 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.37xvdb 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.00xvdc 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.00avg-cpu: user nice system iowait steal idle 0.75 0.00 0.17 0.00 0.00 99.08Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm utilxvda 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.27xvdb 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.30xvdc 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~]# iotopTotal DISK READ: 0.00 B/s| Total DISK WRITE: 15.67 K/sActual 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 start18987 be/4 root 0.00 B/s 3.92 K/s 0.00 0.00 cronolog/guojinbao/tomcat/logs/catalina.Y-m-d.out18796 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 start13193 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 18987COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEcronolog 18987 root cwd DIR 202,17 20480 2400258/guojinbao/tomcat/logscronolog 18987 root rtd DIR 202,1 4096 2/cronolog 18987 root txt REG 202,1 48627 152798/usr/local/sbin/cronologcronolog 18987 root mem REG 202,1 2107600 132826/usr/lib64/libc-2.17.socronolog 18987 root mem REG 202,1 160240 132819/usr/lib64/ld-2.17.socronolog 18987 root 0r FIFO 0,8 0t0 42614018 pipecronolog 18987 root 1w CHR 1,3 0t0 1028/dev/nullcronolog 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文件系统,每个进程目录下都有一个叫io的文件,里边保存这和iotop类似的信息

[root@iZ23iod5vslZ~]# cat/proc/18987/io rchar: 58891582418wchar: 58891579778syscr: 46556085syscw: 46556077read_bytes: 212992write_bytes: 59580235776cancelled_write_bytes: 0

read_bytes和write_bytes是这个进程从磁盘读写的字节数。这个例子中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的结果就是我们要查找的文件

怎么查看linux的哪个进程占用磁盘io较多

您好,很高兴为您解答。

服务器cpu使用率不高,load比较高,所以要查看一下IO。硬盘IO可以通过命令vmstat或iostat获得(也可以用yum安装dstat获得),网络IO可以用iftop命令获取。但是不知道那个进程使用硬盘IO比较高,通过查找没有找到相关命令,只好自己写个脚本进行统计处理。

本脚本在CentOS6下(kernel2.6以上)python2.6测试通过。

直接运行脚本,默认情况下收集3秒钟数据,显示读写最高的前三个进程。如用参数可以使用命令“python fhip.py 4 5 3”,第一个数位每次收集读写数据的间隔秒数,第二个数是打印出读写最多的n个进程,第三个为运行脚本的次数。因为参数部分写的比较简单那,所以用参数必须3个全写。。

#!/bin/python

#-*-coding:utf-8-*-

#Filename:ind_high_io_process

#Revision:1.0

#Date:2013-3-8

#Author:simonzhang

#web:www.simonzhang.net

#Email:simon-zzm@163.com

###ENDINITINFO

importos

importre

importsys

importtime

fromstringimportstrip

####

sys_proc_path='/proc/'

re_find_process_number='^\d+$'

####

#通过/proc/$pid/io获取读写信息

####

defcollect_info():

_tmp={}

re_find_process_dir=re.compile(re_find_process_number)

foriinos.listdir(sys_proc_path):

ifre_find_process_dir.search(i):

#获得进程名

process_name=open("%s%s/stat"%(sys_proc_path,i),"rb").read().split("")[1]

#读取io信息

rw_io=open("%s%s/io"%(sys_proc_path,i),"rb").readlines()

for_infoinrw_io:

cut_info=strip(_info).split(':')

ifstrip(cut_info[0])=="read_bytes":

read_io=int(strip(cut_info[1]))

ifstrip(cut_info[0])=="write_bytes":

write_io=int(strip(cut_info[1]))

_tmp[i]={"name":process_name,"read_bytes":read_io,"write_bytes":write_io}

return_tmp

defmain(_sleep_time,_list_num):

_sort_read_dict={}

_sort_write_dict={}

#获取系统读写数据

process_info_list_frist=collect_info()

time.sleep(_sleep_time)

process_info_list_second=collect_info()

#将读数据和写数据进行分组,写入两个字典中

forloopinprocess_info_list_second.keys():

second_read_v=process_info_list_second[loop]["read_bytes"]

second_write_v=process_info_list_second[loop]["write_bytes"]

try:

frist_read_v=process_info_list_frist[loop]["read_bytes"]

except:

frist_read_v=0

try:

frist_write_v=process_info_list_frist[loop]["write_bytes"]

except:

frist_write_v=0

#计算第二次获得数据域第一次获得数据的差

_sort_read_dict[loop]=second_read_v-frist_read_v

_sort_write_dict[loop]=second_write_v-frist_write_v

#将读写数据进行排序

sort_read_dict=sorted(_sort_read_dict.items(),key=lambda_sort_read_dict:_sort_read_dict[1],reverse=True)

sort_write_dict=sorted(_sort_write_dict.items(),key=lambda_sort_write_dict:_sort_write_dict[1],reverse=True)

#打印统计结果

print"pidprocessread(bytes)pidprocesswrite(btyes)"

for_numinrange(_list_num):

read_pid=sort_read_dict[_num][0]

write_pid=sort_write_dict[_num][0]

res="%s"%read_pid

res+=""*(8-len(read_pid))+process_info_list_second[read_pid]["name"]

res+=""*(12-len(process_info_list_second[read_pid]["name"]))+"%s"%sort_read_dict[_num][1]

res+=""*(12-len("%s"%sort_read_dict[_num][1]))+write_pid

res+=""*(8-len(write_pid))+process_info_list_second[write_pid]["name"]

res+=""*(12-len("%s"%process_info_list_second[write_pid]["name"]))+"%s"%sort_write_dict[_num][1]

printres

print"\n"*1

if__name__=='__main__':

try:

_sleep_time=sys.argv[1]

except:

_sleep_time=3

try:

_num=sys.argv[2]

except:

_num=3

try:

loop=sys.argv[3]

except:

loop=1

foriinrange(int(loop)):

main(int(_sleep_time),int(_num))

如若满意,请点击【采纳答案】,如若还有问题,请点击【追问】

希望我的回答对您有所帮助,望采纳!

~ O(∩_∩)O~

CentOS 磁盘满了排查思路以及解决方法

当 CentOS服务器磁盘空间不足时,通常会引发一系列问题,如终端命令行空间受限,自动补全功能失效,数据库空间不足导致写入数据异常等。以下为排查和解决 CentOS磁盘满问题的思路和方法。

排查思路:

1.**查看磁盘占用情况**:使用 `df-hl`命令检查磁盘空间使用情况,重点关注使用率较高的分区。

2.**确定占用空间的文件**:使用 `du-h`命令找出占用空间较大的文件和目录。

3.**进入对应目录**:根据 `du`命令的结果,定位到具体目录深入排查。

4.**找出真正占用空间的文件**:在对应目录下,找到真正占用大量空间的文件,决定是迁移还是删除。

解决方法:

**方法1:**找出被删除但仍有进程占用的文件。这些文件可能较多,需要耐心排查,找到后结束进程或重启服务。

**方法2:**对于不能停止的进程,可以尝试通过清空文件来释放空间,但需确保此操作不会破坏文件内容。

其他解决方法:

5.**批量删除文件**:使用 `find`命令进行批量删除,如删除以7开头命名的文件夹,删除特定日期之前的图片,或删除365天前创建的 `.jpg`结尾的文件。

需要注意的是,处理磁盘空间不足的问题时,要谨慎操作,避免误删重要数据或破坏系统运行。在执行批量删除前,务必备份关键文件和数据,确保操作的安全性和可靠性。

阅读剩余
THE END