[Linux]查看硬件及操做系统信息

2021年09月15日 阅读数:1
这篇文章主要向大家介绍[Linux]查看硬件及操做系统信息,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

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

命令

  • 所有硬件及系统信息
    • dmidecode (软硬件所有信息)
    • hostnamectl (系统信息: OS发行版、CPU架构、虚拟化、主机名、Linux内核版本)
    • uname -a (系统信息: CPU架构、主机名、Linux内核版本等)
  • BIOS
    • dmidecode -t bios
  • CPU(指令集/架构/核数等)
    • [arch] / [uname -p] / [uname -m] / [uname -i] / [lscpu | awk 'NR1{print}'] / [hostnamectl | awk 'NR12{print}'] # 查看CPU架构
    • gcc -march=native -Q --help=target|grep march # 查看具体支持的CPU指令集
    • [lscpu] # 查看CPU硬件详情信息(CPU架构、CPU模型、处理器个数/核数、模型名称/厂家、L1/L2/L3的Cache、Hypervisor vendor、cpu family[CPU产品系列代号]等)
    • cat /proc/cpuinfo # 查看CPU的各处理器详情
    • getconf LONG_BIT 查看当前运行模式(运行位数)
  • 内存/swap区
    • cat /proc/meminfo
    • [cat /proc/swaps] 查看哪些swap区被使用
    • [free -h] 单位:KB / [free -m] 单位:MB / [free -g] 单位: GB
  • 硬盘/分区/文件系统(挂载点)
    • mount | column -t
    • fdisk -l
    • lsblk
    • df -hT
    • [cat /proc/mounts] 查看已加载的文件系统
  • PCI设备/USB设备
    • lspci
    • lsusb
  • 网络接口(网卡)/MAC/IP等
    • lspci | grep -i 'eth'
    • ifconfig -a
      • cat /sys/class/net/ens192/address # 查看MAC地址
    • ip addr
    • ip link show
    • ethtool eth0
    • [cat /proc/net/dev] 显示网络适配器(网卡)及统计
  • 主机名(主机名!= 域名)
    • [uname -n] / [hostname] # 查看服务器的主机名
      • hostnamectl set-hostname xxxx 重置hostname
  • Linux内核信息
    • [uname -r/--kernel-release] / [cat /proc/version] / [hostnamectl | awk 'NR==11{print}'] # 查看Linux内核版本信息
  • OS/Linux发行版信息
    • echo $OSTYPE # 查看操做系统类型(darwin:Windows/cygwin:Windows/msys:Windows/win32:Windows/freebsd:freebsd/linux-gnu:Linux)
    • cat /etc/os-release # 查看操做系统详情(发行版类型、NAME/VERSION/ID/ID_LIKE/PRETTY_NAME/ANSI_COLOR/CPE_NAME/HOME_URL/BUG_REPORT_URL/...)
    • [cat /etc/system-release] / [cat /etc/redhat-release] / [cat /etc/centos-release] # 查看操做发行版类型及版本信息
  • 其余
    • [cat /proc/interrupts] 显示中断

[0] dmidecode -q/-t/-s

简介

(Desktop Management Interface,帮助收集电脑系统信息的管理系统,DMI信息的收集必须在严格遵守SMBIOS规范的前提下进行;可输出的Linux服务器硬件信息包括 BIOS、系统、主板、处理器、内存、缓存等)
0 BIOS

1 System

2 Base Board

3 Chassis

4 Processor

5 Memory Controller

6 Memory Module

7 Cache

8 Port Connector

9 System Slots

10 On Board Devices

11 OEM Strings

12 System Configuration Options

13 BIOS Language

14 Group Associations

15 System Event Log

16 Physical Memory Array

17 Memory Device

18 32-bit Memory Error

19 Memory Array Mapped Address

20 Memory Device Mapped Address

21 Built-in Pointing Device

22 Portable Battery

23 System Reset

24 Hardware Security

25 System Power Controls

26 Voltage Probe

27 Cooling Device

28 Temperature Probe

29 Electrical Current Probe

30 Out-of-band Remote Access

31 Boot Integrity Services

32 System Boot

33 64-bit Memory Error

34 Management Device

35 Management Device Component

36 Management Device Threshold Data

37 Memory Channel

38 IPMI Device

39 Power Supply

dmidecode -t bios

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

[linux-shell]# dmidecode -t bios
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
	Vendor: SeaBIOS
	Version: rel-1.10.2-0-g5f4c7b1-20181220_000000-szxrtosci10000
	Release Date: 04/01/2014
	Address: 0xE8000
	Runtime Size: 96 kB
	ROM Size: 64 kB
	Characteristics:
		BIOS characteristics not supported
		Targeted content distribution is supported
	BIOS Revision: 0.0

dmidecode -t system

