linux ,系統管理技巧

查看磁盤狀態命令

iostat -x   磁盤使用   # 查看 tm  %util  說明的等待的佔比是多少,數值越大說明磁盤太差

iotop 磁盤使用       # 具體查看哪個佔用的數據大

# 更詳細的查看磁盤狀態


free  查看內存的使用情況

free -h   以Gb的單位顯示

[root@localhost ~]# free -h     #單位是GB
             total       used       free     shared    buffers     cached
Mem:          987M       377M       609M       6.8M       692K       216M
-/+ buffers/cache:       160M       826M
Swap:         2.0G         0B       2.0G

cashe  緩存

buffer      暫存


ps  #查看進程的命令,查看當前的進程的情況

ps   aux    #列出當前系統進程的使用情況

ps -elf     #查看當前系統進程的使用情況



[root@localhost ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.6  44132  6712 ?        Ss   06:47   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 2
root         2  0.0  0.0      0     0 ?        S    06:47   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    06:47   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   06:47   0:00 [kworker/0:0H]


PID    #用於某個時候殺死進程   #結束3個這個進程

用法:kill 3   (有時這樣並不能終止進程,可以使用,kill -9 +pid)

stat :進程狀態,進程狀態可以分爲以下幾種

D:不能中斷的進程(通常稱爲io)

R:run 正在運行的進程,其中包括等待cpu時間片段的進程

S:(sleep):已經中斷的進程,通常情況下,系統大部分的進程都是這個狀態

T:已停止或是暫停的進程

Z:殭屍進程,即殺不死,佔用系統一點資源的進程

<:高優先進程

L:在內存中被鎖了存存分頁

s:主進程

I:多線程進程

+:在前臺運行的進行


ps 查看系統進程的方法,使用最多,通常都是和管道符配合使用:

例如:ps aux |grep -c  shsd    #查看sshd  進程數量

          ps aux |grep sshd         # 查看sshd 的進程

[root@localhost ~]#
[root@localhost ~]# ps aux |grep -c root
208
[root@localhost ~]# ps -elf |grep root
4 S root         1     0  0  80   0 - 11033 ep_pol 06:47 ?        00:00:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
1 S root         2     0  0  80   0 -     0 kthrea 06:47 ?        00:00:00 [kthreadd]
1 S root         3     2  0  80   0 -     0 smpboo 06:47 ?        00:00:00 [ksoftirqd/0]
1 S root         5     2  0  60 -20 -     0 worker 06:47 ?        00:00:00 [kworker/0:0H]


netstat   #查看網絡狀態  實則是查看網絡狀態


[root@localhost ~]# netstat -lnp   #查看監聽端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1429/master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1112/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1429/master
tcp6       0      0 :::22                   :::*                    LISTEN      1112/sshd
udp        0      0 0.0.0.0:58409           0.0.0.0:*                           535/avahi-daemon: r
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           535/avahi-daemon: r
raw6       0      0 :::58                   :::*                    7           616/NetworkManager



netstat -an  #  查看系統的網絡連接狀況

[root@localhost ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0     64 192.168.12.111:22       192.168.12.1:50236      ESTABLISHED
tcp6       0      0 ::1:25                  :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
udp        0      0 0.0.0.0:58409           0.0.0.0:*
udp        0      0 0.0.0.0:5353            0.0.0.0:*
raw6       0      0 :::58                   :::*                    7

netstat -lntp  #只看出tcp的,不包含socket

[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1429/master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1112/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1429/master
tcp6       0      0 :::22                   :::*                    LISTEN      1112/sshd
[root@localhost ~]#


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章