Operation and maintenance
  • 目录
  • linux 历史
    • Linux网卡配置
    • linux互相登陆
  • 文件目录管理
    • linux目录结构
    • 文件的基本信息
    • linux别名alias
    • 环境变量
    • linux终端相关快捷键
    • linux文件和目录添加删除
    • linux文件查看命令
    • linux文件目录权限
    • linux文件特殊权限
    • 链接文件
    • linux下文件查找
    • linux和window文件互传
    • linux文件压缩和打包
    • vim工具集
  • 用户和组管理
    • 用户组和用户管理
    • 修改组和用户
    • 用户切换
    • 禁止root远程登陆
  • linux磁盘管理
    • 磁盘分区
    • 格式化磁盘
    • 分区挂载
    • 手动添加swap分区
    • lvm基础
  • linux软件安装和卸载
    • rpm工具
    • yum工具
    • 源码安装包
  • 日常运维
    • 监控磁盘IO
    • 查看网络状态
    • linux抓包
    • linux网络相关
    • Linux防火墙-netfilter
    • linux任务计划
    • linux系统服务管理
    • linux同步工具rsync
    • linux系统日志和screen
  • LAMP架构
    • 安装mysql
    • 免编译安装mariadb
    • 安装apache
    • 安装php5
    • 安装php7
    • apache 配置虚拟主机
    • apache 用户认证
    • apache 域名跳转
    • apache 访问日志
    • apache 不记录文件日志
    • apache 配置静态元素过期时间
    • apache 配置防盗链
    • apache 访问控制
    • apache 禁止解析php文件
    • apache 禁止user_agent
    • php 配置文件
    • php 动态扩展模块安装
  • LNMP架构
    • 安装mariadb
    • 安装php
    • 安装nginx
    • nginx 默认虚拟主机
    • nginx 用户认证
    • nginx 域名重定向
    • nginx 访问日志
    • nginx 日志切割
    • nginx不记录指定文件类型日志
    • nginx 静态文件和过期时间
    • nginx 防盗链
    • nginx 访问控制
    • nginx 解析php
    • nginx 代理
    • nginx 负载均衡
    • nginx 支持https
  • MySQL集合
    • 更改root密码
    • mysql 常用操作
    • mysql 常用sql
    • mysql 数据备份
    • mysql 主从配置
  • linux常用服务
    • nfs 服务搭建
    • CentOS7 搭建snmp服务
    • ftp 服务搭建
    • samba 服务搭建
    • Squid 服务搭建
    • Tomcat 服务搭建
    • resin 搭建
    • dns 服务搭建
    • iscsi 服务搭建
  • linux开发语言环境
    • python 开发环境
    • golang 开发环境
  • linux集群架构
    • linux 高可用
    • linux 负载均衡
  • linux监控平台
    • zabbix 监控平台(上)
  • shell集合
  • NoSql
    • memcached (上)
    • memcached(下)
    • redis(上)
    • redis(中)
    • redis(下)
    • mongodb(上)
    • mongodb(中)
    • mongodb(下)
  • 代码管理工具
    • 代码管理工具 svn
    • 代码管理工具 git
    • 搭建git私有仓库
    • 安装配置gitlab
  • docker 入门
    • docker 安装
    • docker 镜像管理
    • docker 容器管理
    • docker 仓库管理
    • docker 共享目录
    • docker 数据备份和恢复
    • docker 网络管理
    • docker 使用dockerfile
    • docker compose
  • 自动化运维
    • saltstack 安装
    • saltstack 配置认证
    • saltstack 远程执行命令
    • saltstack grains
    • saltstack pillar
    • saltstack 实战:安装配置httpd
    • saltstack 实战:配置管理文件
    • saltstack 实战:配置管理远程命令
    • saltstack 实战:配置管理任务计划
    • saltstack salt-ssh工具
    • ansible 安装
    • ansible 远程命令
    • ansible 远程目录拷贝
    • ansible 任务计划
    • ansible 远程rpm/服务管理
    • ansible playbook 详解
    • ansible playbook 实战:安装nginx
  • linux虚拟化
    • KVM介绍
    • 安装KVM
    • 虚拟机管理
    • 克隆虚拟机
    • 快照管理
    • 磁盘扩容
    • 调整虚拟机配置
    • 迁移虚拟机
  • 错误排查
    • linux启动挂在不上sysroot问题