[linux-shell]# dmidecode -t system
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
	Manufacturer: OpenStack Foundation
	Product Name: OpenStack Nova
	Version: 13.2.2-409
	Serial Number: 125c53ca-477d-43cc-ac48-512e86f01b3c
	UUID: 125C53CA-477D-43CC-AC48-512E86F01B3C
	Wake-up Type: Power Switch
	SKU Number: Not Specified
	Family: Virtual Machine

Handle 0x2000, DMI type 32, 11 bytes
System Boot Information
	Status: No errors detected

[1] lscpu

display information about the CPU architecturelinux

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_BITios

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: 单位为MBes6

              total        used        free      shared  buff/cache   available
Mem:          11903        3996        2650         265        5256        7329
Swap:          8191           0        8191

[4] cat /proc/meminfo

查看内存详细使用shell

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

查看硬盘和分区分布json

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

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

磁盘 /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目录)与分区的关联关系的状态centos

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

查看硬盘使用状况api

文件系统            类型      容量  已用  可用 已用% 挂载点
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

[12] cat /sys/class/net/ens192/address

查看MAC地址

# ifconfig -a
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.100.102.149  netmask 255.255.255.0  broadcast 10.100.102.255
        inet6 fe80::250:56ff:fe85:8b95  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:85:8b:95  txqueuelen 1000  (Ethernet)
        RX packets 138836  bytes 9388486 (8.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4060  bytes 1595871 (1.5 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 487442  bytes 177800691 (169.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 487442  bytes 177800691 (169.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# cat /sys/class/net/ens192/address
00:50:56:85:8b:95

[13] ip link show

查看系统的全部网络接口 --方式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

[14] 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

[15] 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

[16:shell script]

case1: 检测自动化脚本所兼容的操做系统类型

work_dir=$(cd $(dirname $0);pwd)

menu(){
cat <<END
=================================================
        1.Install at Debian(Ubuntu) 10(buster)
        2.Install at Redhat(CentOS) 7
        3.Exit
=================================================
END
}

checkOs(){
	echo "Welcome to install XXX-Software ..."
	echo "This script support CentOS/RedHat/Debian/Ubuntu"
	echo "Please execute script at path $work_dir "

	#To be compatible with MacOS and Linux
	if [[ "$OSTYPE" == "darwin"* ]]; then
    		# Mac OSX
    		echo " install not support Mac OSX operating system"
    		exit 1
	elif [[ "$OSTYPE" == "linux-gnu" ]]; then
   		# linux
		echo "linux"
	elif [[ "$OSTYPE" == "cygwin" ]]; then
    		# POSIX compatibility layer and Linux environment emulation for Windows
    		echo "this install scripts not support Windows operating system"
    		exit 1
	elif [[ "$OSTYPE" == "msys" ]]; then
    		# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
    		echo "this install scripts not support Windows operating system"
    		exit 1
	elif [[ "$OSTYPE" == "win32" ]]; then
    		echo "this install scripts not support Windows operating system"
    		exit 1
	elif [[ "$OSTYPE" == "freebsd"* ]]; then
    		# ...
    		echo "freebsd"
	else
    		# Unknown.
    		echo "Operating system unknown, please tell us(submit issue) for better service"
    		exit 1
	fi

	# 提示信息
	menu

	read -p "Please input number(1|2|3):" num

   	case $num in
        	1)
                  [[ ! -f /etc/debian_version ]] && echo 'Operating system is not Debian or Ubuntu' && exit 1
                  [[ $(grep 'ID=debian' /etc/os-release 2>/dev/null) == 'ID=debian' ]] && [[ $(grep VERSION_ID /etc/os-release 2>/dev/null) != 'VERSION_ID="10"' ]] &&  echo 'System version not support. Debian 10' && exit 1
                  [[ $(grep 'ID=ubuntu' /etc/os-release 2>/dev/null) == 'ID=ubuntu' ]] && [[ ! $(grep VERSION_ID /etc/os-release 2>/dev/null) =~ 'VERSION_ID="18' ]] &&  echo 'System version not support. Ubuntu 18' && exit 1
                  echo "You chose Debian(Ubuntu) 10(buster)"
                	;;
       		2)
       		        [[ ! -f /etc/redhat-release ]] && echo 'Operating system is not Redhat or Centos' && exit 1
                  [[ $(grep VERSION_ID /etc/os-release 2>/dev/null) != 'VERSION_ID="7"' ]] && [[ -f /etc/redhat-release ]] && echo 'System version not support. Redhat 7' && exit 1
                  echo "You chose Redhat(Centos) 7"
                	;;
        	*)
                	echo $"Usage :bash $0"
                	exit 1
	esac
}

case2: 一键获取服务器主要参数

(仅在CentOS上实测)

#【CPU】
CPU_ARCH_VAR=$(lscpu | grep -i Architecture | awk -F ' ' '{printf $2 "\n"}')
CPU_MODEL_VAR=$(lscpu | grep -i "Model name" | awk -F ':' '{printf $2 "\n"}' | sed 's/^[ \t]*//g')
CPU_IS_VIRTUAL_VAR=$(lscpu | grep -i "Hypervisor vendor" | awk -F ':' '{printf $2 "\n"}' | sed 's/^[ \t]*//g')
# echo "CPU { arch="$CPU_ARCH_VAR" / model="$CPU_MODEL_VAR" / isVirtualMechine="$CPU_IS_VIRTUAL_VAR" }"

#【内存】
MEM_TOTAL_VAR=$(free -h | grep -i "Mem" | awk -F ' ' '{printf $2 "\n"}')
MEM_USED_VAR=$(free -h | grep -i "Mem" | awk -F ' ' '{printf $3 "\n"}')
MEM_AVAIL_VAR=$(free -h | grep -i "Mem" | awk -F ' ' '{printf $4 "\n"}')
# echo "MEM { total="$MEM_TOTAL_VAR" / used="$MEM_USED_VAR" / avail="$MEM_AVAIL_VAR" }"

#【硬盘】
DISK_TOTAL_VAR=$(df -hl | grep /dev/mapper/vg | awk -F ' ' '{printf $2 "\n"}')
DISK_USED_VAR=$(df -hl | grep /dev/mapper/vg | awk -F ' ' '{printf $3 "\n"}')
DISK_USED_PERCENT_VAR=$(df -hl | grep /dev/mapper/vg | awk -F ' ' '{printf $5 "\n"}')
DISK_AVAIL_VAR=$(df -hl | grep /dev/mapper/vg | awk -F ' ' '{printf $4 "\n"}')
# echo "DISK { total="$DISK_TOTAL_VAR" / used="$DISK_USED_VAR"("$DISK_USED_PERCENT_VAR") / avail="$DISK_AVAIL_VAR" } ";

#【操做系统】
OS_KERNEL_VERSION_VAR=$(cat /proc/version)
OS_CENTOS_VAR=$(cat /etc/redhat-release)
# echo "OS { Linux-Kernel="$OS_KERNEL_VERSION_VAR" / CentOS-Version="$OS_CENTOS_VAR" }";

#【MAC】
MACs_VAR=$(ifconfig | grep -i ether | awk -F ' ' '{printf $2 "\n"}')
# echo "MACs { macs="$MACs_VAR"} ";

#【节点名(域名)/IP】
DNS_NODENAME_VAR=$(uname -n)
# 或 DNS_NODENAME_VAR=$(hostname)
DNS_IP_VAR="$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}')"
DNS_IP_VAR="$(ifconfig |grep inet|awk -F "[: ]+" '{print $3}'|head -n1)"
# echo "DNS { ip="${DNS_IP_VAR}" / nodename="$DNS_NODENAME_VAR" } ";
DATE_STR=`date "+%Y-%m-%d %H:%M:%S"`;

CPU="CPU { arch="$CPU_ARCH_VAR" / model="$CPU_MODEL_VAR" / isVirtualMechine="$CPU_IS_VIRTUAL_VAR" }"
MEM="MEM { total="$MEM_TOTAL_VAR" / used="$MEM_USED_VAR" / avail="$MEM_AVAIL_VAR" }"
DISK="DISK { total="$DISK_TOTAL_VAR" / used="$DISK_USED_VAR"("$DISK_USED_PERCENT_VAR") / avail="$DISK_AVAIL_VAR" } ";
OS="OS { Linux-Kernel="$OS_KERNEL_VERSION_VAR" / CentOS-Version="$OS_CENTOS_VAR" }";
MACs="MACs { macs="$MACs_VAR"} ";
DNS="DNS { ip="${DNS_IP_VAR}" / nodename="$DNS_NODENAME_VAR" } ";

echo -e "SERVER BASE INFO
$CPU
$MEM
$DISK
$MACs
$DNS
(updated on $DATE_STR)"

Y 补充命令: lshw 【待续】

lshw(Hardware Lister)是另一个能够查看硬件信息的工具,不只如此,它还能够用来作一些硬件的benchmark。
这个工具其实就是用/proc里面读取一些文件来显示相关的信息,它用到了以下文件和目录(下的文件):

/proc/cpuinfo 显示CPU信息
/proc/bus/pci 显示pci信息
/proc/scsi 显示scsi信息
/proc/net/dev 显示网络设备信息
/proc/kcore 从内存映像读取相关信息
/proc/ide 显示IDE设备信息
/proc/devices
/proc/mounts
/proc/fstab
  • 安装
yum install -y lshw
  • 查看版本
[root@sdc234 ~]# lshw -version
B.02.18
  • 以html/xml/json格式输出
    -html :将设备信息以 html的格式输出
    -xml :将设备信息以 xml的格式输出
    -json :将设备信息以 json的格式输出
lshw -html > info.html

lshw -xml > info.xml

lshw -json > info.xml

X 参考文献