Linux运维常用维护命令记录

2020-01-30 16:44:42于海丽

[root@tiejiang ~]# ps -auxww|awk '{print $5,$1,$11}'|sort -r|more (按照内存使用量排序)

按内存的大到小排序

按虚拟内存从大到小排列进程:

[root@tiejiang ~]# ps -eo "%C%p%z%a"|sort -k3 -nr

按实际使用内存百分比排序

[root@tiejiang ~]# ps -eo user,pid,size,pmem,vsize,command|sort -k4 -nr|more

查看并发访问用户的前10位

[root@tiejiang ~]# netstat -anp|grep 80|grep ESTAB|awk '{print $5}'|awk -F ':' '{print $1}'|sort |uniq -c|sort -rn|head -n 10

对cpu访问量高进程排序

[root@tiejiang ~]# ps -eo user,pid,size,pmem,vsize,command,%cpu|sort -k7 -nr|more

(25)1080p硬盘(2t容量)挂载在115.182.51.25(Centos系统)上时会会报错,初步估计是由于Linux系统对移动硬盘容量的限制引起的问题,而在挂载我自己的移动硬盘时没有出现此情况。

错误情况:“the partition table is corrupt (partition is smaller than NTFS)”

linux系统挂载ntfs

需要安装ntfs-3f fuse

(26)查看进程打开的文件:

[root@tiejiang ~]# lsof -p PID

(27)杀死某一进程,杀死Nginx进程(杀死某一进程)

[root@tiejiang ~]# ps -ef|grep -v grep |grep nginx|awk '{print $2}' 或

[root@tiejiang ~]# for i in ps aux | grep nginx | grep -v grep | awk {'print $2'} ; do kill $i; done

(28)清空Linux Buffer Cache

[root@tiejiang ~]# sync && echo 3 > /proc/sys/vm/drop_caches

(29)Linux测试硬盘读写速度

time有计时作用,dd用于复制,从if读出,写到of。if=/dev/zero不产生IO,因此可以用来测试纯写速度。同理of=/dev/null不产生IO,可以用来测试纯读速度。bs是每次读或写的大小,即一个块的大小,count是读写块的数量。

1.测/目录所在磁盘的纯写速度:

[root@tiejiang / ]# time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file

2.测/目录所在磁盘的纯读速度:

dd if=/kvm/ftp/other/1Gb.file bs=64k |dd of=/dev/null

3.测读写速度(这是什么):

[root@tiejiang ~]# dd if=/vat/test of=/oradata/test1 bs=64k

理论上复制量越大测试越准确。

(30)Crontab中用什么命令定义某个程序执行的优先级别

nice/renice:进程执行优先级

概念:

进程优先级:系统按进程优先级的不同分配CPU时间,优先级高的进程会得到更多的CPU使用时间,以提高速度,缩短总的执行时间。

进程优先级范围:-20至19

最高等级:-20

最低等级:19

系统管理员有权将进程优先级设置为-1至-20,而普通用户只能设置0至19。

进程运行的默认等级为0。

用nice执行的进程其默认等级为10(即nice <程序名>,不指定等级时)。

格式:

nice <程序名>

nice -<等级> <程序名>

如:(命令后加&表示以后台运行)

vi & 优先等级0,默认等级。