linux查看系统硬件信息
服务器硬件数据的收集
回到顶部
dmidecode解析硬件配备。
dmidecode可以解析 CPU 型号、主板型号与内存相关的型号等等:
[root@study ~]# dmidecode -t type选项与参数:
1 :详细的系统数据,含主板的型号与硬件的基础数据;详细的 type 项目请 man dmidecode 查询更多的数据,这里仅列出比较常用的项目
4 :CPU的相关信息,包括倍频、外频、内核数、内核绪数等;
9 :系统的相关插槽格式,包括PCI, PCI-E等的插槽规格说明;
17:每一个内存插槽的规格,若内有内存,则列出该内存的容量与型号;
列出整个系统的硬件信息,例如主板型号等:
[root@study ~]# dmidecode -t 1 # dmidecode 3.1 Getting SMBIOS data from sysfs. SMBIOS 2.5 present. Handle 0x0001, DMI type 1, 27 bytes System Information Manufacturer: innotek GmbH Product Name: VirtualBox Version: 1.2 Serial Number: 0 UUID: B02FA249-A7E1-4EC1-8EE0-6E0F0826AB3E Wake-up Type: Power Switch SKU Number: Not Specified Family: Virtual Machine列出内存相关的数据:
[root@study ~]# dmidecode -t 17 # dmidecode 3.1 SMBIOS 2.5 present. Handle 0x1100, DMI type 17, 21 bytes Memory Device Array Handle: 0x1000 Error Information Handle: 0x0000 Total Width: 64 bits Data Width: 64 bits Size: 3072 MB Form Factor: DIMMSet: None Locator: DIMM 0 Bank Locator: Not Specified Type: RAM Type Detail: None因为我们的系统是虚拟机,否则的话,你的主板型号、每一只安插的内存容量等等,都会被列出来! 这样可以了解系统的所有主要硬件配备!
硬件资源的收集与分析
回到顶部
系统硬件是由操作系统内核管理的,Linux kernel在开机时就能够侦测主机硬件并加载适当的模块来驱动硬件。
内核侦测到的各项硬件设备,会记录在/proc与/sys目录中。 包括/proc/cpuinfo, /proc/partitions,/proc/interrupts等。
除了直接查看/proc目录下的文件内容之外,Linux也提供几个简单的指令来查看内核所侦测到的硬件信息:
gdisk:可以使用 gdisk -l 将分区表列出;想要知道主板与各周边相关设备时,lspci是不可多得的好工具!使用lsusb查看目前USB插槽的使用情况以及侦测到的USB设备! iostat与vmstat类似,是一个实时分析软件!
dmesg:观察内核运作过程当中所显示的各项信息;
vmstat:可分析系统 (CPU/RAM/IO)目前的状态;
lspci:列出整个PC系统的PCI接口设备;
lsusb:列出目前系统上面各个USB端口的状态,与连接的USB设备;
iostat:与vmstat类似,可实时列出整个CPU与接口设备的Input/Output状态。
如果想要知道Linux主机的硬件配备,最好的方法还是直接拆开机壳去察看上面的信息! 如果环境因素导致无法直接拆开主机的话,那么就可以使用上面列出的命令查看。
lspci
回到顶部
lspci显示主机上面的各个PCI接口的设备!
[root@study ~]# lspci [-vvn]选项与参数:
-v: 显示更多的 PCI 接口设备的详细信息;查阅系统内的PCI总线相关设备:
-vv: 比 -v 还要更详细的细部信息;
-n: 直接观察 PCI 的 ID 而不是厂商名称
[root@study ~]# 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 82371AB/EB/MB PIIX4 IDE (rev 01) 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter 00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02) 00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service 00:05.0 Multimedia audio controller: Intel Corporation 82801AA AC'97 Audio Controller (rev 01) 00:06.0 USB controller: Apple Inc. KeyLargo/Intrepid USB 00:07.0 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08) 00:0d.0 SATA controller: Intel Corporation 82801HM/HEM (ICH8M/ICH8M-E) SATA Controller [AHCI mode] (rev 02)上面的信息显示linux主机使用Intel芯片的仿真主板、南桥使用ICH9的控制芯片、附挂QXL的显示适配器、使用虚拟化的Virtio网络卡等。
如果你还想要了解某个设备的详细信息时,可以加上 -v 或 -vv 来显示更多的信息喔!
想要知道以太网络卡更详细的信息时,可以使用如下的选项来处理:
[root@study ~]# lspci -s 00:03.0 -vv-s后面接的每个设备的总线、插槽与相关函数功能!那个是我们硬件侦测所得到的数据啰! 你可以对照底下这个文件来了解该串数据的意义:
/usr/share/hwdata/pci.ids
其实那个就是 PCI 的标准 ID 与厂牌名称的对应表啦!此外,刚刚我们使用 lspci 时,其实所有的数据都是由/proc/bus/pci/目录下的数据所取出的呢
不过,由于硬件的发展太过迅速,所以你的 pci.ids 文件可能会落伍了~那怎办? 没关系~可以使用底下的方式来在线更新你的对应档:
[root@study ~]# update-pciids
lsusb
回到顶部
lsusb列出系统中的所有USB接口设备!
[root@study ~]# lsusb [-t]
选项与参数:
-t:使用类似树状目录来显示各个 USB 端口口的相关性列出主机USB各端口状态:
[root@study ~]# lsusb Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub如上所示,在Bus 001接了一个设备,该设备的 ID 是 80ee:0021,对应的厂商与产品为VirtualBox的设备。
ID号码与厂商型号对照了!那也是写入在/usr/share/hwdata/pci.ids的东西,可以自行查询!
iostat
回到顶部
想要知道磁盘由开机到现在,已经存取多少数据?这个时候就得用到iostat指令了!
默认CentOS并没有安装这个软件!使用yum/apt install sysstat先来安装此软件吧!
[root@study ~]# iostat [-c|-d] [-k|-m] [-t] [间隔秒数] [侦测次数]选项与参数:
-c :仅显示 CPU 的状态;显示目前整个系统的CPU与储存设备的状态:
-d :仅显示储存设备的状态,不可与 -c 一起用;
-k :默认显示的是 block ,这里可以改成 K bytes 的大小来显示;
-m :与 -k 类似,只是以 MB 的单位来显示结果。
-t :显示日期出来;
[root@study ~]# iostat Linux 4.15.0-140-generic (www.initroot.com) 11/14/2021 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 9.51 0.00 2.11 1.64 0.00 86.74 Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 17.20 113.23 139.06 28369609 34842056上面数据总共分为上下两部分,上半部显示的是CPU的当前信息;
# 下面数据则是显示储存设备包括 /dev/vda 的相关数据,他的数据意义:
# tps :平均每秒钟的传送次数!与数据传输『次数』有关,非容量!
# kB_read/s :开机到现在平均的读取单位;
# kB_wrtn/s :开机到现在平均的写入单位;
# kB_read :开机到现在,总共读出来的文件单位;
# kB_wrtn :开机到现在,总共写入的文件单位;
每两秒钟侦测一次sda设备,并且共侦测三次储存设备:
[root@study ~]# iostat -d 2 3 sda Linux 4.15.0-140-generic (www.initroot.com) 11/14/2021 _x86_64_ (4 CPU) Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 17.20 113.18 139.31 28369921 34917976 Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 7.00 0.00 62.00 0 124 Device tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0# 仔细看一下,如果是有侦测次数的情况,那么第一次显示的是『从开机到现在的数据』,
# 第二次以后所显示的数据则代表两次侦测之间的系统传输值!举例来说,上面的信息中,
# 第二次显示的数据,则是两秒钟内(本案例)系统的总传输量与平均值。透过 lspci 及 iostat 可以约略的了解到目前系统的状态还有目前的主机硬件数据呢!
了解磁盘的健康状态
回到顶部
Linux server最重要的就是数据安全了!数据都是放在磁盘当中的,所以经常了解一下磁盘健康状况是个好习惯!
怎么知道磁盘是好是坏呢?这就得要来谈一个smartd服务了!
SMART其实是Self-Monitoring, Analysis and Reporting Technology System的缩写,主要用来监测目前常见的ATA与SCSI接口的磁盘,
被监测的磁盘也必须要支持SMART协议才行!否则smartd就无法去下达指令,让磁盘进行自我健康检查~
不过刚刚好还有另外一颗用作 IDE 界面的2G 磁盘, 这个就能够用来作为测试了! (/dev/sda)!
smartd 提供一只指令名为 smartctl,这个指令功能非常多!不过我们底下只想要介绍数个基本的操作,让各位了解一下如何确认你的磁盘是好是坏!
使用sudo apt install smartmontools安装smartctl工具。
1. 用smartctl来显示完整的/dev/sda的信息:
[root@study ~]# smartctl -a /dev/sda smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-229.el7.x86_64] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org #首先输出磁盘的整体信息!包括制造商、序号、格式、SMART支持度等! === START OF INFORMATION SECTION === Device Model: QEMU HARDDISK Serial Number: QM00002 Firmware Version: 0.12.1 User Capacity: 2,148,073,472 bytes [2.14 GB] Sector Size: 512 bytes logical/physical Device is: Not in smartctl database [for details use: -P showall] ATA Version is: ATA/ATAPI-7, ATA/ATAPI-5 published, ANSI NCITS 340-2000 Local Time is: Wed Sep 2 18:10:38 2015 CST SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED #接下来则是一堆基础说明! General SMART Values: Offline data collection status: (0x82) Offline data collection activity was completed without error. Auto Offline Data Collection: Enabled. ... #有没有曾经发生过磁盘错乱的问题记录! SMART Error Log Version: 1 No Errors Logged #当执行过磁盘自我检测,就会记录在这里! SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Short offline Completed without error 00% 4660 - # 2 Short offline Completed without error 00% 4660 -命令磁盘进行一次自我检测,再次观察磁盘状态:
[root@study ~]# smartctl -t short /dev/sda [root@study ~]# smartctl -a /dev/sda ... # 底下会多出一个第三笔的测试信息!看一下 Status 的状态,没有问题就是好消息! SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Short offline Completed without error 00% 4660 - # 2 Short offline Completed without error 00% 4660 - # 3 Short offline Completed without error 00% 4660 -不过要特别强调的是,因为进行磁盘自我检查时,可能磁盘的 I/O 状态会比较频繁,因此不建议在系统忙碌的时候进行! 否则系统的性能是可能会被影响的!
ifconfig列出系统中的网卡信息
回到顶部ifconfig显示当前所有网络状态
peter@peter-VirtualBox:~$ ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.105 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::1db0:20ae:4993:2b5f prefixlen 64 scopeid 0x20 <link> ether 08:00:27:bd:23:a5 txqueuelen 1000 (Ethernet) RX packets 1270568 bytes 852069142 (852.0 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1415413 bytes 620591851 (620.5 MB) 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 1733758 bytes 136658908 (136.6 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1733758 bytes 136658908 (136.6 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 显示指定网卡状态: peter@peter-VirtualBox:~$ ifconfig eth0 关闭eth0: peter@peter-VirtualBox:~$ ifconfig eth0 down 开启eth0: peter@peter-VirtualBox:~$ ifconfig eth0 up
ping
回到顶部ping常用来测试网络连通性:
peter@peter-VirtualBox:~$ ping www.initroot.com PING www.initroot.com (139.129.102.64) 56(84) bytes of data. 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=1 ttl=52 time=168 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=2 ttl=52 time=92.2 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=3 ttl=52 time=77.0 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=4 ttl=52 time=96.6 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=5 ttl=52 time=102 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=6 ttl=52 time=111 ms 64 bytes from 139.129.102.64 (139.129.102.64): icmp_seq=7 ttl=52 time=131 ms ^C --- www.initroot.com ping statistics --- 7 packets transmitted, 7 received, 0% packet loss, time 6004ms rtt min/avg/max/mdev = 77.003/111.531/168.098/27.963 ms
相关阅读:
linux基础
centos安装
linux mint(ubuntu)安装
什么是linux
linux学习方法建议和学习路线图
本文由initroot编辑整理,转载请注明www.initroot.com