由 GitBook 提供支持
在本页
  • w 命令
  • vmstat 命令
  • top 命令
  • sar 命令
  • free 命令
  • ps 命令

这有帮助吗?

日常运维

w 命令

[root@localhost ~]# w
 19:37:54 up 44 min,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.127.1    18:55    2.00s  0.08s  0.00s w

w 命令 :

18:28:13 up 2 min, 1 user, load average: 0.05, 0.05, 0.01 (同uptime)

[root@localhost ~]# uptime
 19:07:57 up 14 min,  1 user,  load average: 0.00, 0.02, 0.05

load average: 0.05, 0.05, 0.01 :1分钟内,5分钟内,15分钟内使用和等待CPU的进程数 ,一般数值小于CPU核数为正常

18:28:13 up 2 min :运行时间

1 user :用户数

用户名 终端 登录地址 登录时间 空闲时间 终端下进程和子进程占用CPU的时间 命令执行时间 命令

1.USER 2.TTY 3.FROM 4.LOGIN@ 5.IDLE 6.JCPU 7.PCPU 8.WHAT

root pts/0 192.168.130.1 18:26 0.00s 0.02s 0.00s w

[root@localhost ~]# cat /proc/cpuinfo  # 查看系统cpu信息
processor       : 0 # 为逻辑CPU个数减一
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
stepping        : 9
microcode       : 0x1c
cpu MHz         : 2601.000
cache size      : 3072 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep arat
bogomips        : 5202.00
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management:

vmstat 命令

vmstat 命令 :

介绍:动态显示系统负载状态

格式:vmstat [option]

  • vmstat N M :每Ns显示一次,共显示M次

[root@localhost ~]# 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 st
 2  0      0 478328   2076 376100    0    0   144    94  111  176  1  1 96  2  0
 0  0      0 478328   2076 376100    0    0     0     0   51   46  0  0 100  0  0

vmstat 结果说明:

procs 进程:

  • r (run) :每N时间内的任务数

  • b (block) :被I/O堵塞的任务数

memory内存:

  • swpd :交换分区的数据量kb(数值大且频繁变动是当注意)

  • free :内存剩余数

  • buff:缓冲大小

  • cache:缓存大小

swap 交换分区:

  • si (storage in):写入内存

  • so (storage out):从内存读出的

si so 频繁变动且大于零时说明内存不足

io 磁盘:

  • bi (block in):读磁盘

  • bo (block out):写磁盘

普通硬盘长期大于1000时有问题

system 显示采集间隔内发生的中断次数:

  • in :表示在某一时间间隔中观测到的每秒设备中断数

  • cs :上下文切换数

cpu:

  • us :用户占用百分比

  • sy :系统占用百分比

  • id :空闲百分比

  • wa :等待百分比

  • st :被偷百分比

top 命令

top :动态查看负载

Tasks:  92 total,   1 running,  91 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   997956 total,   478088 free,   141684 used,   378184 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   671184 avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                        
  2231 root      20   0  161944   2212   1556 R  0.7  0.2   0:00.02 top                                                            
     1 root      20   0  125328   3848   2592 S  0.0  0.4   0:01.57 systemd                                                        
     2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd                                                       
     3 root      20   0       0      0      0 S  0.0  0.0   0:00.10 ksoftirqd/0                                                    
     5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H                                                   
     7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
  • PID :进程ID号 可在/proc/ 下查看

  • USER : 用户名 shirf + u查看

  • PR : 0-39 越高优先级越高

  • NT :-20-19

PR+NT <=20

  • VIRI :虚拟内存

  • RES :物理内存

  • SHR :共享内存

  • TIME+ :运行时长

  • %CPU :占用CPU百分比 shift + t

  • %MEM :占用内存百分比 shift + m

用法:

  • -bn 1 :一次性显示(可用于脚本)

  • -d # :指定间隔时间

  • -c :详细显示最后一列

sar 命令

sar 命令:

介绍:显示网卡流量,需要yum install -y sysstat

格式:sar -n DEV 1 10 :显示网卡流量 每秒1次,共10次

