10月23日任务centos
10.1 使用w查看系统负载网络
10.2 vmstat命令ssh
10.3 top命令ui
10.4 sar命令centos7
10.5 nload命令spa
# 第一行:当前系统时间,系统启动时间,登陆的用户,系统负载:1分钟内,5分钟内,15分钟内 [root@centos7 ~]# w 20:54:14 up 5 min, 1 user, load average: 0.01, 0.14, 0.09 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 19:49 2.00s 0.04s 0.00s w root pts/0 192.168.65.1 20:50 6.00s 0.07s 0.03s w
tty[1-7]:物理机终端; pts:虚拟终端(经过ssh远程链接)code
关于系统负载的值:单位时间内使用cpu的活动的平均进程数。最佳的值为系统逻辑cpu的个数,大于该值对cpu有压力,小于该值表示cpu空闲。排序
# 查看当前系统的cpu个数(+1) [root@centos7 ~]# grep "processor" /proc/cpuinfo | tail -n 1 processor : 1 # 上面的代码表示系统的cpu个数为2
# 显示内容至关于w命令的首行 [root@centos7 ~]# uptime 21:03:14 up 14 min, 1 user, load average: 0.00, 0.03, 0.05
# 统计每隔1s的系统状态,共统计5次(后面的5不加,会一直统计下去,除非用ctrl+c打断) [root@centos7 ~]# vmstat 1 5 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 0 736764 2076 135812 0 0 34 4 59 57 0 0 98 1 0 1 0 0 736764 2076 135812 0 0 0 0 60 49 0 1 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 42 33 0 0 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 53 44 0 0 100 0 0 0 0 0 736764 2076 135844 0 0 0 0 41 36 0 0 100 0 0
符号 | 说明 |
---|---|
r(run) | 当前运行的进程数 |
b(block) | 当前系统等待的进程数(被网络、磁盘阻断) |
swpd | 内存不足时交换分区才会变化,需注意 |
free | 内存剩余大小 |
si | 数据从swap写入内存 |
so | 数据从内存写入swap |
bi | 磁盘->内存:读的数据量 |
bo | 内存->磁盘:写的数据量 |
us | 用户级别生成的进程所占用的cpu资源百分比(长时间大于50,资源可能不够) |
sy | 系统级别生成的进程、服务所占用的cpu资源百分比 |
id | 空闲资源占用cpu资源百分比(us+sy+id=100) |
wa | 等待cpu的百分比(值大cpu可能不足) |
查看进程使用资源状况(动态,每3秒刷新一次)进程
[root@centos7 ~]# top top - 21:27:28 up 38 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999720 total, 732700 free, 125816 used, 141204 buff/cache KiB Swap: 4194300 total, 4194300 free, 0 used. 711064 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 128164 6816 4048 S 0.0 0.7 0:02.61 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd+ 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0+ 6 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kworker/u+ 7 root rt 0 0 0 0 S 0.0 0.0 0:00.03 migration+ 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 0:00.45 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/1
top - 21:27:28 up 38 min, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 999720 total, 732700 free, 125816 used, 141204 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 711064 avail Mem
显示效果切换内存
top -c 显示各具体进程命令使用资源状况
[root@centos7 ~]# top -c top - 21:47:42 up 58 min, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.2 us, 0.3 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999720 total, 706460 free, 138408 used, 154852 buff/cache KiB Swap: 4194300 total, 4194300 free, 0 used. 690712 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 525 root 20 0 305296 6292 4920 S 0.3 0.6 0:05.09 /usr/bin/vmtoolsd 1273 root 20 0 157612 2192 1592 R 0.3 0.2 0:00.10 top -c 1 root 20 0 128164 6816 4048 S 0.0 0.7 0:02.63 /usr/lib/systemd/systemd --switched-root --system --deserializ+ 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kthreadd] 3 root 20 0 0 0 0 S 0.0 0.0 0:00.03 [ksoftirqd/0] 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H] 6 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kworker/u256:0] 7 root rt 0 0 0 0 S 0.0 0.0 0:00.03 [migration/0] 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh] 9 root 20 0 0 0 0 S 0.0 0.0 0:00.53 [rcu_sched] 10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 [watchdog/0] 11 root rt 0 0 0 0 S 0.0 0.0 0:00.02 [watchdog/1] 12 root rt 0 0 0 0 S 0.0 0.0 0:00.01 [migration/1] 13 root 20 0 0 0 0 S 0.0 0.0 0:00.04 [ksoftirqd/1] 15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0H] 17 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kdevtmpfs] 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [netns] 19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [khungtaskd] 20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [writeback] 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kintegrityd]
top -bn1
一次性显示所有信息,适合脚本使用
安装
yum install -y epel-release yum install -y sysstat
每隔10分钟会将系统的状态存储在/var/log/sa/目录下,默认sar命令不加参数会调用/var/log/sa/目录下的历史文件。这些历史文件没法使用cat读取!是一些二进制文件!
查看网卡流量 -n DEV
# 每隔1s输出一次,显示4次 [root@centos7 ~]# sar -n DEV 1 4 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22时07分26秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22时07分27秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22时07分27秒 ens33 1.00 0.00 0.06 0.00 0.00 0.00 0.00 22时07分27秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22时07分28秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22时07分28秒 ens33 2.00 1.00 0.12 0.40 0.00 0.00 0.00 22时07分28秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22时07分29秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22时07分29秒 ens33 2.00 1.00 0.12 0.40 0.00 0.00 0.00 22时07分29秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22时07分30秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22时07分30秒 ens33 1.00 1.00 0.06 0.40 0.00 0.00 0.00 平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均时间: ens33 1.50 0.75 0.09 0.30 0.00 0.00 0.00
说明:
接收的数据包在某段时间内异常增多,可能被攻击,须要注意!
查看历史数据(只保存1个月的历史文件)
-f /var/log/sa/saDD(DD为文件日期的天)
[root@centos7 ~]# sar -n DEV -f /var/log/sa/sa08 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22时00分01秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22时10分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22时10分01秒 ens33 0.44 0.14 0.03 0.02 0.00 0.00 0.00 平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均时间: ens33 0.44 0.14 0.03 0.02 0.00 0.00 0.00 [root@centos7 ~]# sar -q -f /var/log/sa/sa08 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22时00分01秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 22时10分01秒 0 110 0.02 0.02 0.05 0 平均时间: 0 110 0.02 0.02 0.05 0
查看磁盘信息
[root@centos7 ~]# sar -b 1 5 Linux 3.10.0-693.2.2.el7.x86_64 (centos7) ... _x86_64_ (2 CPU) 22时16分03秒 tps rtps wtps bread/s bwrtn/s 22时16分04秒 0.00 0.00 0.00 0.00 0.00 22时16分05秒 0.00 0.00 0.00 0.00 0.00 22时16分06秒 0.00 0.00 0.00 0.00 0.00 22时16分07秒 0.00 0.00 0.00 0.00 0.00 22时16分08秒 0.00 0.00 0.00 0.00 0.00 平均时间: 0.00 0.00 0.00 0.00 0.00
安装
yum install -y epel-release yum install -y nload
使用左右方向键盘切换显示系统的各网卡;nload命令会动态显示网卡的IO流量,以便了解当前系统流量状态。