在 Linux 下,我们经常需要查看系统的硬件信息, 这里我罗列了查看系统硬件信息的实用命令,并做了分类,实例解说。
由于我所使用的是腾讯云的云主机,所以会有很多参数没有,但您可以在真实的服务器上查询得到
CPU
lscpu---查看的是 cpu 的统计信息
[root@cn-sh ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 94
Model name: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping: 3
CPU MHz: 2394.374
BogoMIPS: 4788.74
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
L3 cache: 28160K
NUMA node0 CPU(s): 0,1
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl 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 3dnowprefetch invpcid_single fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat
查看/proc/cpuinfo
,可以知道每个cpu信息,如每个CPU的型号,主频等
[root@cn-sh ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
stepping : 3
microcode : 0x1
cpu MHz : 2394.374
cache size : 28160 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
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 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl 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 3dnowprefetch invpcid_single fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat
bogomips : 4788.74
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
stepping : 3
microcode : 0x1
cpu MHz : 2394.374
cache size : 28160 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
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 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl 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 3dnowprefetch invpcid_single fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat
bogomips : 4788.74
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
内存
概要查看内存情况
[root@cn-sh ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 630M 2.1G 808K 1.0G 2.8G
Swap: 0B 0B 0B
查看内存详细使用
[root@cn-sh ~]# cat /proc/meminfo
MemTotal: 3880168 kB
MemFree: 2179824 kB
MemAvailable: 2953032 kB
Buffers: 140184 kB
Cached: 712932 kB
SwapCached: 0 kB
Active: 1098856 kB
Inactive: 265416 kB
Active(anon): 511272 kB
Inactive(anon): 696 kB
Active(file): 587584 kB
Inactive(file): 264720 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 308 kB
Writeback: 0 kB
AnonPages: 511208 kB
Mapped: 66772 kB
Shmem: 808 kB
Slab: 234540 kB
SReclaimable: 210124 kB
SUnreclaim: 24416 kB
KernelStack: 2928 kB
PageTables: 29976 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1940084 kB
Committed_AS: 1776716 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 12832 kB
VmallocChunk: 34359720444 kB
Percpu: 328 kB
HardwareCorrupted: 0 kB
AnonHugePages: 67584 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 59256 kB
DirectMap2M: 3086336 kB
DirectMap1G: 3145728 kB
查看内存硬件信息
[root@cn-sh ~]# dmidecode -t memory
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
Location: Other
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 1
Handle 0x1100, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: 4096 MB
Form Factor: DIMM
Set: None
Locator: DIMM 0
Bank Locator: Not Specified
Type: RAM
Type Detail: Other
Speed: Unknown
Manufacturer: Smdbmds
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown
Configured Memory Speed: Unknown
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: Unknown
磁盘
查看硬盘和分区分布
[root@cn-sh ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 16.5M 0 rom
vda 253:0 0 50G 0 disk
└─vda1 253:1 0 50G 0 part /
查看硬盘和分区的详细信息
[root@cn-sh ~]# fdisk -l
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d64b4
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857566 52427759+ 83 Linux
网卡
查看网卡硬件信息
[root@cn-sh ~]# lspci | grep -i 'eth'
00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device
查看系统的所有网络接口
[root@cn-sh ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.7 netmask 255.255.240.0 broadcast 172.17.15.255
inet6 fe80::5054:ff:fe4e:6e10 prefixlen 64 scopeid 0x20<link>
ether 52:54:00:4e:6e:10 txqueuelen 1000 (Ethernet)
RX packets 76544140 bytes 52961330313 (49.3 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 49994906 bytes 14614980486 (13.6 GiB)
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 1114162 bytes 4204361788 (3.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1114162 bytes 4204361788 (3.9 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
或者是
[root@cn-sh ~]# ip link show
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:4e:6e:10 brd ff:ff:ff:ff:ff:ff
又或者是
[root@cn-sh ~]# cat /proc/net/dev
Inter-| Receive | Transmitface |bytes packets errs drop fifo frame compressed multicast | bytes packets errs drop fifo colls carrier compressed
eth0: 52962064257 76545540 0 0 0 0 0 0 14615225394 49996010 0 0 0 0 0 0
lo: 4204456644 1114222 0 0 0 0 0 0 4204456644 1114222 0 0 0 0 0 0
看某个网卡的详细信息
[root@cn-sh ~]# ethtool eth0
Settings for eth0:
Link detected: yes
PCI
查看pci信息,即主板所有硬件槽信息
[root@cn-sh ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
00:04.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:06.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:07.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
BIOS
[root@cn-sh ~]# dmidecode -t bios
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
Vendor: SeaBIOS
Version: seabios-1.9.1-qemu-project.org
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以一种可读的方式dump出机器的DMI(Desktop Management Interface)信息,这些信息包括了硬件以及BIOS,既可以得到当前的配置,也可以得到系统支持的最大配置,比如说支持的最大内存数等,如果要查看所有有用信息,可以使用dmidecode -q
,里面包含了很多硬件信息。
一次性看全的作弊码
lshw