zoukankan      html  css  js  c++  java
  • [Linux]查看硬件及操作系统信息

    许多的软件产品对硬件及操作系统等环境是有具体要求的,那么这时候如何快速知晓目标机器的目标资源信息是较为频繁的操作。

    命令

    • dmidecode –q
    • BIOS
      • dmidecode -t bios
    • CPU(架构)
      • [arch]
      • [lscpu]
      • [uname -m] 显示机器的处理器架构
      • cat /proc/cpuinfo
      • getconf LONG_BIT 查看当前运行模式(运行位数)
    • 内存/swap区
      • cat /proc/meminfo
      • [cat /proc/swaps] 查看哪些swap被使用
      • free -m
    • 硬盘/分区/OS目录(挂载点)
      • mount | column -t
      • fdisk -l
      • lsblk
      • df -hT
      • [cat /proc/mounts] 查看已加载的文件系统
    • PCI设备/USB设备
      • lspci
      • lsusb
    • 网络接口(网卡)
      • lspci | grep -i 'eth'
      • ifconfig -a
      • ip addr
      • ip link show
      • ethtool eth0
      • [cat /proc/net/dev] 显示网络适配器(网卡)及统计
    • OS/主机
      • hostname 查看服务器名称
        • hostnamectl set-hostname xxxx 重置hostname
      • uname -a 查看版本当前操作系统信息(含:内核等信息)
      • [uname -r] 查看正在使用的【内核】版本
      • cat /proc/version 查看【内核】的版本/查看当前操作系统版本信息
      • cat /etc/issue 或 cat /etc/redhat-release 查看版本当前操作系统发行版信息
    • 其他
      • [cat /proc/interrupts] 显示中断
    [0] dmidecode -t bios

    查看bios信息
    Dmidecode:这款软件允许你在 Linux 系统下获取有关硬件方面的信息。Dmidecode 遵循 SMBIOS/DMI 标准,其输出的信息包括 BIOS、系统、主板、处理器、内存、缓存等等。
    Dmidecode命令格式 : dmidecode -t typecode (dmidecode -t 0 等效于 dmidecode -t BIOS)
    dmidecode –q : 查看所有硬件信息(CPU、硬盘、网卡、磁盘等硬件)

    # dmidecode 3.2
    Getting SMBIOS data from sysfs.
    SMBIOS 2.7 present.
    
    Handle 0x0000, DMI type 0, 24 bytes
    BIOS Information
    	Vendor: LENOVO
    	Version: ELKT35AUS
    	Release Date: 11/26/2013
    	Address: 0xF0000
    	Runtime Size: 64 kB
    	ROM Size: 4608 kB
    	Characteristics:
    		PCI is supported
    		BIOS is upgradeable
    		BIOS shadowing is allowed
    		Boot from CD is supported
    		Selectable boot is supported
    		BIOS ROM is socketed
    		EDD is supported
    		5.25"/1.2 MB floppy services are supported (int 13h)
    		3.5"/720 kB floppy services are supported (int 13h)
    		3.5"/2.88 MB floppy services are supported (int 13h)
    		Print screen service is supported (int 5h)
    		8042 keyboard services are supported (int 9h)
    		Serial services are supported (int 14h)
    		Printer services are supported (int 17h)
    		ACPI is supported
    		USB legacy is supported
    		BIOS boot specification is supported
    		Targeted content distribution is supported
    		UEFI is supported
    	BIOS Revision: 1.35
    	Firmware Revision: 1.22
    
    Handle 0x004D, DMI type 13, 22 bytes
    BIOS Language Information
    	Language Description Format: Long
    	Installable Languages: 3
    		en|US|iso8859-1
    		fr|FR|iso8859-1
    		zh|CN|unicode
    	Currently Installed Language: en|US|iso8859-1
    
    [1] lscpu

    display information about the CPU architecture

    Architecture:          x86_64
    CPU op-mode(s):        32-bit, 64-bit
    Byte Order:            Little Endian
    CPU(s):                4
    On-line CPU(s) list:   0-3
    Thread(s) per core:    2
    Core(s) per socket:    2
    座:                 1
    NUMA 节点:         1
    厂商 ID:           GenuineIntel
    CPU 系列:          6
    型号:              58
    型号名称:        Intel(R) Core(TM) i3-3240T CPU @ 2.90GHz
    步进:              9
    CPU MHz:             1599.743
    CPU max MHz:           2900.0000
    CPU min MHz:           1600.0000
    BogoMIPS:            5786.80
    虚拟化:           VT-x
    L1d 缓存:          32K
    L1i 缓存:          32K
    L2 缓存:           256K
    L3 缓存:           3072K
    NUMA 节点0 CPU:    0-3
    
    [2] cat /proc/cpuinfo

    查看CPU详细信息: cat /proc/cpuinfo
    查看cpu运行模式: getconf LONG_BIT

    processor	: 0
    ...
    
    processor	: 1
    vendor_id	: GenuineIntel
    cpu family	: 6
    model		: 58
    model name	: Intel(R) Core(TM) i3-3240T CPU @ 2.90GHz
    stepping	: 9
    microcode	: 0x21
    cpu MHz		: 1627.709
    cache size	: 3072 KB
    physical id	: 0
    siblings	: 4
    core id		: 1
    cpu cores	: 2
    apicid		: 2
    initial apicid	: 2
    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 dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx f16c lahf_lm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm arat pln pts md_clear spec_ctrl intel_stibp flush_l1d
    bogomips	: 5786.80
    clflush size	: 64
    cache_alignment	: 64
    address sizes	: 36 bits physical, 48 bits virtual
    power management:
    
    processor	: 2
    ...
    
    processor	: 3
    ...
    
    [3] free -m

    m: 单位为MB

                  total        used        free      shared  buff/cache   available
    Mem:          11903        3996        2650         265        5256        7329
    Swap:          8191           0        8191
    
    [4] cat /proc/meminfo

    查看内存详细使用

    MemTotal:       12188892 kB
    MemFree:         2714864 kB
    MemAvailable:    7505604 kB
    Buffers:            1088 kB
    Cached:          5190608 kB
    SwapCached:            0 kB
    Active:          5281500 kB
    Inactive:        3602352 kB
    Active(anon):    3693968 kB
    Inactive(anon):   270024 kB
    Active(file):    1587532 kB
    Inactive(file):  3332328 kB
    Unevictable:           0 kB
    Mlocked:               0 kB
    SwapTotal:       8388604 kB
    SwapFree:        8388604 kB
    Dirty:                 4 kB
    Writeback:             0 kB
    AnonPages:       3692156 kB
    Mapped:           369268 kB
    Shmem:            271836 kB
    Slab:             276088 kB
    SReclaimable:     190960 kB
    SUnreclaim:        85128 kB
    KernelStack:       18512 kB
    PageTables:        84760 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:    14483048 kB
    Committed_AS:   11778012 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:      368152 kB
    VmallocChunk:   34358947836 kB
    Percpu:             1536 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:   2482176 kB
    CmaTotal:              0 kB
    CmaFree:               0 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:      113516 kB
    DirectMap2M:    12355584 kB
    
    [5] lsblk

    查看硬盘和分区分布

    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda           8:0    0 465.8G  0 disk 
    ├─sda1        8:1    0   500M  0 part /boot
    └─sda2        8:2    0    58G  0 part 
      ├─cl-root 253:0    0    50G  0 lvm  /
      └─cl-swap 253:1    0     8G  0 lvm  [SWAP]
    sr0          11:0    1  1024M  0 rom 
    
    [6] fdisk -l

    查看硬盘和分区的详细信息

    磁盘 /dev/sda:500.1 GB, 500107862016 字节,976773168 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 4096 字节
    I/O 大小(最小/最佳):4096 字节 / 4096 字节
    磁盘标签类型:dos
    磁盘标识符:0x00031a77
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048   122677247    60825600   8e  Linux LVM
    
    磁盘 /dev/mapper/cl-root:53.7 GB, 53687091200 字节,104857600 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 4096 字节
    I/O 大小(最小/最佳):4096 字节 / 4096 字节
    
    
    磁盘 /dev/mapper/cl-swap:8589 MB, 8589934592 字节,16777216 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 4096 字节
    I/O 大小(最小/最佳):4096 字节 / 4096 字节
    
    [7] mount | column -t

    查看挂载点(OS目录)与分区的关联关系的状态

    sysfs                on  /sys                             type  sysfs            (rw,nosuid,nodev,noexec,relatime,seclabel)
    proc                 on  /proc                            type  proc             (rw,nosuid,nodev,noexec,relatime)
    devtmpfs             on  /dev                             type  devtmpfs         (rw,nosuid,seclabel,size=6077156k,nr_inodes=1519289,mode=755)
    securityfs           on  /sys/kernel/security             type  securityfs       (rw,nosuid,nodev,noexec,relatime)
    tmpfs                on  /dev/shm                         type  tmpfs            (rw,nosuid,nodev,seclabel)
    devpts               on  /dev/pts                         type  devpts           (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
    tmpfs                on  /run                             type  tmpfs            (rw,nosuid,nodev,seclabel,mode=755)
    tmpfs                on  /sys/fs/cgroup                   type  tmpfs            (ro,nosuid,nodev,noexec,seclabel,mode=755)
    cgroup               on  /sys/fs/cgroup/systemd           type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore               on  /sys/fs/pstore                   type  pstore           (rw,nosuid,nodev,noexec,relatime)
    cgroup               on  /sys/fs/cgroup/memory            type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,memory)
    cgroup               on  /sys/fs/cgroup/cpu,cpuacct       type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,cpuacct,cpu)
    cgroup               on  /sys/fs/cgroup/net_cls,net_prio  type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,net_prio,net_cls)
    cgroup               on  /sys/fs/cgroup/pids              type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,pids)
    cgroup               on  /sys/fs/cgroup/blkio             type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,blkio)
    cgroup               on  /sys/fs/cgroup/cpuset            type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset)
    cgroup               on  /sys/fs/cgroup/perf_event        type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event)
    cgroup               on  /sys/fs/cgroup/devices           type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,devices)
    cgroup               on  /sys/fs/cgroup/freezer           type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,freezer)
    cgroup               on  /sys/fs/cgroup/hugetlb           type  cgroup           (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb)
    configfs             on  /sys/kernel/config               type  configfs         (rw,relatime)
    /dev/mapper/cl-root  on  /                                type  xfs              (rw,relatime,seclabel,attr2,inode64,noquota)
    selinuxfs            on  /sys/fs/selinux                  type  selinuxfs        (rw,relatime)
    systemd-1            on  /proc/sys/fs/binfmt_misc         type  autofs           (rw,relatime,fd=24,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=11076)
    debugfs              on  /sys/kernel/debug                type  debugfs          (rw,relatime)
    mqueue               on  /dev/mqueue                      type  mqueue           (rw,relatime,seclabel)
    hugetlbfs            on  /dev/hugepages                   type  hugetlbfs        (rw,relatime,seclabel)
    tmpfs                on  /tmp                             type  tmpfs            (rw,seclabel)
    /dev/sda1            on  /boot                            type  xfs              (rw,relatime,seclabel,attr2,inode64,noquota)
    sunrpc               on  /var/lib/nfs/rpc_pipefs          type  rpc_pipefs       (rw,relatime)
    tmpfs                on  /run/user/1000                   type  tmpfs            (rw,nosuid,nodev,relatime,seclabel,size=1218892k,mode=700,uid=1000,gid=1000)
    fusectl              on  /sys/fs/fuse/connections         type  fusectl          (rw,relatime)
    gvfsd-fuse           on  /run/user/1000/gvfs              type  fuse.gvfsd-fuse  (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    tmpfs                on  /run/user/1001                   type  tmpfs            (rw,nosuid,nodev,relatime,seclabel,size=1218892k,mode=700,uid=1001,gid=1001)
    gvfsd-fuse           on  /run/user/1001/gvfs              type  fuse.gvfsd-fuse  (rw,nosuid,nodev,relatime,user_id=1001,group_id=1001)
    tmpfs                on  /run/user/0                      type  tmpfs            (rw,nosuid,nodev,relatime,seclabel,size=1218892k,mode=700)
    
    [8] df -hT

    查看硬盘使用情况

    文件系统            类型      容量  已用  可用 已用% 挂载点
    devtmpfs            devtmpfs  5.8G     0  5.8G    0% /dev
    tmpfs               tmpfs     5.9G   31M  5.8G    1% /dev/shm
    tmpfs               tmpfs     5.9G   19M  5.8G    1% /run
    tmpfs               tmpfs     5.9G     0  5.9G    0% /sys/fs/cgroup
    /dev/mapper/cl-root xfs        50G  9.9G   41G   20% /
    tmpfs               tmpfs     5.9G  684K  5.9G    1% /tmp
    /dev/sda1           xfs       494M  209M  286M   43% /boot
    tmpfs               tmpfs     1.2G   32K  1.2G    1% /run/user/1000
    tmpfs               tmpfs     1.2G   64K  1.2G    1% /run/user/1001
    tmpfs               tmpfs     1.2G     0  1.2G    0% /run/user/0
    
    [9] lspci

    查看pci信息,即 主板所有硬件槽信息

    00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v2/3rd Gen Core processor DRAM Controller (rev 09)
    00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v2/3rd Gen Core processor Graphics Controller (rev 09)
    00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1 (rev 04)
    00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 (rev 05)
    00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller (rev 05)
    00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 (rev b5)
    00:1c.2 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 3 (rev b5)
    00:1c.3 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 4 (rev b5)
    00:1c.5 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 6 (rev b5)
    00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 05)
    00:1f.0 ISA bridge: Intel Corporation H61 Express Chipset LPC Controller (rev 05)
    00:1f.2 SATA controller: Intel Corporation 6 Series/C200 Series Chipset Family 6 port Desktop SATA AHCI Controller (rev 05)
    00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 05)
    02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 07)
    03:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5229 PCI Express Card Reader (rev 01)
    04:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8188EE Wireless Network Adapter (rev 01)
    
    [10] lspci | grep -i 'eth'

    查看网卡硬件信息

    02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 07)
    
    [11] ifconfig -a

    查看系统的所有网络接口 --方式1

    enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.0.11.143  netmask 255.255.255.0  broadcast 10.0.11.255
            inet6 fe80::225:abff:fe7b:350f  prefixlen 64  scopeid 0x20<link>
            ether 00:25:ab:7b:35:0f  txqueuelen 1000  (Ethernet)
            RX packets 1956257  bytes 758582738 (723.4 MiB)
            RX errors 0  dropped 1  overruns 0  frame 0
            TX packets 577940  bytes 61943949 (59.0 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 1000  (Local Loopback)
            RX packets 378776  bytes 35602917 (33.9 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 378776  bytes 35602917 (33.9 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    wlp4s0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
            ether 0e:f1:0d:bc:25:10  txqueuelen 1000  (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
    

    查看系统的所有网络接口 --方式2

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
        link/ether 00:25:ab:7b:35:0f brd ff:ff:ff:ff:ff:ff
    3: wlp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
        link/ether 0e:f1:0d:bc:25:10 brd ff:ff:ff:ff:ff:ff
    
    [13] ip addr

    查看系统的所有网络接口 --方式3

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:25:ab:7b:35:0f brd ff:ff:ff:ff:ff:ff
        inet 10.0.11.143/24 brd 10.0.11.255 scope global noprefixroute enp2s0
           valid_lft forever preferred_lft forever
        inet6 fe80::225:abff:fe7b:350f/64 scope link 
           valid_lft forever preferred_lft forever
    3: wlp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 0e:f1:0d:bc:25:10 brd ff:ff:ff:ff:ff:ff
    
    [14] ethtool eth0

    查看某个网络接口的详细信息,例如:eth0的详细参数和指标
    Link detected: yes # 表示有网线连接,和路由是通的
    Duplex: Full # 全双工

    Settings for enp2s0:
    	Supported ports: [ TP MII ]
    	Supported link modes:   10baseT/Half 10baseT/Full 
    	                        100baseT/Half 100baseT/Full 
    	                        1000baseT/Half 1000baseT/Full 
    	Supported pause frame use: No
    	Supports auto-negotiation: Yes
    	Supported FEC modes: Not reported
    	Advertised link modes:  10baseT/Half 10baseT/Full 
    	                        100baseT/Half 100baseT/Full 
    	                        1000baseT/Half 1000baseT/Full 
    	Advertised pause frame use: No
    	Advertised auto-negotiation: Yes
    	Advertised FEC modes: Not reported
    	Link partner advertised link modes:  10baseT/Half 10baseT/Full 
    	                                     100baseT/Half 100baseT/Full 
    	Link partner advertised pause frame use: Symmetric Receive-only
    	Link partner advertised auto-negotiation: Yes
    	Link partner advertised FEC modes: Not reported
    	Speed: 100Mb/s
    	Duplex: Full
    	Port: MII
    	PHYAD: 0
    	Transceiver: internal
    	Auto-negotiation: on
    	Supports Wake-on: pumbg
    	Wake-on: d
    	Current message level: 0x00000033 (51)
    			       drv probe ifdown ifup
    	Link detected: yes
    

    参考文献

  • 相关阅读:
    创建线程的三种方式
    SpringMVC:拦截器和POST中文乱码问题
    SpringMVC:静态资源访问
    SpringMVC :转发、重定向、RedirectAttributes
    SpringMVC:Controller的编写
    SpringMVC——DispatcherServlet
    SpringMVC的执行流程
    第一个SpringMVC程序(注解实现)
    第一个SpringMVC程序
    springsecurity学习
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/13157624.html
Copyright © 2011-2022 走看看