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 ~]#


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