用法:

  • -q : 历史负载

  • -b :磁盘

  • -p :cpu

  • -f filename : 查看某一天网卡历史记录(/var/log/sa/下)

  • -q :查看历史负载

[root@localhost ~]# sar -n DEV 1 3
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年08月05日  _x86_64_        (1 CPU)

19时44分21秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
19时44分22秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
19时44分22秒     ens33      0.99      0.99      0.06      0.18      0.00      0.00      0.00

19时44分22秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
19时44分23秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
19时44分23秒     ens33      1.00      1.00      0.06      0.38      0.00      0.00      0.00

19时44分23秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
19时44分24秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
19时44分24秒     ens33      0.99      0.99      0.06      0.38      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      0.99      0.99      0.06      0.31      0.00      0.00      0.00
[root@localhost ~]# sar -q
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年08月05日  _x86_64_        (1 CPU)

19时20分01秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked
19时30分01秒         1       109      0.00      0.01      0.05         0
19时40分01秒         1       109      0.00      0.01      0.05         0
平均时间:         1       109      0.00      0.01      0.05         0
[root@localhost ~]# sar -b
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年08月05日  _x86_64_        (1 CPU)

19时20分01秒       tps      rtps      wtps   bread/s   bwrtn/s
19时30分01秒      0.05      0.00      0.05      0.00      0.59
19时40分01秒      0.03      0.00      0.03      0.00      0.28
平均时间:      0.04      0.00      0.04      0.00      0.43
[root@localhost ~]# sar -p
Linux 3.10.0-862.el7.x86_64 (localhost.localdomain)     2018年08月05日  _x86_64_        (1 CPU)

19时20分01秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
19时30分01秒     all      0.03      0.00      0.10      0.00      0.00     99.87
19时40分01秒     all      0.02      0.00      0.09      0.00      0.00     99.88
平均时间:     all      0.03      0.00      0.10      0.00      0.00     99.87

还有一个命令 nload,需要安装nload

free 命令

free 命令:

介绍:输出linux内存信息

格式:free [option]

用法:

  • -m :M为单位,默认为kb

  • -g :G为单位

  • -h :合适的单位

[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           974M        138M        463M        7.6M        372M        655M
Swap:          2.0G          0B        2.0G

内存公式:total = used + free + shared + buff(缓冲)/cache(缓存)

available包含buff和cache剩余部分

ps 命令

ps 命令

介绍:查看进程

格式:ps [option]

用法:

  • ps aux

  • ps -elf

[root@localhost ~]# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.3 125328  3848 ?        Ss   18:53   0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 2
root          2  0.0  0.0      0     0 ?        S    18:53   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    18:53   0:00 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   18:53   0:00 [kworker/0:0H]
root          7  0.0  0.0      0     0 ?        S    18:53   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    18:53   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        R    18:53   0:00 [rcu_sched]
root         10  0.0  0.0      0     0 ?        S<   18:53   0:00 [lru-add-drain]
root         11  0.0  0.0      0     0 ?        S    18:53   0:00 [watchdog/0]
root         13  0.0  0.0      0     0 ?        S    18:53   0:00 [kdevtmpfs]
root         14  0.0  0.0      0     0 ?        S<   18:53   0:00 [netns]
root         15  0.0  0.0      0     0 ?        S    18:53   0:00 [khungtaskd]
root         16  0.0  0.0      0     0 ?        S<   18:53   0:00 [writeback]
root         17  0.0  0.0      0     0 ?        S<   18:53   0:00 [kintegrityd]
root         18  0.0  0.0      0     0 ?        S<   18:53   0:00 [bioset]
root         19  0.0  0.0      0     0 ?        S<   18:53   0:00 [kblockd]

输出解析:

USER:进程用户

PID:进程ID

%CPU:使用CPU百分比

%MEM:使用内存百分比

VSZ:使用虚拟内存

RSS:使用物理内存

TTY:运行终端

STAT :进程运行状态

  • S :sleep

  • s :主进程

  • < : 高优先级

  • N :低优先级

  • +:前台

  • R :running

  • L :被锁

  • l :多线程进程

  • Z :僵尸进程

  • X :死亡进程

  • T :暂停进程

  • D :不可中断进程

TIME:时间

COMMEND:命令

上一页源码安装包下一页监控磁盘IO

最后更新于4年前

这有帮助吗?