1、查看磁盘
2、查看CPU
3、查看内存
4、查看负载
5、进程基础命令
1、查看磁盘
df -hl : 查看磁盘使用情况
[root@linux-node1 ~]# df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 37G 2.9G 35G 8% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 910M 16K 910M 1% /dev/shm
tmpfs 910M 34M 877M 4% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 182M 0 182M 0% /run/user/0
df -h /home :查看指定目录磁盘使用情况
[root@linux-node1 ~]# df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 37G 2.9G 35G 8% /
du -sh ./*|grep G : 查看当前目录下个文件大于1G的文件夹
[root@linux-node1 /]# du -sh ./*|grep G
2.2G ./usr
1.2G ./home
find / -type f -size +10M -a -size -100M -print0 | xargs -0 du -h | sort -nr : 查找文件大于10M小于100M,倒序排列
[root@linux-node1 /]# find / -type f -size +10M -a -size -100M -print0 | xargs -0 du -h | sort -nr
85M /usr/bin/docker
80M /var/lib/rpm/Packages
48M /usr/bin/containerd
47M /boot/initramfs-0-rescue-8b956f09fe0549c4b6182589acceab30.img
find / -type f -size +10M -a -size -100M # 查找根文件夹下大于 10M小于 100M
2、查看CPU
killcpu.sh 编写一个脚本耗尽CPU
[root@linux-node1 aaa]# killcpu.sh # 编写一个shell脚本耗尽cpu
#!/bin/bash
i=1
while true
do
i=i+100;
i=100
done
[root@linux-node1 aaa]# nohup ./killcpu.sh & # 后台运行脚本测试
top :查看cpu 内存等使用情况
[root@linux-node1 /]# top
top - 03:24:29 # 表示当前时间
up 4 days, 22:56, # 系统已经运行时间
2 users, # 当前登录用户数
load average: 0.01, 0.03, 0.05 # 系统负载,即任务队列的平均长度。 三个数值分别为 1分钟、5分钟、15分钟前到现在的平均值
Tasks: 123 total(进程总数), 2 running(正在运行进程数), 121 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0
us, 0.0 # 用户空间占用CPU百分比
sy, 0.0 # 内核空间占用CPU百分比
ni,100.0 # 用户进程空间内改变过优先级的进程占用CPU百分比
id, 0.0 # 空闲CPU百分比
wa, 0.0 # 等待输入输出的CPU时间百分比
hi, 0.0 # 硬中断(Hardware IRQ)占用CPU的百分比
si, 0.0 # 软中断(Software Interrupts)占用CPU的百分比
st
KiB Mem : 1863224 total(物理内存总量), 219592 free, 498732 used, 1144900 buff/cache #
KiB Swap: 2097148 total(交换区总量), 2094580 free, 2568 used. 1043628 avail Mem #
进程id 进程所有者 优先级
PID USER PR RES SHR S %CPU %MEM TIME+ COMMAND
6583 root 20 5156 3796 S 0.3 0.3 10:54.90 vmtoolsd
7284 root 20 2252 1580 R 0.3 0.1 0:00.03 top
1 root 20 3844 2436 S 0.0 0.2 2:04.28 systemd
sar -u 1 5 : 每1秒采集一次CPU使用率,共采集5次
[root@linux-node1 /]# yum install sysstat # 安装sar工具
[root@linux-node1 /]# sar -u 1 5 # 每1秒采集一次CPU使用率,共采集5次
03:58:40 AM CPU %user %nice %system %iowait %steal %idle
03:58:41 AM all 0.00 0.00 3.61 0.00 0.00 96.39
03:58:42 AM all 0.00 0.00 0.00 0.00 0.00 100.00
03:58:43 AM all 0.00 0.00 0.00 0.00 0.00 100.00
Average: all 0.00 0.00 0.62 0.00 0.00 99.38
cat /proc/cpuinfo : 查看CPU基本信息
[root@linux-node1 ~]# cat /proc/cpuinfo
processor : 0 # 系统中逻辑处理核的编号
vendor_id : GenuineIntel # CPU制造商
cpu family : 6 # CPU产品系列代号
model : 142 # CPU属于其系列中的哪一代的代号
model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz # CPU属于的名字及其编号、标称主频
stepping : 9 # CPU属于制作更新版本
cache size : 4096 KB # CPU二级缓存大小
physical id : 0 # 单个CPU的标号
siblings : 1 # 单个CPU逻辑物理核数
cpu cores : 1 # cpu个数
cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l :查看CPU个数
[root@linux-node1 ~]# cat /proc/cpuinfo
processor : 0 # 系统中逻辑处理核的编号
vendor_id : GenuineIntel # CPU制造商
cpu family : 6 # CPU产品系列代号
model : 142 # CPU属于其系列中的哪一代的代号
model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz # CPU属于的名字及其编号、标称主频
stepping : 9 # CPU属于制作更新版本
cache size : 4096 KB # CPU二级缓存大小
physical id : 0 # 单个CPU的标号
siblings : 1 # 单个CPU逻辑物理核数
cpu cores : 1 # cpu个数
3、查看内存
kill_memory.sh 编写一个脚本消耗内存
#!/bin/bash
mkdir /tmp/memory
mount -t tmpfs -o size=1024M tmpfs /tmp/memory
dd if=/dev/zero of=/tmp/memory/block
sleep 3600
rm /tmp/memory/block
umount /tmp/memory
rmdir /tmp/memory
# 1. 挂载tmpfs文件系统最大1024M到 /tmp/memory 文件夹中
# mount -t tmpfs -o size=1024M tmpfs /tmp/memory
# 2. dd if=/dev/zero of=/tmp/memory/block
# dd:用指定大小的块拷贝一个文件
# if=/dev/zero (指定拷贝的源文件为/dev/zero)
# of=/tmp/memory/block (将文件拷贝到 /tmp/memory/block 文件夹)
free -m :查询内存详情
[root@linux-node1 ~]# free -m
total used free shared buff/cache available
Mem: 1819 486 190 32 1142 1020
Swap: 2047 2 2045
总内存 已使用 可用空间 多进程共享内存 磁盘缓存大小
cat /proc/meminfo :查看内存详细信息
[root@linux-node1 ~]# cat /proc/meminfo
MemTotal: 1863224 kB
MemFree: 195568 kB
MemAvailable: 1044924 kB
Buffers: 0 kB
vmstat -s : 显示内存使用详细信息
[root@linux-node1 ~]# vmstat -s
1863224 K total memory
497780 K used memory
599272 K active memory
620812 K inactive memory
188652 K free memory
0 K buffer memory
1176792 K swap cache
2097148 K total swap
2568 K used swap
2094580 K free swap
608294 non-nice user cpu ticks
625 nice user cpu ticks
539067 system cpu ticks
63631049 idle cpu ticks
15051 IO-wait cpu ticks
0 IRQ cpu ticks
10324 softirq cpu ticks
0 stolen cpu ticks
420669 pages paged in
3118282 pages paged out
7 pages swapped in
627 pages swapped out
73440819 interrupts
111933117 CPU context switches
1574604468 boot time
1097163 forks
vmstat
[root@linux-node1 shdir]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 2568 181696 0 1057272 0 0 9 52 107 155 2 1 97 0 0
r # 表示运行队列(就是说多少个进程真的分配到CPU),当这个值超过了CPU数目,就会出现CPU瓶颈了。
b # 表示阻塞的进程,这个不多说,进程阻塞,大家懂的。
swpd # 虚拟内存已使用的大小,如果大于0,表示你的机器物理内存不足了
free #空闲的物理内存的大小,我的机器内存总共8G,剩余3415M。
buff # 用来存储目录里面有什么内容,权限等的缓存,我本机大概占用300多M
cache # cache直接用来记忆我们打开的文件,给文件做缓冲
si # 每秒从磁盘读入虚拟内存的大小,如果这个值大于0,表示物理内存不够用或者内存泄露了,要查找耗内存进程解决掉。
so # 每秒虚拟内存写入磁盘的大小,如果这个值大于0,表示物理内存不够用或者内存泄露了,要查找耗内存进程解决掉。
bi # 块设备每秒接收的块数量,当处理拷贝大量数据(2-3T)的机器上看过可以达到140000/s,磁盘写入速度差不多140M每秒
bo # 块设备每秒发送的块数量,例如我们读取文件,bo就要大于0。bi和bo一般都要接近0,不然就是IO过于频繁,需要调整。
in # 每秒CPU的中断次数,包括时间中断
cs # 每秒上下文切换次数,例如我们调用系统函数,就要进行上下文切换,线程的切换,也要进程上下文切换,这个值要越小越好
us # 用户CPU使用百分比
sy # 系统CPU使用百分比
id # idle(空闲CPU百分比),一般来说,id + us + sy = 100,一般我认为id是空闲CPU使用率,us是用户CPU使用率,sy是系统CPU使用率。
wt # 等待IO CPU时间(大于0代表系统资源不足)
4、查看负载
那么什么是系统平均负载呢?
'''那么什么是系统平均负载呢?'''
# 1. 系统平均负载是指在特定时间间隔内运行队列中的平均进程数。
# 2. 如果每个CPU内核的当前活动进程数不大于3的话,那么系统的性能是良好的。
# 3. 如果每个CPU内核的任务数大于5,那么这台机器的性能有严重问题。
# 4. 如果你的linux主机是1个双核CPU的话,当Load Average 为6的时候说明机器已经被充分使用了。
# 5. 1可以被认为是最优的负载值。负载是会随着系统不同改变得。
# 6. 单CPU系统1-3和SMP系统6-10都是可能接受的。
uptime : 查询系统当前负载信息
[root@linux-node1 ~]# uptime
21:03:50 up 5 days, 5:14, 2 users, load average: 0.02, 0.04, 0.05
'''显示内容说明:'''
10:19:04 # 系统当前时间
up 257 days, 18:56 # 主机已运行时间,时间越大,说明你的机器越稳定。
12 user # 用户连接数,是总连接数而不是用户数
load average # 系统平均负载,统计最近1,5,15分钟的系统平均负载
cat /proc/loadavg :查看负载信息
[root@linux-node1 ~]# cat /proc/loadavg
0.00 0.01 0.05 2/384 4482
# 0.00 0.01 0.05 表示最近1分钟,5分钟,15分钟 系统的平均负载; 系统负载越高,代表CPU越繁忙;
# 2/384 2代表此时运行队列中的进程个数;384 代表系统中进程的总数
# 4482 代表到此为止创建的最后一个进程的ID.
5、进程基础命令
ps -ef|grep python : 查看python相关进程
[root@linux-node1 ~]# ps -ef|grep python
root 6852 1 0 Nov23 ? 00:01:23 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 37276 1 0 Nov24 ? 00:00:25 /usr/bin/python /usr/bin/salt-master
root 37285 37276 0 Nov24 ? 00:00:00 /usr/bin/python /usr/bin/salt-master
ps -aux | grep python :查看python相关进程
[root@linux-node1 ~]# ps -aux | grep python
root 6852 0.0 0.8 573820 16424 ? Ssl Nov23 1:23 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 37276 0.0 2.1 389128 40640 ? Ss Nov24 0:25 /usr/bin/python /usr/bin/salt-master
root 37285 0.0 1.0 306196 20276 ? S Nov24 0:00 /usr/bin/python /usr/bin/salt-master
top : 显示当前正在运行的进程
[root@linux-node1 /]# top
top - 03:24:29 # 表示当前时间
up 4 days, 22:56, # 系统已经运行时间
2 users, # 当前登录用户数
load average: 0.01, 0.03, 0.05 # 系统负载,即任务队列的平均长度。 三个数值分别为 1分钟、5分钟、15分钟前到现在的平均值
Tasks: 123 total(进程总数), 2 running(正在运行进程数), 121 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0
us, 0.0 # 用户空间占用CPU百分比
sy, 0.0 # 内核空间占用CPU百分比
ni,100.0 # 用户进程空间内改变过优先级的进程占用CPU百分比
id, 0.0 # 空闲CPU百分比
wa, 0.0 # 等待输入输出的CPU时间百分比
hi, 0.0 # 硬中断(Hardware IRQ)占用CPU的百分比
si, 0.0 # 软中断(Software Interrupts)占用CPU的百分比
st
KiB Mem : 1863224 total(物理内存总量), 219592 free, 498732 used, 1144900 buff/cache #
KiB Swap: 2097148 total(交换区总量), 2094580 free, 2568 used. 1043628 avail Mem #
进程id 进程所有者 优先级
PID USER PR RES SHR S %CPU %MEM TIME+ COMMAND
6583 root 20 5156 3796 S 0.3 0.3 10:54.90 vmtoolsd
7284 root 20 2252 1580 R 0.3 0.1 0:00.03 top
1 root 20 3844 2436 S 0.0 0.2 2:04.28 systemd
pgrep -ln sshd : 通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行
[root@linux-node1 ~]# pgrep -ln sshd
32946 sshd
pstree -apnh|grep sshd :显示进程间的关系
[root@linux-node1 ~]# pstree -apnh|grep sshd
|-sshd,6851 -D
| `-sshd,32946
| `-grep,39535 --color=auto sshd
pidof sshd :显示sshd进程的所有进程号
[root@linux-node1 ~]# pidof sshd
32946 6851
kill 和 pkill 杀死进程
[root@linux-node1 ~]# kill -9 2233 # 杀死进程2233
[root@linux-node1 ~]# pkill zabbix # 杀死zabbix进程
netstat -anptu|grep 22 | 查看22端口运行的服务
[root@linux-node1 ~]# netstat -anptu|grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6851/sshd
tcp 0 0 192.168.56.11:22 192.168.56.1:62530 ESTABLISHED 32946/sshd: root@pt
tcp6 0 0 :::22 :::* LISTEN 6851/sshd