https://zhuanlan.zhihu.com/p/144368206
Linux服务器配置文档找不到,你还在为查询Linux服务器硬件信息发愁吗?学会这些命令,让你轻松查看Linux服务器的CPU,内存,硬盘,SN序列号等信息,根本就不用去机房。
CPU信息常常包括查看CPU型号信息,物理CPU个数,每个物理CPU中core的个数(即核数),逻辑CPU个数信息。默认Linux服务器中,这些信息都保存在/proc/cpuinfo
文件中,通过cat命令结合grep命令我们可以很容易查询出来。
1、查看CPU型号信息
[root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
32 Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
这其中的32
是逻辑CPU的个数,Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
是CPU型号信息及频率。
2、查看物理CPU个数
[root@localhost ~]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
2
上面命令执行后,结果为2
,这就是物理CPU个数。
3、每个物理CPU中核数
[root@localhost ~]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores : 8
可以从结果中看出,每个cpu核数是8
。
4、查看逻辑CPU的个数
[root@localhost ~]# cat /proc/cpuinfo| grep "processor"| wc -l
32
5、整体查看CPU相关信息
lscpu
输出结果:
[root@localhost ~]# lscpu
Architecture: x86_64 #cpu架构
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 32 #逻辑CPU核数
On-line CPU(s) list: 0-31
Thread(s) per core: 2 #每核超线程数
Core(s) per socket: 8 #每个cpu核数
Socket(s): 2 #物理cpu个数
NUMA node(s): 2
Vendor ID: GenuineIntel #cpu产商 intel
CPU family: 6
Model: 62
Model name: Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
Stepping: 4
CPU MHz: 1200.000 #cpu主频
BogoMIPS: 5187.29
Virtualization: VT-x #支持cpu虚拟化技术
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 20480K
NUMA node0 CPU(s): 0-7,16-23
NUMA node1 CPU(s): 8-15,24-31
结合上面的信息,我们需要了解的CPU的物理数,CPU核数,物理核数,超线程数概念关系如下:
CPU总核数(16) = 物理CPU个数(2) * 每颗物理CPU的核数(8)
CPU总逻辑数(32) = 物理CPU个数(2) * 每颗物理CPU的核数(8) * 超线程数(2)
在Linux系统中查看linux内存的大小时,我们最长用到的命令就是free
命令。free命令可以查看当前内存大小及使用情况,但如果要查看更多关于内存的物理信息,例如内存条数,内存插槽数,内存速率等信息,我们就需要dmidecode
命令。
dmidecode
命令工具用于获取服务器的硬件信息,不用到机房打开机箱查看设备型号,使用该命令来查找硬件详细信息。
1、查看内存使用情况
[root@localhost ~]# free -h
total used free shared buffers cached
Mem: 62G 60G 2.7G 1.2M 483M 56G
-/+ buffers/cache: 3.1G 59G
Swap: 31G 0B 31G
-h
以人类可读的方式显示,即后边会自动带上单位。
更多关于free命令使用,可以查看《如何在Linux系统中使用linux free命令》教程介绍。
2、查询内存(RAM)信息 通过以下命令,可以查询机器最大支持的内存总量**
[root@localhost ~]# dmidecode -t 16
# dmidecode 2.12
SMBIOS 2.7 present.
Handle 0x002B, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 768 GB
Error Information Handle: Not Provided
Number Of Devices: 12
这里可以查看到当前服务器允许扩容的最大内存,从输出结果可以看出,该机器理论上支持的最大内存为768G。
3、查看可用内存大小
首先我们可以通过cat命令查看/proc/meminfo
文件内容获取内存大小信息。
[root@localhost ~]# grep MemTotal /proc/meminfo
MemTotal: 65890032 kB
4、查看内存大小、内存数、内存插槽数
[root@localhost ~]# dmidecode|grep -P -A5 "Memory Device" |grep Size
Size: 16384 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: 16384 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: 16384 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: 16384 MB
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
Size: No Module Installed
从上面的结果可以看出,插槽总数为24,内存数量为4,总大小为4 x 16384 MB = 65536 MB ,65536 MB /1024 = 64G。
5、查看内存速率
[root@localhost ~]# dmidecode|grep -A16 "Memory Device"|grep 'Speed' | grep -v "Unknown"
Speed: 1600 MHz
Speed: 1600 MHz
Speed: 1600 MHz
Speed: 1600 MHz
从上面的结果我们们可以看出,所有内存的速率都是1600 MHz。
查看挂接的分区状态
1、查看挂接的分区状态
[root@localhost ~]# fdisk -l |grep Disk
Disk /dev/sda: 1197.8 GB, 1197759004672 bytes
Disk identifier: 0x0005efcd
2、查看硬盘和分区分布
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.1T 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 31.3G 0 part [SWAP]
└─sda3 8:3 0 1.1T 0 part /
sr0 11:0 1 1024M 0 rom
3、查看硬盘和分区的详细信息
[root@localhost ~]# fdisk -l
Disk /dev/sda: 1197.8 GB, 1197759004672 bytes
255 heads, 63 sectors/track, 145619 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: 0x0005efcd
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 4144 32768000 82 Linux swap / Solaris
/dev/sda3 4144 145620 1136405504 83 Linux
4、查看挂接的分区状态
[root@localhost ~]# mount | column -t
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /sys/kernel/config type configfs (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
5、查看硬盘使用情况
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 1.1T 355G 658G 36% /
tmpfs tmpfs 32G 68K 32G 1% /dev/shm
/dev/sda1 ext4 477M 40M 412M 9% /boot
1、查看网卡硬件信息
[root@localhost ~]# lspci | grep -i 'eth'
02:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
02:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
07:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
07:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
查看系统的所有网络接口
ifconfig -a
ip link show
查看某个网络接口的详细信息,例如eth0的详细参数和指标
[root@localhost ~]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
dmidecode命令不仅仅可以查看内存等信息,另外这个命令强大到几乎可以查任何硬件信息 包括设备型号、bios 、cpu、主板 、处理器、内存、缓存详细信息等等都例举出来。
1、查看服务器型号、序列号
[root@localhost ~]# dmidecode|grep "System Information" -A9|egrep "Manufacturer|Product|Serial"
Manufacturer: FUJITSU
Product Name: PRIMERGY RX200 S8
Serial Number: MANS012234
2、查看主板型号
[root@localhost ~]# dmidecode |grep -A16 "System Information$"
System Information
Manufacturer: FUJITSU
Product Name: PRIMERGY RX200 S8
Version: GS01
Serial Number: MANS012234
UUID: 2B5C344E-4406-E411-9EFE-70E284092502
Wake-up Type: Power Switch
SKU Number: S26361-K1455-Vxxx
Family: SERVER
Handle 0x0002, DMI type 2, 15 bytes
Base Board Information
Manufacturer: FUJITSU
Product Name: D3302-A1
Version: S26361-D3302-A100 GS02
Serial Number: 5556W06001G4280004BJ0D1
Asset Tag:
3、查看BIOS信息
[root@localhost ~]# dmidecode -t bios
# dmidecode 2.12
SMBIOS 2.7 present.
Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
Vendor: FUJITSU // American Megatrends Inc.
Version: V4.6.5.4 R1.8.0 for D3302-A1x
Release Date: 06/23/2014
Address: 0xF0000
Runtime Size: 64 kB
ROM Size: 13248 kB
Characteristics:
PCI is supported
BIOS is upgradeable
BIOS shadowing is allowed
Boot from CD is supported
Selectable boot is supported
EDD is supported
Print screen service is supported (int 5h)
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.8
Handle 0x0114, DMI type 13, 22 bytes
BIOS Language Information
Language Description Format: Abbreviated
Installable Languages: 1
enUS
Currently Installed Language: enUS
如果要了解更多关于dmidecode,不妨在命令终端中输入dmidecode --help
查看该命令的具体使用说明。
对于大部分普通Linux用户来说,不知道这些命令很正常。但是如果你需要了解一下服务器信息时,这些命令就非常有用了,不论是维系系统还是核查设备信息,绝对是必备技能。
也许你现在不需要,但你以后可能会用到,聪明的你不妨先做收藏以备后用。
关注公众号『Linux265』获取更多Linux 新鲜事,技术资讯、相关教程,软件推荐等。我在这里等你!这里有您,有我,有大家!