盒子
盒子

Linux系统信息查看(一)

对于一台新的Linux计算机或者服务器,我们需要收集一些关于这台机器的硬件信息。当你更换机器的内存或者网卡以及硬盘等硬件设备时候同样十分有用,因为更换之前你需要首先收集你系统硬件信息的型号,以此来挑选相应的硬件,这里列出几个常用的用于收集硬件信息的指令。

所有以下的指令都是在我自己的Ubuntu15.10上做的测试,但这些指令同样适用于Debian系的其他发行版,部分指令适用于RedHat系。

1.查看系统主机名

查看hostname

1
2
3
4
$ hostname
Finder
$ cat /etc/hostname
Finder

查看DNS domain name

1
2
$ dnsdomainname
cyberciti.biz

查看系统全称域名

1
2
$ hostname -f
Finder

2.查看主板序列号、机器制造商以及架构名称

1
2
3
4
5
6
$ sudo dmidecode -s system-serial-number
N/A
$ sudo dmidecode -s system-manufacturer
Hasee Computer Co.,Ltd.
$ sudo dmidecode -s system-product-name
CW35

或者使用lshw指令

1
2
3
4
5
6
7
8
9
10
$ lshw | more
finder
description: Computer
width: 64 bits
capabilities: vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
(信息较多,部分忽略)

3.查看已安装的硬件

1
2
3
4
5
6
7
8
$ sudo lsdev
Device DMA IRQ I/O Ports
------------------------------------------------
0000:00:02.0 f000-f03f
0000:00:1f.2 28 f060-f07f f080-f083 f090-f097 f0a0-f0a3 f0b0-f0b7
0000:00:1f.3 f040-f05f
0000:01:00.0 e000-e07f
(信息较多,部分忽略)

4.查看CPU信息

1
2
3
4
5
6
7
8
9
10
11
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
stepping : 9
microcode : 0x12
cpu MHz : 1200.000
cache size : 6144 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
$ lscpu
Architecture: x86_64
CPU 运行模式: 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
每个核的线程数:2
每个座的核数: 4
Socket(s): 1
NUMA 节点: 1
厂商 ID: GenuineIntel
CPU 系列: 6
型号: 58
Model name: Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
步进: 9
CPU MHz: 1217.062
CPU max MHz: 3400.0000
CPU min MHz: 1200.0000
BogoMIPS: 4789.17
虚拟化: VT-x
L1d 缓存: 32K
L1i 缓存: 32K
L2 缓存: 256K
L3 缓存: 6144K
NUMA node0 CPU(s): 0-7

5.查看CPU相关数据

1
2
3
4
5
$ sudo mpstat
Linux 4.2.0-34-generic (Finder) 2015年11月12日 _x86_64_ (8 CPU)

12时53分14秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12时53分14秒 all 7.79 0.60 2.65 0.28 0.00 0.01 0.00 0.00 0.00 88.67

注意:使用上述操作前请安装sysstat,执行apt-get install sysstat

6.查看内存信息

1
2
3
4
5
6
7
8
9
10
11
12
$ sudo dmidecode -t 16
# dmidecode 2.12
SMBIOS 2.7 present.

Handle 0x0040, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 4

上述信息中Maximum Capacity: 32 GB表示系统最大支持32GB内存,Number Of Devices: 4表示系统有四个内存插槽。

7.查看系统交换空间的使用情况

1
2
3
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sdb1 partition 2000892 0 -1

8.查看系统虚拟内存数据

1
2
3
4
$ sudo vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 11852376 203272 2081544 0 0 38 56 198 394 8 3 89 0 0

9.查看Linux发行版本及相关信息

1
2
3
4
5
6
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 15.10
Release: 15.10
Codename: wily

10.查看系统内核版本号

1
2
$ uname -r
4.2.0-34-generic

或者

1
2
$ uname -a
Linux Finder 4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux