zoukankan      html  css  js  c++  java
  • CentOS7下查询硬件信息

    原文:https://blog.csdn.net/pwb1994001/article/details/80896267

    因为个人需要,整理的

    参考:https://blog.csdn.net/dream_broken/article/details/52883883
    参考:https://blog.csdn.net/lampsunny/article/details/6288457
    • 1
    • 2

    一.系统

    1.版本

    ① 确认是64位还是32位,其他信息不多

    $ uname -a
    Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    • 1
    • 2

    ② 看到更多信息

    $ more /etc/*release
    ::::::::::::::
    /etc/centos-release
    ::::::::::::::
    CentOS Linux release 7.2.1511 (Core) 
    ::::::::::::::
    /etc/os-release
    ::::::::::::::
    NAME="CentOS Linux"
    VERSION="7 (Core)"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="7"
    PRETTY_NAME="CentOS Linux 7 (Core)"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:centos:centos:7"
    HOME_URL="https://www.centos.org/"
    BUG_REPORT_URL="https://bugs.centos.org/"
    
    CENTOS_MANTISBT_PROJECT="CentOS-7"
    CENTOS_MANTISBT_PROJECT_VERSION="7"
    REDHAT_SUPPORT_PRODUCT="centos"
    REDHAT_SUPPORT_PRODUCT_VERSION="7"
    
    ::::::::::::::
    /etc/redhat-release
    ::::::::::::::
    CentOS Linux release 7.2.1511 (Core) 
    ::::::::::::::
    /etc/system-release
    ::::::::::::::
    CentOS Linux release 7.2.1511 (Core)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    2.CPU

    总核数 = 物理CPU个数 × 每颗物理CPU的核数 
    总逻辑CPU数 = 物理CPU个数 × 每颗物理CPU的核数 × 超线程数 
    ① 查看物理CPU个数

    $ cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
    1
    • 1
    • 2

    ② 查看每颗物理CPU中core的个数(即核数)

    $ cat /proc/cpuinfo | grep "cpu cores" | uniq
    cpu cores   : 8
    • 1
    • 2

    ③ 查看逻辑CPU的个数

    $ cat /proc/cpuinfo | grep "processor" | wc -l
    16
    • 1
    • 2

    ④ 查看CPU信息(型号)

    $ cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
         16  Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
    • 1
    • 2

    ⑤ 查看CPU详细信息

    $ cat /proc/cpuinfo
    processor   : 0
    vendor_id   : GenuineIntel
    cpu family  : 6
    model       : 63
    model name  : Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz
    stepping    : 2
    microcode   : 0x3c
    cpu MHz     : 2900.028
    cache size  : 25600 KB
    physical id : 0
    siblings    : 16
    core id     : 0
    cpu cores   : 8
    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 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase bmi1 avx2 smep bmi2 erms invpcid xsaveopt
    bogomips    : 5800.05
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 46 bits physical, 48 bits virtual
    power management:
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    3.运行模式

    ① 查看CPU运行在多少位模式下

    $ getconf LONG_BIT 
    64
    • 1
    • 2

    ② 如果是32,说明当前CPU运行在32bit模式下,但不代表CPU不支持64bit

    $ cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
    16
    • 1
    • 2

    结果大于0,说明支持64bit计算,lm指long mode,支持lm则是64bit

    4.计算机名

    ① 计算机名

    $ hostname
    localhost.localdomain
    • 1
    • 2
    5.查看环境变量

    ① 环境变量

    $ env
    XDG_SESSION_ID=4  
    HOSTNAME=localhost.localdomain  
    SELINUX_ROLE_REQUESTED=  
    TERM=vt100  
    SHELL=/bin/bash  
    HISTSIZE=1000  
    SSH_CLIENT=192.168.174.1 58896 22  
    SELINUX_USE_CURRENT_RANGE=  
    SSH_TTY=/dev/pts/0  
    USER=root
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    6.系统运行

    ① 系统运行时间

    $ uptime
     02:16:07 up 36 days, 27 min,  7 users,  load average: 1.38, 1.36, 1.34
    • 1
    • 2
    02:16:07                               // 系统当前时间
    up 36 days, 27 min                     // 主机已运行时间,36天27分钟,时间越大,说明你的机器越稳定。
    7 users                                // 用户连接数,是总连接数而不是用户数
    load average: 1.38, 1.36, 1.34         // 系统平均负载,统计最近1,5,15分钟的系统平均负载
    • 1
    • 2
    • 3
    • 4

    ② 查看平均负载

    $ cat /proc/loadavg
    1.80 1.53 1.41 4/3909 4106
    • 1
    • 2

    前面三个值分别对应系统当前1分钟、5分钟、15分钟内的平均load; 
    后面的1个分数,分母表示系统进程总数,分子表示正在运行的进程数; 
    最后一个数字表示最近运行的进程ID。

    二.资源

    1.内存

    ① 内存详细信息

    $ cat /proc/meminfo
    MemTotal:       30440564 kB
    MemFree:         1292332 kB
    MemAvailable:    9045208 kB
    Buffers:             788 kB
    Cached:          8805368 kB
    SwapCached:            0 kB
    Active:         23305524 kB
    Inactive:        4361900 kB
    Active(anon):   19620352 kB
    Inactive(anon):   869288 kB
    Active(file):    3685172 kB
    Inactive(file):  3492612 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:             0 kB
    SwapFree:              0 kB
    Dirty:              1396 kB
    Writeback:             0 kB
    AnonPages:      18861432 kB
    Mapped:           281464 kB
    Shmem:           1628228 kB
    Slab:            1021668 kB
    SReclaimable:     828508 kB
    SUnreclaim:       193160 kB
    KernelStack:       66336 kB
    PageTables:        84196 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:    15220280 kB
    Committed_AS:   36287560 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:       83692 kB
    VmallocChunk:   34359493624 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:  15896576 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:      284672 kB
    DirectMap2M:    22784000 kB
    DirectMap1G:     8388608 kB
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    MemTotal总内存,MemFree可用内存 
    ② 查看可用内存(-m,单位是m,-g,单位是g)

    $ free -m
                  total        used        free      shared  buff/cache   available
    Mem:          29727       18867        1248        1598        9611        8825
    Swap:             0           0           0
    
    $ free -g
                  total        used        free      shared  buff/cache   available
    Mem:             29          18           1           1           9           8
    Swap:             0           0           0
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    空闲内存:total - used = free + buff/cache

    我们通过free命令查看机器空闲内存时,会发现free的值很小。这主要是因为,在linux中有这么一种思想,内存不用白不用,因此它尽可能的cache和buffer一些数据,以方便下次使用。但实际上这些内存也是可以立刻拿来使用的。

    三.硬盘

    1.磁盘和分区

    ① 查看各分区使用情况

    $ df -h
    Filesystem               Size  Used Avail Use% Mounted on  
    /dev/mapper/centos-root   45G   22G   24G  48% /  
    devtmpfs                 906M     0  906M   0% /dev  
    tmpfs                    921M   96K  921M   1% /dev/shm  
    tmpfs                    921M 1004K  920M   1% /run  
    tmpfs                    921M     0  921M   0% /sys/fs/cgroup  
    /dev/sda1                497M  195M  303M  40% /boot  
    tmpfs                    185M     0  185M   0% /run/user/1001  
    tmpfs                    185M     0  185M   0% /run/user/0
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    ② 查看指定目录的大小

    $ du -sh /root
    1.2G    /root 
    • 1
    • 2

    ③ 查看所有分区

    $ fdisk -l
    磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区  
    Units = 扇区 of 1 * 512 = 512 bytes  
    扇区大小(逻辑/物理):512 字节 / 512 字节  
    I/O 大小(最小/最佳):512 字节 / 512 字节  
    磁盘标签类型:dos  
    磁盘标识符:0x000a0cd4  
    
       设备 Boot      Start         End      Blocks   Id  System  
    /dev/sda1   *        2048     1026047      512000   83  Linux  
    /dev/sda2         1026048    62914559    30944256   8e  Linux LVM  
    
    磁盘 /dev/mapper/centos-root:29.5 GB, 29490151424 字节,57597952 个扇区  
    Units = 扇区 of 1 * 512 = 512 bytes  
    扇区大小(逻辑/物理):512 字节 / 512 字节  
    I/O 大小(最小/最佳):512 字节 / 512 字节  
    
    
    磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区  
    Units = 扇区 of 1 * 512 = 512 bytes  
    扇区大小(逻辑/物理):512 字节 / 512 字节  
    I/O 大小(最小/最佳):512 字节 / 512 字节  
    
    
    磁盘 /dev/mapper/centos-docker--poolmeta:33 MB, 33554432 字节,65536 个扇区  
    Units = 扇区 of 1 * 512 = 512 bytes  
    扇区大小(逻辑/物理):512 字节 / 512 字节  
    I/O 大小(最小/最佳):512 字节 / 512 字节  
    
    
    磁盘 /dev/mapper/docker-253:0-101330881-pool:107.4 GB, 107374182400 字节,209715200 个扇区  
    Units = 扇区 of 1 * 512 = 512 bytes  
    扇区大小(逻辑/物理):512 字节 / 512 字节  
    I/O 大小(最小/最佳):65536 字节 / 65536 字节  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    ④ 查看所有交换分区

    $ swapon -s
    文件名                          类型            大小    已用    权限  
    /dev/dm-1                       partition       2097148 8       -1 
    • 1
    • 2
    • 3

    四.网络

    1.网络属性信息

    ① 查看所有网络接口的属性

    $ ifconfig
    docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500  
            inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0  
            ether 02:42:e1:b8:a5:4f  txqueuelen 0  (Ethernet)  
            RX packets 0  bytes 0 (0.0 B)  
            RX errors 0  dropped 0  overruns 0  frame 0  
            TX packets 0  bytes 0 (0.0 B)  
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  
    
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  
            inet 192.168.174.129  netmask 255.255.255.0  broadcast 192.168.174.255  
            inet6 fe80::20c:29ff:fe50:b3b4  prefixlen 64  scopeid 0x20<link>  
            ether 00:0c:29:50:b3:b4  txqueuelen 1000  (Ethernet)  
            RX packets 28649  bytes 38411280 (36.6 MiB)  
            RX errors 0  dropped 0  overruns 0  frame 0  
            TX packets 8937  bytes 1226914 (1.1 MiB)  
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536  
            inet 127.0.0.1  netmask 255.0.0.0  
            inet6 ::1  prefixlen 128  scopeid 0x10<host>  
            loop  txqueuelen 0  (Local Loopback)  
            RX packets 4  bytes 340 (340.0 B)  
            RX errors 0  dropped 0  overruns 0  frame 0  
            TX packets 4  bytes 340 (340.0 B)  
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  
    
    virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500  
            inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255  
            ether 00:00:00:00:00:00  txqueuelen 0  (Ethernet)  
            RX packets 0  bytes 0 (0.0 B)  
            RX errors 0  dropped 0  overruns 0  frame 0  
            TX packets 0  bytes 0 (0.0 B)  
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    ② 带宽

    $ ethtool ens192(网卡名)
    Settings for ens192:  
            Supported ports: [ TP ]  
            Supported link modes:   1000baseT/Full   
                                    10000baseT/Full   
            Supported pause frame use: No  
            Supports auto-negotiation: No  
            Advertised link modes:  Not reported  
            Advertised pause frame use: No  
            Advertised auto-negotiation: No  
            Speed: 10000Mb/s 
            Duplex: Full  
            Port: Twisted Pair  
            PHYAD: 0  
            Transceiver: internal  
            Auto-negotiation: off  
            MDI-X: Unknown  
            Supports Wake-on: uag  
            Wake-on: d  
            Link detected: yes 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    主要查看speed

    ③ 查看路由表

    $ route -n 
    
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.31.16.1     0.0.0.0         UG    0      0        0 eth0
    172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
    172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-b3fca78f9ec2
    172.31.16.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    ④ 查看所有监听端口

    $ netstat -ntpl
    
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      112434/java         
    tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      15725/kube-proxy    
    tcp        0      0 172.31.24.20:10250      0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:50090         0.0.0.0:*               LISTEN      112806/java         
    tcp        0      0 0.0.0.0:26380           0.0.0.0:*               LISTEN      119314/redis-sentin 
    tcp        0      0 0.0.0.0:6380            0.0.0.0:*               LISTEN      121036/./redis-serv 
    tcp        0      0 0.0.0.0:26381           0.0.0.0:*               LISTEN      126277/redis-sentin 
    tcp        0      0 0.0.0.0:6381            0.0.0.0:*               LISTEN      94302/redis-server  
    tcp        0      0 0.0.0.0:26382           0.0.0.0:*               LISTEN      130400/redis-sentin 
    tcp        0      0 0.0.0.0:6382            0.0.0.0:*               LISTEN      70223/redis-server  
    tcp        0      0 0.0.0.0:17070           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 172.31.24.20:10255      0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 0.0.0.0:20880           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:19888           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      39892/java          
    tcp        0      0 0.0.0.0:28080           0.0.0.0:*               LISTEN      39892/java          
    tcp        0      0 0.0.0.0:20050           0.0.0.0:*               LISTEN      1181/zabbix_agentd  
    tcp        0      0 0.0.0.0:21268           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:8020            0.0.0.0:*               LISTEN      1325/nginx: master  
    tcp        0      0 127.0.0.1:50070         0.0.0.0:*               LISTEN      112434/java         
    tcp        0      0 0.0.0.0:50071           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8088            0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:50072           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50073           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50074           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50010           0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:50075           0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:27070           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8030            0.0.0.0:*               LISTEN      15480/nginx: master 
    tcp        0      0 127.0.0.1:25664         0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:36000           0.0.0.0:*               LISTEN      101488/sshd         
    tcp        0      0 0.0.0.0:11970           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 172.31.24.20:4194       0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:50020         0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:18086           0.0.0.0:*               LISTEN      80641/java          
    tcp6       0      0 :::3306                 :::*                    LISTEN      51298/mysqld        
    tcp6       0      0 :::17070                :::*                    LISTEN      9519/nginx: master  
    tcp6       0      0 :::19888                :::*                    LISTEN      9519/nginx: master  
    tcp6       0      0 :::10256                :::*                    LISTEN      15725/kube-proxy    
    tcp6       0      0 :::21                   :::*                    LISTEN      63183/vsftpd        
    tcp6       0      0 :::8087                 :::*                    LISTEN      19337/java          
    tcp6       0      0 :::50071                :::*                    LISTEN      9519/nginx: master
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    ⑤ 查看所有已经建立的连接

    $ netstat -napt
    
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      112434/java         
    tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      15725/kube-proxy    
    tcp        0      0 172.31.24.20:10250      0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:50090         0.0.0.0:*               LISTEN      112806/java         
    tcp        0      0 0.0.0.0:26380           0.0.0.0:*               LISTEN      119314/redis-sentin 
    tcp        0      0 0.0.0.0:6380            0.0.0.0:*               LISTEN      121036/./redis-serv 
    tcp        0      0 0.0.0.0:26381           0.0.0.0:*               LISTEN      126277/redis-sentin 
    tcp        0      0 0.0.0.0:6381            0.0.0.0:*               LISTEN      94302/redis-server  
    tcp        0      0 0.0.0.0:26382           0.0.0.0:*               LISTEN      130400/redis-sentin 
    tcp        0      0 0.0.0.0:6382            0.0.0.0:*               LISTEN      70223/redis-server  
    tcp        0      0 0.0.0.0:17070           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 172.31.24.20:10255      0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 0.0.0.0:20880           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:19888           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      39892/java          
    tcp        0      0 0.0.0.0:28080           0.0.0.0:*               LISTEN      39892/java          
    tcp        0      0 0.0.0.0:20050           0.0.0.0:*               LISTEN      1181/zabbix_agentd  
    tcp        0      0 0.0.0.0:21268           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:8020            0.0.0.0:*               LISTEN      1325/nginx: master  
    tcp        0      0 127.0.0.1:50070         0.0.0.0:*               LISTEN      112434/java         
    tcp        0      0 0.0.0.0:50071           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8088            0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 0.0.0.0:50072           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50073           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50074           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:50010           0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:50075           0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:27070           0.0.0.0:*               LISTEN      9519/nginx: master  
    tcp        0      0 0.0.0.0:8030            0.0.0.0:*               LISTEN      15480/nginx: master 
    tcp        0      0 127.0.0.1:25664         0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:36000           0.0.0.0:*               LISTEN      101488/sshd         
    tcp        0      0 0.0.0.0:11970           0.0.0.0:*               LISTEN      80641/java          
    tcp        0      0 172.31.24.20:4194       0.0.0.0:*               LISTEN      48609/kubelet       
    tcp        0      0 127.0.0.1:50020         0.0.0.0:*               LISTEN      112593/java         
    tcp        0      0 0.0.0.0:18086           0.0.0.0:*               LISTEN      80641/java          
    tcp6       0      0 :::3306                 :::*                    LISTEN      51298/mysqld        
    tcp6       0      0 :::17070                :::*                    LISTEN      9519/nginx: master  
    tcp6       0      0 :::19888                :::*                    LISTEN      9519/nginx: master  
    tcp6       0      0 :::10256                :::*                    LISTEN      15725/kube-proxy    
    tcp6       0      0 :::21                   :::*                    LISTEN      63183/vsftpd        
    tcp6       0      0 :::8087                 :::*                    LISTEN      19337/java          
    tcp6       0      0 :::50071                :::*                    LISTEN      9519/nginx: master
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    ⑥ 查看某端口使用情况

    $ lsof -i:8030(端口号)
    
    COMMAND   PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
    nginx   15480   root    7u  IPv4 260155918      0t0  TCP *:8030 (LISTEN)
    nginx   15482 nobody    7u  IPv4 260155918      0t0  TCP *:8030 (LISTEN)
    
    $ netstat -apn | grep 8030(端口号)
    
    tcp        0      0 0.0.0.0:8030            0.0.0.0:*               LISTEN      15480/nginx: master
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    五.进程

    1.查看进程

    ① 查看所有进程

    $ ps -ef
    
    UID         PID   PPID  C STIME TTY          TIME CMD
    root          1      0  0 May28 ?        00:12:45 /usr/lib/systemd/systemd --system --deserialize 20
    root          2      0  0 May28 ?        00:00:00 [kthreadd]
    root          3      2  0 May28 ?        00:05:45 [ksoftirqd/0]
    root          5      2  0 May28 ?        00:00:00 [kworker/0:0H]
    root          7      2  0 May28 ?        00:00:05 [migration/0]
    root          8      2  0 May28 ?        00:00:00 [rcu_bh]
    root          9      2  0 May28 ?        00:00:00 [rcuob/0]
    root         10      2  0 May28 ?        00:00:00 [rcuob/1]
    root         11      2  0 May28 ?        00:00:00 [rcuob/2]
    root         12      2  0 May28 ?        00:00:00 [rcuob/3]
    root         13      2  0 May28 ?        00:00:00 [rcuob/4]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    可以通过ps -ef | grep 进程名 进行过滤

    $ ps -aux 
    
    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root          1  0.0  0.0 189908  4196 ?        Ss   May28  12:45 /usr/lib/systemd/systemd --system --deserialize 20
    root          2  0.0  0.0      0     0 ?        S    May28   0:00 [kthreadd]
    root          3  0.0  0.0      0     0 ?        S    May28   5:45 [ksoftirqd/0]
    root          5  0.0  0.0      0     0 ?        S<   May28   0:00 [kworker/0:0H]
    root          7  0.0  0.0      0     0 ?        S    May28   0:05 [migration/0]
    root          8  0.0  0.0      0     0 ?        S    May28   0:00 [rcu_bh]
    root          9  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/0]
    root         10  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/1]
    root         11  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/2]
    root         12  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/3]
    root         13  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/4]
    root         14  0.0  0.0      0     0 ?        S    May28   0:00 [rcuob/5]
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    ps -aux 可以看到进程占用CPU,内存情况

    ② 实时显示进程状态

    $ top
    
    top - 07:20:17 up 36 days,  5:31,  9 users,  load average: 1.78, 1.48, 1.38
    Tasks: 669 total,   2 running, 667 sleeping,   0 stopped,   0 zombie
    %Cpu(s):  2.9 us,  4.9 sy,  0.0 ni, 92.0 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
    KiB Mem : 30440564 total,   797520 free, 19349712 used, 10293332 buff/cache
    KiB Swap:        0 total,        0 free,        0 used.  9069184 avail Mem 
    
       PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                   
     14124 root      20   0  110092    536    408 R 100.0  0.0   8943:33 agetty                                                                                                    
     32399 root      20   0  9.932g 1.295g  18276 S   3.0  4.5 224:25.65 java                                                                                                      
     30791 root      20   0 9456624 314496   7304 S   1.7  1.0 102:43.09 java                                                                                                      
     60824 root      20   0 9461308 311600   7264 S   1.7  1.0 101:58.13 java                                                                                                      
     48609 root      20   0 1571064  50992   8996 S   1.0  0.2 153:24.50 kubelet                                                                                                   
    106830 root      20   0  420984    596     28 S   0.7  0.0  23:16.55 docker-containe                                                                                           
       137 root      20   0       0      0      0 S   0.3  0.0  84:51.73 rcu_sched                                                                                                 
       138 root      20   0       0      0      0 S   0.3  0.0  28:02.18 rcuos/0                                                                                                   
       143 root      20   0       0      0      0 S   0.3  0.0  14:46.18 rcuos/5                                                                                                   
       145 root      20   0       0      0      0 S   0.3  0.0  14:36.10 rcuos/7                                                                                                   
       148 root      20   0       0      0      0 S   0.3  0.0   6:19.49 rcuos/10                                                                                                  
       152 root      20   0       0      0      0 S   0.3  0.0   6:20.98 rcuos/14                                                                                                  
       760 root      20   0   26884   1784    976 S   0.3  0.0   2:34.61 systemd-logind                                                                                            
      1182 zabbix    20   0   45108   2104   1532 S   0.3  0.0  20:35.96 zabbix_agentd                                                                                             
      9312 root      20   0 6126612 1.165g  29680 S   0.3  4.0   1:04.32 java  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    六.用户

    1.查看用户

    ① 查看活动用户

    $ w
    
    root     pts/0        192.168.174.1    Mon Oct 24 09:51   still logged in   
    (unknown :0           :0               Mon Oct 24 09:27   still logged in   
    reboot   system boot  3.10.0-327.el7.x Mon Oct 24 09:26 - 11:35  (02:09)    
    root     pts/0        192.168.174.1    Fri Oct 21 09:41 - 18:44  (09:03)    
    (unknown :0           :0               Fri Oct 21 09:15 - 18:44  (09:28)    
    reboot   system boot  3.10.0-327.el7.x Fri Oct 21 09:15 - 11:35 (3+02:20)   
    root     pts/1        192.168.174.1    Thu Oct 20 10:05 - 18:13  (08:08) 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    ② 查看指定用户的信息

    $ id root
    
    uid=0(root) gid=0(root) groups=0(root)
    [root@localhost ~]# id cavan
    uid=1001(cavan) gid=1001(cavan) groups=1001(cavan)
    • 1
    • 2
    • 3
    • 4
    • 5

    ③ 查看用户登录日志

    $ last 
    
    
    root     pts/0        192.168.174.1    Mon Oct 24 09:51   still logged in   
    (unknown :0           :0               Mon Oct 24 09:27   still logged in   
    reboot   system boot  3.10.0-327.el7.x Mon Oct 24 09:26 - 11:35  (02:09)    
    root     pts/0        192.168.174.1    Fri Oct 21 09:41 - 18:44  (09:03)    
    (unknown :0           :0               Fri Oct 21 09:15 - 18:44  (09:28)    
    reboot   system boot  3.10.0-327.el7.x Fri Oct 21 09:15 - 11:35 (3+02:20)   
    root     pts/1        192.168.174.1    Thu Oct 20 10:05 - 18:13  (08:08) 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    ④ 查看系统所有用户

    $ cut -d: -f1 /etc/passwd
    
    
    root
    bin
    daemon
    adm
    lp
    sync
    shutdown
    halt
    mail
    operator
    games
    ftp
    nobody
    dbus
    polkitd
    abrt
    unbound
    colord
    usbmuxd
  • 相关阅读:
    des和Rijndael加密
    信息熵
    逻辑回归简单多变不易把握、特征离散化原因、最大熵模型
    特征选择
    数据清洗
    海塞矩阵、黄金分割、牛顿法、下降迭代法
    BP算法推导python实现
    分布函数,概率,离散,连续
    损失函数coding
    leetcode中二分查找的具体应用
  • 原文地址:https://www.cnblogs.com/jiftle/p/9615864.html
Copyright © 2011-2022 走看看