Linux系统资源管理 之 硬件信息

1. CPU

  • lscpu :

一般不加参数,直接使用该命令.

  • cat /proc/cpuinfo:

该文件中列出了CPU的详细信息,类似于'lscpu'命令

lscpu

[niesh @niesh Desktop]$ lscpu
Architecture:          x86_64           #CPU的架构(64bit)
CPU op-mode(s):        32-bit, 64-bit   #支持32-bit和64-bit
Byte Order:            Little Endian    #小端(x86架构皆为小端模式)
CPU(s):                1                #总共1个CPU
On-line CPU(s) list:   0
Thread(s) per core:    1                #每个cpu核心,只能运行一个线程
Core(s) per socket:    1                #只有一个核心(因为我在虚拟机里)
Socket(s):             1                
NUMA node(s):          1
Vendor ID:             GenuineIntel     #Intel生产
CPU family:            6
Model:                 142
Model name:            Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Stepping:              9
CPU MHz:               2712.002         #CPU的频率(2712/1024 ~~ 2.5G)
BogoMIPS:              5424.00
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K              #L1 cache for data
L1i cache:             32K              #L1 cache for instruction
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0

/proc/cpuinfo

[niesh  @niesh ~]$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 142
model name      : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping        : 9
microcode       : 0x4e
cpu MHz         : 2712.002
cache size      : 3072 KB
physical id     : 0
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 ida arat epb pln pts dtherm hwp hwp_noitfy hwp_act_window hwp_epp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt
bogomips        : 5424.00
clflush size    : 64
cache_alignment : 64
address sizes   : 42 bits physical, 48 bits virtual
power management:

2. 内存

查看内存的命令有多种,如下:

  • free: //查看内存大小

-b: 以byte形式显示
-k: 以KB形式显示
-m: 以MB形式显示
-g: 以GB形式显示
-h: 以方便人类观察的形式显示

  • cat /proc/meminfo: //内存的详细硬件信息
  • vmstat [sec/time][times] : //类似top, 查看整个机器CPU、MEM、IO使用情况

sec/times: 多少秒刷新一次
times: 刷新多少次,不写则表示持续

  • dmidecode -t memeory:

显示memory的详细硬件信息

free:

[niesh@niesh ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.4G        602M        427M         10M        452M        664M
Swap:          2.0G          0B        2.0G

PS:

buf缓冲,指用于“写入”的一块内存
cache缓存,指用于“读取”的一块内存

cat /proc/meminfo:

[niesh@niesh ~]$ cat /proc/meminfo
MemTotal:        1517428 kB
MemFree:          437744 kB
MemAvailable:     680592 kB
Buffers:            1260 kB
Cached:           328404 kB
SwapCached:            0 kB
Active:           570780 kB
Inactive:         254344 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
...

vmstat:

[niesh@niesh ~]$ vmstat 3 3     ##3秒每次,总共3次
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 437612   1260 461948    0    0    21     2   55  135  0  1 99  0  0
 0  0      0 437612   1260 461948    0    0     0     0   34   59  0  0 100  0  0
 0  0      0 437612   1260 461948    0    0     0     0   32   51  0  0 100  0  0

以上各列解释如下:

r: Running, 正在运行和等待运行的进程数
b: Sleeping,处于Sleeeping状态的进程数
swpd: 虚拟内存使用量,一般为0,否则可能是物理内存不够用了
free: 物理内存空闲大小
buf: 缓冲区大小
cache: 缓存大小
si: 每秒从虚拟内存写入硬盘的大小
so: 每秒从硬盘读入到虚拟内存的大小
bi: 块设备每秒接受的块数量
bo: 块设备每秒发送的块数量
in: interrupt, 每秒中断CPU的次数
cs: context switch,每秒切换上下文的次数
us: 用户CPU时间,%
sy: 系统CPU时间
id: 空闲CPU时间
wa: 等待IO的CPU时间

3. 磁盘

  • fdisk -l:

查看磁盘分区, 此命令必须root执行

  • df -h:

列出磁盘的总大小和使用情况

  • du -h:

使用该命令,我们可以查看硬盘的使用情况,但是它会列出所有目录的大小;该命令的常用用法一般为统计一个目录的大小:

fdisk -l

[root@niesh ~]# fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00071326

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM
磁盘 /dev/mapper/centos_niesh-root:18.8 GB, 18756927488 字节,36634624 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos_niesh-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

以上我们可以看到 /dev/sda1字样,那它代表什么意思呢?
我们知道,磁盘我们最常用的接口形式有两种:IDE & SATA,不同的接口形式,Linux的显示是不一样的:

  • IDE

盘符:hd[a-z][1-n]

hd:代表IDE接口
a-z:硬盘数量排序(a代表第一块,b第二块,以此类推)
0-n: 代表第几个分区

EX: hdb2代表第二块磁盘的第二个分区

  • SATA

盘符:sd[a-z][1-n]
解析同上
注意:分区部分,若为1-4则表示主分区(包含扩展分区),>=5表示逻辑分区

df -h

[root@niesh ~]# df -h
文件系统                       容量  已用  可用 已用% 挂载点
/dev/mapper/centos_niesh-root   18G  9.1G  8.5G   52% /
devtmpfs                       726M     0  726M    0% /dev
tmpfs                          741M  156K  741M    1% /dev/shm
tmpfs                          741M  9.1M  732M    2% /run
tmpfs                          741M     0  741M    0% /sys/fs/cgroup
/dev/sda1                      497M  158M  339M   32% /boot
.host:/                        222G   17G  206G    8% /mnt/hgfs
tmpfs                          149M   20K  149M    1% /run/user/1000

一般我们只关心 / /boot 挂载点的大小;

du -h

[root@niesh ~]# du -sh /root
40M     /root
[root@niesh ~]# du -sh  /dev
156K    /dev
[root@niesh ~]# du -sh  /etc
36M     /etc

4. ip地址信息:

  • ifconfig -a:

查看本机所有的网络接口信息和ip地址信息

[root@niesh ~]# ifconfig -a
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.139.129  netmask 255.255.255.0  broadcast 192.168.139.255
        inet6 fe80::20c:29ff:feb5:18f9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b5:18:f9  txqueuelen 1000  (Ethernet)
        RX packets 11758  bytes 779308 (761.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5065  bytes 635337 (620.4 KiB)
        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 0  (Local Loopback)
        RX packets 12  bytes 732 (732.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 732 (732.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 00:00:00:00:00:00  txqueuelen 0  (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

如上所示,我这里包含了三个网络接口:

  • eno167777736:

CentOS 7.x 的命名规则,其实就相当于eth0

  • lo:

loop,回环网络设备,ip地址固定为127.0.0.1,一般localhost绑定到此端口,只要本机的网络组建没问题,便可以ping通;否则,你就要好好检查一下自己的网络硬件了!

  • birbr0:

虚拟机的网络接口,不做详细介绍!

5. 其它

以下几个命令非常强大,可以查看几乎所有的硬件信息:

  • dmesg:

详细信息参见:http://blog.csdn.net/rwdxll/article/details/38560137

  • lspci:

详细信息参考:http://blog.csdn.net/styshoo/article/details/51281437

  • dmidecode:

详细信息请参考:http://www.laozuo.org/6682.html

原文地址:https://www.cnblogs.com/Jimmy1988/p/7423491.html