如何查看linux服务器的cpu数量,内核数,和cpu线程数?

如何查看linux服务器的cpu数量,内核数,和cpu线程数?,第1张

lscpu命令,查看的是cpu的统计信息.\x0d\x0ablue@blue-pc:~$ lscpu\x0d\x0aArchitecture: i686#cpu架构\x0d\x0aCPU op-mode(s):32-bit, 64-bit\x0d\x0aByte Order:Little Endian #小尾序\x0d\x0aCPU(s):4 #总共有4核\x0d\x0aOn-line CPU(s) list: 0-3\x0d\x0aThread(s) per core:1 #每个cpu核,只能支持一个线程,即不支持超线程\x0d\x0aCore(s) per socket:4 #每个cpu,有4个核\x0d\x0aSocket(s): 1 #总共有1一个cpu\x0d\x0aVendor ID: GenuineIntel#cpu产商 intel\x0d\x0aCPU family:6\x0d\x0aModel: 42\x0d\x0aStepping: 7\x0d\x0aCPU MHz: 1600.000\x0d\x0aBogoMIPS: 5986.12\x0d\x0aVirtualization:VT-x#支持cpu虚拟化技术\x0d\x0aL1d cache: 32K\x0d\x0aL1i cache: 32K\x0d\x0aL2 cache: 256K\x0d\x0aL3 cache: 6144K\x0d\x0a \x0d\x0a 查看/proc/cpuinfo,可以知道每个cpu信息,如每个CPU的型号,主频等。\x0d\x0a#cat /proc/cpuinfo\x0d\x0aprocessor: 0\x0d\x0avendor_id: GenuineIntel\x0d\x0acpu family: 6\x0d\x0amodel: 42\x0d\x0amodel name: Intel(R) Core(TM) i5-2320 CPU @ 3.00GHz\x0d\x0a.....\x0d\x0a 上面输出的是第一个cpu部分信息,还有3个cpu信息省略了。\x0d\x0a \x0d\x0a 内存\x0d\x0a 概要查看内存情况\x0d\x0a free -m\x0d\x0a total used free sharedbuffers cached\x0d\x0a Mem: 3926 3651274 0 12404\x0d\x0a -/+ buffers/cache: 3235691\x0d\x0a Swap: 9536 31 9505\x0d\x0a 这里的单位是MB,总共的内存是3926MB。\x0d\x0a \x0d\x0a 查看内存详细使用\x0d\x0a# cat /proc/meminfo\x0d\x0aMemTotal:4020868 kB\x0d\x0aMemFree: 230884 kB\x0d\x0aBuffers:7600 kB\x0d\x0aCached: 454772 kB\x0d\x0aSwapCached: 836 kB\x0d\x0a.....\x0d\x0a \x0d\x0a 查看内存硬件信息\x0d\x0admidecode -t memory\x0d\x0a# dmidecode 2.11\x0d\x0aSMBIOS 2.7 present.\x0d\x0aHandle 0x0008, DMI type 16, 23 bytes\x0d\x0aPhysical Memory Array\x0d\x0aLocation: System Board Or Motherboard\x0d\x0a....\x0d\x0aMaximum Capacity: 32 GB\x0d\x0a....\x0d\x0aHandle 0x000A, DMI type 17, 34 bytes\x0d\x0a....\x0d\x0aMemory Device\x0d\x0aArray Handle: 0x0008\x0d\x0aError Information Handle: Not Provided\x0d\x0aTotal Width: 64 bits\x0d\x0aData Width: 64 bits\x0d\x0aSize: 4096 MB\x0d\x0a.....\x0d\x0a 我的主板有4个槽位,只用了一个槽位,上面插了一条4096MB的内存。\x0d\x0a \x0d\x0a 磁盘\x0d\x0a 查看硬盘和分区分布\x0d\x0a# lsblk\x0d\x0aNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\x0d\x0asda 8:00 465.8G 0 disk\x0d\x0a├—sda1 8:10 1G 0 part /boot\x0d\x0a├—sda2 8:20 9.3G 0 part [SWAP]\x0d\x0a├—sda3 8:30 74.5G 0 part /\x0d\x0a├—sda4 8:40 1K 0 part\x0d\x0a├—sda5 8:50 111.8G 0 part /home\x0d\x0a└—sda6 8:60 269.2G 0 part\x0d\x0a 显示很直观\x0d\x0a \x0d\x0a 如果要看硬盘和分区的详细信息\x0d\x0a# fdisk -l\x0d\x0aDisk /dev/sda: 500.1 GB, 500107862016 bytes\x0d\x0a255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors\x0d\x0aUnits = sectors of 1 * 512 = 512 bytes\x0d\x0aSector size (logical/physical): 512 bytes / 4096 bytes\x0d\x0aI/O size (minimum/optimal): 4096 bytes / 4096 bytes\x0d\x0aDisk identifier: 0x00023728\x0d\x0a Device Boot Start End Blocks Id System\x0d\x0a/dev/sda1 *2048 2148351 1073152 83 Linux\x0d\x0a/dev/sda2 214835221680127 9765888 82 Linux swap / Solaris\x0d\x0a/dev/sda321680128 17793023978125056 83 Linux\x0d\x0a/dev/sda4 177932286 976771071 3994193935 Extended/dev/sda5 177932288 412305407 117186560 83 Linux\x0d\x0a/dev/sda6 412307456 976771071 282231808 83 Linux\x0d\x0a \x0d\x0a 网卡\x0d\x0a 查看网卡硬件信息\x0d\x0a# lspci | grep -i 'eth'\x0d\x0a02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)\x0d\x0a \x0d\x0a 查看系统的所有网络接口\x0d\x0a# ifconfig -a\x0d\x0aeth0 Link encap:以太网 硬件地址 b8:97:5a:17:b3:8f \x0d\x0a .....\x0d\x0aloLink encap:本地环回 \x0d\x0a .....\x0d\x0a 或者是\x0d\x0aip link show\x0d\x0a1: lo: mtu 16436 qdisc noqueue state DOWN\x0d\x0alink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\x0d\x0a2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000\x0d\x0alink/ether b8:97:5a:17:b3:8f brd ff:ff:ff:ff:ff:ff\x0d\x0a \x0d\x0a 如果要查看某个网络接口的详细信息,例如eth0的详细参数和指标\x0d\x0a# ethtool eth0\x0d\x0aSettings for eth0:\x0d\x0aSupported ports: [ TP MII ]\x0d\x0aSupported link modes: 10baseT/Half 10baseT/Full\x0d\x0a100baseT/Half 100baseT/Full\x0d\x0a1000baseT/Half 1000baseT/Full #支持千兆半双工,全双工模式\x0d\x0aSupported pause frame use: No\x0d\x0aSupports auto-negotiation: Yes #支持自适应模式,一般都支持\x0d\x0aAdvertised link modes: 10baseT/Half 10baseT/Full\x0d\x0a100baseT/Half 100baseT/Full\x0d\x0a1000baseT/Half 1000baseT/Full\x0d\x0aAdvertised pause frame use: Symmetric Receive-only\x0d\x0aAdvertised auto-negotiation: Yes #默认使用自适应模式\x0d\x0aLink partner advertised link modes: 10baseT/Half 10baseT/Full\x0d\x0a 100baseT/Half 100baseT/Full\x0d\x0a.....\x0d\x0aSpeed: 100Mb/s #现在网卡的速度是100Mb,网卡使用自适应模式,所以推测路由是100Mb,导致网卡从支 持千兆,变成要支持百兆\x0d\x0aDuplex: Full #全双工\x0d\x0a.....\x0d\x0aLink detected: yes#表示有网线连接,和路由是通的\x0d\x0a\x0d\x0a其他\x0d\x0a 查看pci信息,即主板所有硬件槽信息。\x0d\x0alspci\x0d\x0a00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller (rev 09) #主板芯片\x0d\x0a00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09) #显卡\x0d\x0a00:14.0 USB controller: Intel Corporation Panther Point USB xHCI Host Controller (rev 04) #usb控制器\x0d\x0a00:16.0 Communication controller: Intel Corporation Panther Point MEI Controller #1 (rev 04)\x0d\x0a00:1a.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #2 (rev 04)\x0d\x0a00:1b.0 Audio device: Intel Corporation Panther Point High Definition Audio Controller (rev 04) #声卡\x0d\x0a00:1c.0 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 1 (rev c4) #pci 插槽\x0d\x0a00:1c.2 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 3 (rev c4)\x0d\x0a00:1c.3 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 4 (rev c4)\x0d\x0a00:1d.0 USB controller: Intel Corporation Panther Point USB Enhanced Host Controller #1 (rev 04)\x0d\x0a00:1f.0 ISA bridge: Intel Corporation Panther Point LPC Controller (rev 04)\x0d\x0a00:1f.2 IDE interface: Intel Corporation Panther Point 4 port SATA Controller [IDE mode] (rev 04) #硬盘接口\x0d\x0a00:1f.3 SMBus: Intel Corporation Panther Point SMBus Controller (rev 04)\x0d\x0a00:1f.5 IDE interface: Intel Corporation Panther Point 2 port SATA Controller [IDE mode] (rev 04) #硬盘接口\x0d\x0a02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06) #网卡\x0d\x0a03:00.0 PCI bridge: Integrated Technology Express, Inc. Device 8893 (rev 41)\x0d\x0a 如果要更详细的信息:lspci -v 或者 lspci -vv\x0d\x0a 如果要看设备树:lscpi -t\x0d\x0a \x0d\x0a 查看bios信息\x0d\x0a# dmidecode -t bios\x0d\x0a......\x0d\x0aBIOS Information\x0d\x0aVendor: American Megatrends Inc.\x0d\x0aVersion: 4.6.5\x0d\x0aRelease Date: 04/25/2012\x0d\x0a.......\x0d\x0aBIOS Revision: 4.6\x0d\x0a......\x0d\x0a dmidecode以一种可读的方式dump出机器的DMI(Desktop Management Interface)信息。这些信息包括了硬件以及BIOS,既可以得到当前的配置,也可以得到系统支持的最大配置,比如说支持的最大内存数等。\x0d\x0a 如果要查看所有有用信息\x0d\x0a dmidecode -q\x0d\x0a 以上是linux查看硬件信息的所有命令,可以查看CPU、硬盘、网卡、磁盘等硬件的信息。

1.查看逻辑CPU个数:

#cat /proc/cpuinfo |grep "processor"|sort -u|wc -l

24

2.由于有超线程技术有必要查看一下物理CPU个数:

#grep "physical id" /proc/cpuinfo|sort -u|wc -l

2

#grep "physical id" /proc/cpuinfo|sort -u

physical id : 0

physical id : 1

查看每个物理CPU内核个数:

#grep "cpu cores" /proc/cpuinfo|uniq

cpu cores : 6

每个物理CPU上逻辑CPU个数:

#grep "siblings" /proc/cpuinfo|uniq

siblings : 12

一、查cpu数的方法

第一种方法:top命令法

在top命令的显示界面,按数字键1,即可查看到当前系统中的总cpu数,如下图为4核的cpu。

第二种方法:通过proc文件系统,直接获取cpu总数量,具体执行如下命令:

cat /proc/cpuinfo  | grep processor

二、查看总内存的方法

第一种方法:free命令法

一般使用free命令的-h参数,更人性化的显示

第二种方法:通过proc虚拟文件系统,来直接获取总内存数。

head /proc/meminfo


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8943099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存