查看linux服务器系统配置

311 阅读8分钟

查看linux服务器系统配置

查看网络带宽

  1. 查看网卡信息ifconfig
root@xxxxxxx:~$ ifconfig
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.23.81  netmask 255.255.255.0  broadcast 192.168.23.255
        inet6 fe80::ce82:7fff:fe39:2fa0  prefixlen 64  scopeid 0x20<link>
        ether cc:82:7f:39:2f:a0  txqueuelen 1000  (Ethernet)
        RX packets 90276863  bytes 24467717465 (24.4 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 112677025  bytes 7677943393 (7.6 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xf7100000-f7120000

enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.81  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::ce82:7fff:fe39:2fa1  prefixlen 64  scopeid 0x20<link>
        ether cc:82:7f:39:2f:a1  txqueuelen 1000  (Ethernet)
        RX packets 3032062  bytes 748146486 (748.1 MB)
        RX errors 0  dropped 829622  overruns 0  frame 0
        TX packets 1107311  bytes 996536309 (996.5 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xf7000000-f707ffff

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 14107693371  bytes 1746336951488 (1.7 TB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14107693371  bytes 1746336951488 (1.7 TB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. 查看各网卡带宽 使用ehttool 网卡名称 带宽即为查询结果中的Speed参数
root@xxxxxxx:~$ ethtool enp1s0
Settings for enp1s0:
        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
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Auto-negotiation: on
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        MDI-X: off (auto)
netlink error: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes
root@xxxxxxx:~$ ethtool enp0s31f6
Settings for enp0s31f6:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Auto-negotiation: on
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        MDI-X: on (auto)
netlink error: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

若需要查看各网卡带宽,需要安装ethtool

root@xxxxxxx:~$ sudo apt-get install ethtool
[sudo] password for zoesolar:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libopts25 sntp
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  ethtool
0 upgraded, 1 newly installed, 0 to remove and 25 not upgraded.
Need to get 208 kB of archives.
After this operation, 645 kB of additional disk space will be used.
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 ethtool amd64 1:5.16-1 [208 kB]
Fetched 208 kB in 7s (31.7 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package ethtool.
(Reading database ... 130143 files and directories currently installed.)
Preparing to unpack .../ethtool_1%3a5.16-1_amd64.deb ...
Unpacking ethtool (1:5.16-1) ...
Setting up ethtool (1:5.16-1) ...
Processing triggers for man-db (2.10.2-1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...
Pending kernel upgrade
----------------------

Newer kernel available

The currently running kernel version is 5.15.0-91-generic which is not the expected kernel version
5.15.0-92-generic.

Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting.


The processor microcode seems to be up-to-date.

Restarting services...
Daemons using outdated libraries
--------------------------------

  1. packagekit.service  2. systemd-resolved.service  3. none of the above

(Enter the items or ranges you want to select, separated by spaces.)

Which services should be restarted? 1 2

 systemctl restart packagekit.service systemd-resolved.service

No containers need to be restarted.

No user sessions are running outdated binaries.

查看cpu型号

使用命令cat /proc/cpuinfo

root@xxxxxxx:~$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
stepping        : 9
microcode       : 0xf4
cpu MHz         : 665.165
cache size      : 8192 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes

查看内存大小

通过sudo dmidecode -t memory 命令查看内存条个数、型号、容量

root@xxxxxxx:~$ sudo dmidecode -t memory
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.

Handle 0x003D, DMI type 16, 23 bytes
Physical Memory Array
        Location: System Board Or Motherboard
        Use: System Memory
        Error Correction Type: None
        Maximum Capacity: 64 GB # 最大容量64GB
        Error Information Handle: Not Provided
        Number Of Devices: 4  # 4个内存条卡槽

# 该数据表明未插入内存条
Handle 0x003E, DMI type 17, 40 bytes
Memory Device
        Array Handle: 0x003D
        Error Information Handle: Not Provided
        Total Width: Unknown
        Data Width: Unknown
        Size: No Module Installed
        Form Factor: Unknown
        Set: None
        Locator: ChannelA-DIMM0
        Bank Locator: BANK 0
        Type: Unknown
        Type Detail: None
        Speed: Unknown
        Manufacturer: Not Specified
        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

# 该数据为已插入内存条
Handle 0x0040, DMI type 17, 40 bytes
Memory Device
        Array Handle: 0x003D
        Error Information Handle: Not Provided
        Total Width: 64 bits
        Data Width: 64 bits
        Size: 8 GB   # 大小8GB
        Form Factor: SODIMM
        Set: None
        Locator: ChannelB-DIMM0
        Bank Locator: BANK 2
        Type: DDR4
        Type Detail: Synchronous
        Speed: 2667 MT/s
        Manufacturer: Kingston  # 型号
        Serial Number: 0BB2A4F1
        Asset Tag: 9876543210
        Part Number: CBD26D4S9S8K1C-8
        Rank: 1
        Configured Memory Speed: 2400 MT/s
        Minimum Voltage: 1.2 V
        Maximum Voltage: 1.2 V
        Configured Voltage: 1.2 V

若只想查看内存条个数与容量,可以使用以下指令

root@xxxxxxx:~$ sudo dmidecode -t memory | grep Size
        Size: No Module Installed
        Size: No Module Installed
        Size: 8 GB
        Size: No Module Installed

以上查询结果解析为内存为8G 若未安装dmidecode,可使用以下命令安装

sudo apt-get install dmidecode

查看硬盘容量

可以使用命令df -h查看

df -h

上面的命令中的-h选项表示以人类可读的方式(例如KB, MB, GB)显示大小。

如果你只想查看特定的硬盘或分区,比如 /dev/sda1 的容量,你可以这样做:

df -h /dev/sda1

此外,fdisk工具也可以用来查看硬盘的基本信息,包括总容量,但并不直接显示已用和剩余空间:

sudo fdisk -l

上述命令将列出所有连接到系统的磁盘以及它们的基本分区信息,但不包括文件系统级别的使用情况。

fdisk -l的查询结果如何解读? fdisk -l命令在Linux中用于列出所有磁盘和分区的信息。其输出结果通常包括以下部分:

plaintext
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0xabcdef12

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1            2048 20971519 20969472  10G 83 Linux

Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
...
Disk:磁盘设备的名称,如 /dev/sda 表示第一块SCSI或SATA硬盘。
大小信息:例如 10 GiB, 10737418240 bytes, 20971520 sectors,表示该磁盘总容量(此处为10GB)、总字节数以及总扇区数。
单位与扇区大小:Sector size (logical/physical): 512 bytes / 512 bytes 表示逻辑扇区和物理扇区的大小均为512字节。
I/O大小:I/O size (minimum/optimal): 512 bytes / 512 bytes 表示磁盘读写操作时最小和最优的I/O尺寸也是512字节。
Disklabel类型:如 Disklabel type: dos,表示采用的是DOS类型的磁盘标签格式。
Disk标识符:Disk identifier: 0xabcdef12 是一个唯一的标识符,用来标记这个磁盘分区表。
分区列表:接下来是每个分区的具体信息,每一行代表一个分区:
Device:分区设备名,例如 /dev/sda1 表示sda磁盘的第一个主分区或者扩展分区。
Boot:如果该分区被设置为可启动,则会显示Boot,否则为空。
Start、End 和 Sectors:分区起始扇区、结束扇区及其包含的总扇区数,可以据此计算出分区的大小。
Size:分区的实际大小。
Id:分区类型ID,例如 83 对应Linux文件系统。
通过这些信息,你可以了解系统的磁盘配置情况,包括磁盘的总容量、已分区情况以及各分区的详细属性。

解读示例: fdisk -l查询结果如下:

Disk /dev/sda: 476.94 GiB, 512110190592 bytes, 1000215216 sectors

Disk model: KINGSTON OCP0S35

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 82CBAB63-C0D9-4F14-A15D-DC16301F0729

Device Start End Sectors Size Type

/dev/sda1 2048 2203647 2201600 1G EFI System

/dev/sda2 2203648 6397951 4194304 2G Linux filesystem

/dev/sda3 6397952 1000212479 993814528 473.9G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 473.52 GiB, 508433530880 bytes, 993034240 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

解读结果如下:

这段信息是通过fdisk -l命令获取的Linux系统中两块硬盘 /dev/sda 和 /dev/mapper/ubuntu--vg-ubuntu--lv 的详细信息。下面对这些信息进行逐条解析:

Disk /dev/sda:

总容量:476.94 GiB,对应的字节数为512110190592 bytes,总扇区数为1000215216。
硬盘型号:KINGSTON OCP0S35
存储单位:扇区大小为512字节(逻辑和物理)
I/O大小:最小和最优读写操作尺寸都是512字节
磁盘标签类型:GPT (GUID Partition Table)
磁盘标识符:82CBAB63-C0D9-4F14-A15D-DC16301F0729
分区情况:

/dev/sda1:起始于第2048个扇区,结束于第2203647个扇区,共2201600个扇区,大小为1GB,分区类型为EFI System(通常用于存放启动加载器等文件)。
/dev/sda2:起始于第2203648个扇区,结束于第6397951个扇区,共4194304个扇区,大小为2GB,分区类型为Linux filesystem。
/dev/sda3:起始于第6397952个扇区,结束于第1000212479个扇区,共993814528个扇区,大小为473.9G,分区类型为Linux filesystem。
Disk /dev/mapper/ubuntu--vg-ubuntu--lv:

这是一个逻辑卷(LVM),总容量为473.52 GiB,对应字节数为508433530880,总扇区数为993034240。
单位、扇区大小以及I/O大小与上一块磁盘相同。
总结来说,这里显示了两块存储设备的信息:一个是物理硬盘/dev/sda,并且它已经被划分为三个分区;另一个是基于物理硬盘创建的逻辑卷/dev/mapper/ubuntu--vg-ubuntu--lv,作为Linux系统的实际存储空间使用。