全面了解linux情况常用命令

  • 查看linux服务器CPU详细情况
    1. 显示CPU个数命令
    # cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
    1

    2. 显示每个物理cpu中core的个数

    # cat /proc/cpuinfo |grep "cpu cores" | uniq
    cpu cores    : 2

    3. 显示逻辑cpu个数命令

    # cat /proc/cpuinfo |grep "processor" |wc -l
    2

          物理cpu个数 X 核实数=逻辑CPU个数

  • 看服务器内存使用情况
    # free -m
                 total       used       free     shared    buffers     cached
    Mem:           980        576        404          0         22        424
    -/+ buffers/cache:        129        851

           已用内存=used-buffers-cache
           可用内存=free+buffers+cache
           shared :表示多个进程共享内存总额

  • 查看服务器硬盘使用情况
    1. 查看硬盘及分区信息
    # fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000be518
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        1339    10240000   83  Linux
    /dev/sda3            1339        1594     2048000   82  Linux swap / Solaris
    /dev/sda4            1594        2611     8170496    5  Extended
    /dev/sda5            1594        2611     8169472   83  Linux
    
    Disk /dev/sdb: 5368 MB, 5368709120 bytes
    255 heads, 63 sectors/track, 652 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x7669f3d4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1         132     1060258+  83  Linux
    /dev/sdb2             133         394     2104515   83  Linux
    /dev/sdb3             395         652     2072385   83  Linux

      2. 查看文件系统磁盘占用情况

      
    # df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda2       9.5G  1.1G  8.0G  12% /
    tmpfs           491M     0  491M   0% /dev/shm
    /dev/sda1       477M   28M  425M   7% /boot
    /dev/sda5       7.6G  164M  7.0G   3% /var
    /dev/sr0        447M  447M     0 100% /mnt
    /dev/sdb1       988M  1.3M  935M   1% /tmp/sdb1

      3. 查看硬盘的I/O性能高

    yum -y install sysstat
    # iostat -d -x -k 1 5
    Linux 2.6.32-642.el6.x86_64    09/24/2016     _x86_64_    (2 CPU)
    
    Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
    sda               0.10     6.09    0.31    0.94     9.10    28.19    59.59     0.12   98.08   11.61  126.49   6.10   0.76
    sdb               0.09     0.00    0.06    0.00     0.15     0.00     4.87     0.00    2.55    2.37  204.00   2.27   0.01
    scd0              0.00     0.00    0.00    0.00     0.01     0.00     7.32     0.00    5.05    5.05    0.00   5.05   0.00
    
    Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
    sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    sdb               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    scd0              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    

         rrqm/s: 每秒进行merge的读操作数目(delta(rmerge)/s)
         wrqm/s: 每秒进行merge的写操作数目(delta(wmerge)/s)
        r/s :每秒完成的读I/O设备的次数
        w/s :每秒完成的写I/O设备的次数
        rsec/s: 每秒读扇区数
        wsec/s: 每秒写扇区数   
       await:平均每次设备I/O操作等待时间(单位毫秒),超多5ms表示I/O压力很大
       svctm:平均每次设备I/O操作服务等待时间(单位毫秒)
      %util:一秒中有百分之多少的时间用于I/O操作,如果%util接近100%,则说明产生的I/O产生的负荷较多,该磁盘存在瓶颈
      4. 查看某目录大小
       

    # du -sh /opt/
    12K    /opt/

    5. 查看分区使用率过高,可以进入该分区挂载点,应用以下命令查看占用空间最多的目录或文件

    # du -cks * |sort -rn |head -n 10
    456274    total
    231477    images
    178654    Packages
    44420    isolinux
    1435    repodata
    256    EFI
    18    GPL
    4    TRANS.TBL
    2    RPM-GPG-KEY-CentOS-Testing-6
    2    RPM-GPG-KEY-CentOS-Security-6
  • 查看linux系统的平均负载
    # uptime
     16:40:30 up  5:25,  2 users,  load average: 0.11, 0.15, 0.10
    # w
     16:41:25 up  5:26,  2 users,  load average: 0.04, 0.12, 0.09
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    root     pts/0    192.168.0.104    06:48    0.00s  1.37s  0.18s w
    root     pts/1    192.168.0.104    07:21    9:19m  0.04s  0.04s -bash
    # 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      0 356664  33232 435904    0    0     5    13   13   10  0  0 99  0  0    
  • 查看系统的其他参数
     1. 用vmstat监控linux系统的整体性能
    # vmstat 1 4
    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 356432  33256 435924    0    0     5    13   13   10  0  0 99  0  0    
     0  0      0 356400  33256 435924    0    0     0     0   33   25  0  1 100  0  0    
     0  0      0 356400  33256 435924    0    0     0     0   21   24  0  0 100  0  0    
     0  0      0 356400  33264 435924    0    0     0    12   23   28  0  0 100  0  0    

     (1)proc   r:等待运行的进程数  b:处于非中断睡眠状态的进程数
      (2)memory  swpd:虚拟内存使用情况(KB) free:空闲的内存(kb) buff:被用来缓存的内存数量(KB)
      (3)swap si:从磁盘减缓到内存的交换页数量
                     so:从内存交换到磁盘的交换页数量
      (4)io   bi:发送到块设备的块数
                   bo:从块设备接收到的块数
       (5)system  in:每秒中断数,包括时钟中断
                          cs:每秒的环境(上下文)切换次数
        (6)cpu 按cpu的使用百分比显示
                       us:CPU的使用时间
                       uy:CPU的系统使用时间
                       id:闲置时间
    2.查看内核 

    # uname -r
    2.6.32-642.el6.x86_64
    # uname -a
    Linux xuegod35 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    # file /sbin/init
    /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

    3. 查看发布版本

    # yum install redhat-lsb
    # lsb_release -a
    LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
    Distributor ID:    CentOS
    Description:    CentOS release 6.8 (Final)
    Release:    6.8
    Codename:    Final

    4. 查看系统已载入的模块

  • # lsmod | grep ipv6
    nf_conntrack_ipv6       7985  3 
    nf_defrag_ipv6         26468  1 nf_conntrack_ipv6
    nf_conntrack           79537  2 nf_conntrack_ipv6,xt_state
    ipv6                  336282  305 nfsd,lockd,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
原文地址:https://www.cnblogs.com/love3556/p/5903613.html