日常运维命令

  • w命令
    负载 1分钟 5分钟 15分钟
 21:35:21 up 1 min,  1 user,  load average: 0.36, 0.17, 0.06
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    101.81.30.208    21:35    1.00s  0.00s  0.00s w
  • vmstat
    格式: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  80220   9328 207376    0    0   193    15  123  290  1  0 98  0  0
 0  0      0  80220   9328 207392    0    0     0     0  115  256  1  0 99  0  0
 0  0      0  80220   9328 207392    0    0     0     0  100  235  0  0 100  0  0
 0  0      0  80220   9328 207392    0    0     0     0  108  240  0  0 100  0  0
 0  0      0  80220   9328 207392    0    0     0     0  112  247  0  0 100  0  0
  • top
    M 内存排序
    P CPU排序
    1 显示所有CPU
    q 退出top
    top -c 查看具体的进程命令、全局的路劲
    top -bn1 静态显示所有内容
top - 11:32:50 up 13 min,  1 user,  load average: 0.00, 0.01, 0.03
Tasks: 112 total,   1 running, 111 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 :   999936 total,   541184 free,   233352 used,   225400 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.   586724 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
  1336 mysql     20   0 1424620 116212  10232 S  0.0 11.6   0:00.79 mysqld
   654 root      20   0  327428  26860   6548 S  0.0  2.7   0:00.29 firewalld
   962 root      20   0  553152  16456   5804 S  0.0  1.6   0:00.20 tuned
   627 polkitd   20   0  528276  11620   4712 S  0.0  1.2   0:00.02 polkitd
   663 root      20   0  587516   8336   6376 S  0.0  0.8   0:00.06 NetworkManager
     1 root      20   0  128092   6700   3944 S  0.0  0.7   0:00.98 systemd
   488 root      20   0  195120   6208   2608 S  0.0  0.6   0:00.00 
  • sar

    • 安装 yum install -y sysstat
    • /var/log/sa 记录文件路径;
      sa文件为二进制,10分钟产生一次;只能sar -f 指定查看;
      sar为普通文件,每天产生一次,可cat查看;
      名称最后以当前日期结尾(如:sa11、sar11 11号产生的记录);最长保留时间1个月。
    • 用法
      sar -n DEV 1 3 查看网卡流量
      sar -n DEV -f /var/log/sa/sa11 (-f 指定文件查看历史流量)
      sar -q -f /var/log/sa/sa11查看历史负载(-q 查看负载)
      sar -b 1 3 (-b 查看磁盘读写)
Linux 3.10.0-514.el7.x86_64 (localhost.localdomain)     2017年09月11日  _x86_64_        (1 CPU)

14时41分54秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
14时41分55秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
14时41分55秒     ens33      1.00      1.00      0.06      0.19      0.00      0.00      0.00

14时41分55秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
14时41分56秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
14时41分56秒     ens33      0.99      0.99      0.06      0.39      0.00      0.00      0.00

14时41分56秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
14时41分57秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
14时41分57秒     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.00      1.00      0.06      0.33      0.00      0.00      0.00
  • nload
    安装:
    yum install -y epel-release
    yum install -y nload

  • 监控IO性能

    • iostat
      iostat 1 3
      iostat -x 主要查看%user参数
    • 安装:yum install -y sysstat
    • iotop
      安装:yum install -y iotop
  • free
    -m -g指定单位兆
    -h 容量后显示具体单位

    • buffer/cache区别
      buffer 缓冲 CPU-->内存(buffer)-->磁盘
      cache 缓存 磁盘-->内存(cache)-->CPU
    • 公式:
      total=used+free+buff/cache
      avaliable包含free和buffer/cache剩余部分
  • ps 查看系统进程

    • 用法:ps aux、ps -elf
    • STAT部分状态说明

      D 不能中断的进程
      R run状态的进程
      S sleep状态的进程
      T 暂停的进程
      Z 僵尸进程
      < 高优先级进程
      N 低优先级进程
      L 内存中被锁了内存分页
      s 主进程
      l 多线程进程
      /+ 前台进程


ifconfig 查看网卡IP yum install net-tools
ifconfig -a

ip add
ifup ens33 开启ens33网卡
ifdown ens33 关闭ens33网卡
ifdown ens33 && ifup ens33

mii-tool ens33 link ok
ethtool ens3

修改主机命令
hostname set-hostname
主机名名配置文件 /etc/hostname
DNS配置文件 /etc/resolv.conf (重启后会恢复,永久修改,修改网卡配置文件)
/etc/host

原文地址:https://www.cnblogs.com/cy-8593/p/7513739.html