CentOS故障排除详解(2): 进程相关
在這篇文章中, 將會了解到如何使用ps/vmstat/top等命令確認進程相關信息, 以及使用iotop/iostat/lsof確認當前信息,以及如何使用systemd在centos下進行服務的管理。
顯示內存信息
| free -b | 以byte單位顯示內存信息 |
| free -k | 以Kbyte單位顯示內存信息 |
| free -m | 以Mbyte單位顯示內存信息 |
| free -g | 以Gbyte單位顯示內存信息 |
顯示swap信息(free)
[root@liumiaocn ~]# free -mtotal used free shared buff/cache available Mem: 977 712 72 2 193 76 Swap: 2047 646 1401 [root@liumiaocn ~]#顯示swap信息(文件)
[root@liumiaocn ~]# cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 2097148 660212 -1 [root@liumiaocn ~]#/proc/sys/vm/swappiness
[root@liumiaocn ~]# cat /proc/sys/vm/swappiness 30 [root@liumiaocn ~]# 此值為0-100范圍,30的意思是當內存70%被使用后,swap內存開始使用swap其他命令
除此之外,還有sysctl -w vm.swappiness=X/swapoff -a/swapon -a等命令可以用于swap相關操作
vmstat
vmstat也可以用于查看內存相關信息,比如vmstat -a
[root@liumiaocn ~]# vmstat procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st3 0 656988 60880 0 213068 255 257 1672 817 279 552 4 2 94 1 0 [root@liumiaocn ~]#| si | This column shows the value swapped in from disk |
| so | This column shows the value swapped out to disk |
| bi | This column shows the value sent to block devices |
| bo | This column shows the value received from block devices |
| us | This column shows the user time |
| sy | This column shows the system time |
| id | This column shows the idle time |
vmstat 1 2
以1秒為間隔,進行兩次vmstat操作后退出
[root@liumiaocn ~]# vmstat 1 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st3 0 659108 83376 0 198864 249 251 1630 797 275 548 3 2 94 1 01 0 659084 83376 0 198888 4 0 4 0 133 411 0 0 100 0 0 [root@liumiaocn ~]#vmstat 1
以1秒為間隔,一直作vmstat操作
vmstat -t 1 2
以1秒為間隔,進行兩次vmstat操作后退出, 會列出兩次命令執行時的時間信息
[root@liumiaocn ~]# vmstat -t 1 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----r b swpd free buff cache si so bi bo in cs us sy id wa st EST4 0 656952 80324 0 199540 245 247 1603 784 273 545 3 2 94 1 0 2017-01-22 19:11:050 0 656948 80324 0 199528 0 0 0 0 107 353 0 0 100 0 0 2017-01-22 19:11:06 [root@liumiaocn ~]#vmstat -S M 1 2
以MB為單位顯示結果信息
[root@liumiaocn ~]# vmstat -S M 1 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st6 0 639 75 0 195 0 0 1578 772 270 543 3 2 94 1 01 0 639 75 0 195 0 0 4 0 116 377 1 1 98 0 0 [root@liumiaocn ~]# vmstat 1 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st3 0 654568 77408 0 199792 242 242 1576 771 270 542 3 2 94 1 00 0 654564 77408 0 199792 0 0 0 0 123 373 0 1 99 0 0 [root@liumiaocn ~]#top命令
top命令時用來檢查系統RAM和CPU信息的標準命令。
top -u admin
顯示出admin用戶所有的信息
top -n 2
兩次循環之后推出top命令
iotop
iotop命令可以用來監視磁盤I/O,最小安裝不包含該命令,所以需要用如下命令進行安裝
yum install iotop| iotop | 顯示磁盤I/O相關信息 |
| iotop -o | 僅顯示活動中的磁盤I/O的相關信息 |
iostat
iostat像vmstat一樣,只不過iostat是用于CPU以及磁盤I/O相關信息確認
[root@liumiaocn ~]# iostat Linux 3.10.0-327.el7.x86_64 (liumiaocn) 01/22/2017 _x86_64_ (1 CPU)avg-cpu: %user %nice %system %iowait %steal %idle2.89 0.01 1.51 0.45 0.00 95.14Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 35.87 1068.79 475.86 8833449 3932944 scd0 0.00 0.01 0.00 44 0 dm-0 24.45 863.54 269.25 7137068 2225343 dm-1 102.71 204.56 206.36 1690640 1705540 dm-2 18.11 264.64 187.13 2187192 1546636 dm-3 10.58 204.14 27.12 1687240 224155[root@liumiaocn ~]#iostat -c 1
每隔1秒輸出cpu相關信息
[root@liumiaocn ~]# iostat -c 1 Linux 3.10.0-327.el7.x86_64 (liumiaocn) 01/22/2017 _x86_64_ (1 CPU)avg-cpu: %user %nice %system %iowait %steal %idle2.83 0.01 1.48 0.44 0.00 95.24avg-cpu: %user %nice %system %iowait %steal %idle0.00 0.00 1.02 0.00 0.00 98.98avg-cpu: %user %nice %system %iowait %steal %idle1.03 0.00 0.00 0.00 0.00 98.97 ...iostat 1
每1秒輸出一次信息
iostat -t 1
每1秒輸出一次信息,同時輸出時間信息
lsof
lsof = list open file。 一般用于故障排除時已知某一端口被使用,順藤摸瓜找到使用此端口的進程時非常有效
uptime
用以確認系統啟動的時間
systemd相關
| systemctl status service | 確認 |
| systemctl start service | 啟動 |
| systemctl stop service | 停止 |
| systemctl enable service | 有效 |
| systemctl disable service | 無效 |
| systemd-cgtop | 按照使用量列出cgroup信息 |
| systemd-cgls | 列出cgroup信息 |
| systemctl list-units --type service | 列出service |
| systemctl list-units --type mount | type mount |
| systemctl list-dependencies .service | 依賴 |
參考文檔
The Red Hat Enterprise Linux 7 System Administrators guide:
https://access.redhat.com/documentation/enUS/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/chapManaging_Services_with_systemd.html
The Swappiness Wikipedia page:
http://en.wikipedia.org/wiki/Swappiness
The vmstat command Wikipedia page:
http://en.wikipedia.org/wiki/Vmstat
The iostat command Wikipedia page:
http://en.wikipedia.org/wiki/Iostat
The lsof command Wikipedia page:
http://en.wikipedia.org/wiki/Lsof
The kill command Wikipedia page:
http://en.wikipedia.org/wiki/Kill_(command)
The pkill command Wikipedia page:
http://en.wikipedia.org/wiki/Pkill
SysVinit to Systemd Cheatsheet:
https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet
The Orphans Wikipedia page:
http://en.wikipedia.org/wiki/Orphan_process
總結
以上是生活随笔為你收集整理的CentOS故障排除详解(2): 进程相关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 2859 Phalanx(二维D
- 下一篇: Sql Server常用函数及技巧