在管理服务器时,了解和监控其配置信息是至关重要的,这有助于管理员确保系统运行正常,并在出现问题时快速诊断和解决,以下是一些常用的命令,用于查看服务器的配置信息:
`uname -a`

这个命令显示了操作系统的名称、版本、内核版本等信息。
$ uname -a Linux example-server 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
`hostnamectl`
这个命令提供了关于主机名和操作系统版本的详细信息。
$ hostnamectl
Static hostname: example-server
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Boot ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Virtualization: kvm
Operating System: Ubuntu 20.04.1 LTS
Kernel: Linux 5.4.0-42-generic
Architecture: x86-64 `lscpu`
这个命令显示CPU架构信息,包括核心数、线程数等。
$ lscpu Architecture: x86_64 CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Stepping: 9 CPU MHz: 2808.000 BogoMIPS: 5616.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 6144K NUMA node0 CPU(s): 0-3
`free -h`
这个命令显示内存使用情况。
$ free -h
total used free shared buff/cache available
Mem: 7.7G 1.1G 5.3G 32M 1.3G 6.2G
Swap: 2.0G 0B 2.0G `df -h`
这个命令显示磁盘使用情况。
$ df -h Filesystem Size Used Avail Use% Mounted on udev 2.0G 0 2.0G 0% /dev tmpfs 396M 2.0M 394M 1% /run /dev/sda1 20G 15G 4.5G 78% / tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
`ip a`
这个命令显示网络接口及其状态。
$ ip a
1: lo: <LOOPBACK,mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 fe80::1/64 scope link
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST>UP>SLAVE>RUNNING>MASTER>MASTER>qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:cf:24:c5 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0
valid_lft 86383sec preferred_lft 86383sec
inet6 fe80::5054:ff:fecf:24:c5/64 scope link
valid_lft forever preferred_lft forever `uptime`
这个命令显示系统运行时间和负载平均值。

$ uptime 14:32:17 up 1 day, 3:21, 2 users, load average: 0.04, 0.02, 0.05
`top`
这个命令实时显示系统的资源使用情况,包括CPU、内存和进程信息。
$ top top 14:32:17 up 1 day, 3:21, 2 users, load average: 0.04, 0.02, 0.05 Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.2 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8192000 total, 1173848 free, 5349764 used, 1668388 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 6787556 avail Mem
`ps aux`
这个命令显示当前运行的所有进程。
$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 22448 2728 ? Ss 14:32 0:01 /sbin/init ...
`dmesg`
这个命令显示内核环缓冲区的消息,通常用于调试和故障排除。
$ dmesg | grep -i error [ 0.000000] ACPI Error: [_SB_.PCI0.RP05.PXSX] ... [ 0.000000] ACPI Error: Method parse/execution failed ...
`lspci`
这个命令列出所有PCI设备。
$ lspci 00:00.0 Host bridge: Intel Corporation Device 59cb (rev ff) ...
`lsusb`
这个命令列出所有USB设备。
$ lsusb Bus 002 Device 003: ID 8087:0a2b Intel Corp. ...
13.cat /proc/cpuinfo
这个命令显示详细的CPU信息。

$ cat /proc/cpuinfo | less processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 158 model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz stepping : 9 microcode : 0xea cpu MHz : 2808.000 ...
14.cat /proc/meminfo
这个命令显示详细的内存信息。
$ cat /proc/meminfo | less MemTotal: 16277728 kB MemFree: 5349764 kB MemAvailable: 6787556 kB Buffers: 229444 kB Cached: 3776484 kB SwapCached: 0 kB ...
15.cat /proc/partitions
这个命令显示系统中的所有分区。
$ cat /proc/partitions major minor #blocks name 8 1 16M rootfs /boot/efi 8 2 8192M rootfs / ...
FAQ相关问题及答案:
问题1:如何查看服务器的CPU型号?
答:可以使用以下命令查看CPU型号:
$ lscpu | grep "Model name" Model name: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
或者:
$ cat /proc/cpuinfo | grep "model name" | uniq model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
问题2:如何查看服务器的内存使用情况?
答:可以使用以下命令查看内存使用情况:
$ free -h
total used free shared buff/cache available
Mem: 7.7G 1.1G 5.3G 32M 1.3G 6.2G
Swap: 2.0G 0B 2.0G 小伙伴们,上文介绍了“服务器配置信息命令”的内容,你了解清楚吗?希望对你有所帮助,任何问题可以给我留言,让我们下期再见吧。
【版权声明】:本站所有内容均来自网络,若无意侵犯到您的权利,请及时与我们联系将尽快删除相关内容!
发表回复