引言
在运维和开发工作中,我们经常需要快速检查linux服务器的硬件配置和性能指标,例如:
- cpu核心数(几核?)
- 内存大小(几gb?)
- 网络带宽(1gbps还是10gbps?当前流量如何?)
本文将以 centos 为例,介绍如何通过命令行快速获取这些关键信息,并提供详细的代码示例和解析,帮助你在服务器管理和故障排查时更加高效。
一、查询cpu核心数(几c?)
cpu核心数直接影响服务器的并发处理能力,我们可以通过以下几种方式查询:
1. 使用 nproc(最简单)
nproc
输出示例:
8
表示 8核cpu。
2. 使用 lscpu(详细信息)
lscpu
关键输出:
cpu(s): 8 # 总逻辑cpu数 thread(s) per core: 2 # 每个核心的线程数 core(s) per socket: 4 # 每个物理cpu的核心数 socket(s): 1 # 物理cpu数量
计算方式:
- 物理核心数 = socket(s) × core(s) per socket = 1 × 4 = 4(4核)
- 逻辑核心数 = cpu(s) = 8(超线程开启时,逻辑核心数=物理核心数×2)
3. 使用 /proc/cpuinfo
grep -c "processor" /proc/cpuinfo
输出:
8
表示 8个逻辑cpu。
二、查询内存大小(几g?)
内存大小直接影响服务器的应用承载能力,我们可以通过以下方式查询:
1. 使用 free -h(推荐)
free -h
输出:
total used free shared buff/cache available
mem: 16g 2.1g 12g 200m 1.9g 13g
swap: 2.0g 0b 2.0g
mem: 16g 表示 总内存16gb。
2. 使用 /proc/meminfo
cat /proc/meminfo | grep memtotal
输出:
memtotal: 16430812 kb
换算成gb:
echo "$(grep memtotal /proc/meminfo | awk '{print $2}') / 1024 / 1024" | bc -l
输出:
15.6
表示 约16gb内存。
3. 使用 dmidecode(需root)
sudo dmidecode -t memory | grep -a5 "memory device" | grep size
输出:
size: 8192 mb
size: 8192 mb
表示 8gb × 2 = 16gb内存。
三、查询网络带宽(1gbps还是10gbps?)
网络带宽直接影响服务器的网络吞吐量,我们可以通过以下方式查询:
1. 查询网卡理论带宽(ethtool)
ethtool eth0 | grep speed
输出:
speed: 1000mb/s
- 1000mb/s = 1gbps
- 10000mb/s = 10gbps
2. 查询网卡型号(lspci)
lspci | grep -i ethernet
输出:
00:03.0 ethernet controller: intel corporation 82540em gigabit ethernet controller (rev 02)
gigabit ethernet = 1gbps
10 gigabit = 10gbps
3. 实时监控带宽(nload)
nload
输出:
incoming: 50.00 mbps
outgoing: 10.25 mbps
- incoming = 下载速度
- outgoing = 上传速度
安装 nload
yum install epel-release -y yum install nload -y
四、综合查询工具
1. htop(cpu + 内存监控)
htop
输出:
图形化显示 cpu使用率、内存占用、进程信息。
安装 htop
yum install epel-release -y yum install htop -y
2. neofetch(系统概览)
neofetch
输出:
显示 cpu型号、核心数、内存、操作系统 等完整信息。
安装 neofetch
yum install epel-release -y yum install neofetch -y
五、实战:快速查询服务器配置
1. 一键查询cpu、内存、带宽
echo "cpu: $(nproc) cores | ram: $(free -h | awk '/mem/{print $2}') | network: $(ethtool eth0 | grep speed | awk '{print $2}')"
输出示例:
cpu: 8 cores | ram: 16g | network: 1000mb/s
2. 监控实时流量
nload
或
iftop
六、总结
查询项 | 推荐命令 | 说明 |
---|---|---|
cpu核心数 | nproc | 快速查看逻辑cpu数 |
cpu详细信息 | lscpu | 查看物理核心、超线程等信息 |
内存大小 | free -h | 查看总内存和可用内存 |
网卡带宽 | ethtool eth0 | 查看1gbps还是10gbps |
实时流量 | nload | 监控当前上传/下载速度 |
综合信息 | htop / neofetch | 图形化显示系统状态 |
掌握这些命令,可以让你在 服务器管理、性能优化、故障排查 时更加高效!
到此这篇关于linux如何快速检查服务器的硬件配置和性能指标的文章就介绍到这了,更多相关linux服务器性能排查内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论