之前面試的時候問到用戶量,然後扯到了服務器的配置相關,但服務器是都是由組長申請的,所以當時並不瞭解。回來後,瞭解了Linux下硬件信息配置的查看,記錄如下。
1. CPU信息
CPU信息有三種方式查看。
一種是直接cat /proc/cpuinfo,會打印出所有CPU的詳細信息,單個CPU的信息如下:
[user@VM_0_4_centos debug]$ cat /proc/cpuinfo
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-26xx v4
stepping : 1
microcode : 0x1
cpu MHz : 2399.988
cache size : 4096 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch bmi1 avx2 bmi2 rdseed adx xsaveopt
bogomips : 4799.97
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:
各項的含義如下:
processor :系統中邏輯處理核的編號。對於單核處理器,則課認爲是其CPU編號,對於多核處理器則可以是物理核、或者使用超線程技術虛擬的邏輯核
vendor_id :CPU製造商
cpu family :CPU產品系列代號
model :CPU屬於其系列中的哪一代的代號
model name:CPU屬於的名字及其編號、標稱主頻
stepping :CPU屬於製作更新版本
cpu MHz :CPU的實際使用主頻
cache size :CPU二級緩存大小
physical id :單個CPU的標號
siblings :單個CPU邏輯物理核數
core id :當前物理核在其所處CPU中的編號,這個編號不一定連續
cpu cores :該邏輯核所處CPU的物理核數
apicid :用來區分不同邏輯核的編號,系統中每個邏輯核的此編號必然不同,此編號不一定連續
fpu :是否具有浮點運算單元(Floating Point Unit)
fpu_exception :是否支持浮點計算異常
cpuid level :執行cpuid指令前,eax寄存器中的值,根據不同的值cpuid指令會返回不同的內容
wp :表明當前CPU是否在內核態支持對用戶空間的寫保護(Write Protection)
flags :當前CPU支持的功能
bogomips :在系統內核啓動時粗略測算的CPU速度(Million Instructions Per Second)
clflush size :每次刷新緩存的大小單位
cache_alignment :緩存地址對齊單位
address sizes :可訪問地址空間位數
我們可以grep需要的信息查看:
cat /proc/cpuinfo | grep "cpu cores" // 查看每個CPU核數
cat /proc/cpuinfo | grep "physical id" | wc -l // 查看CPU個數
第二種是使用lscpu命令,該命令時從sysfs和/proc/cpuinfo收集cpu體系結構信息,命令的輸出比較易讀 ,如下:
[user@VM_0_4_centos debug]$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-26xx v4
Stepping: 1
CPU MHz: 2399.988
BogoMIPS: 4799.97
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
NUMA node0 CPU(s): 0,1
我們可以看到CPU數量("CPU(s)")、每個CPU核數("Core(s) pre socket")、大小端信息("Byte Order")和CPU架構("Architecture")。另外還有支持的操作模式("CPU op-mode(s)")應該就是指支持32位及64位指令集,可否運行32位操作系統及64位操作系統吧,其中64-bit也叫Long mode。
第三種就是dmidecode命令,"sudo dmidecode -t processor"就可以指定查看CPU相關的信息。
2. 內存信息
內存信息有三種方式可以查看。
第一種是通過/proc/meminfo文件查看,"cat /proc/meminfo"就可以打印,內容比較長,並且可讀性不太好,這裏只貼出一部分內容。我們也可以通過grep命令提取出我們需要的內容打印出來。
[user@VM_0_4_centos debug]$ cat /proc/meminfo
MemTotal: 3882032 kB
MemFree: 126164 kB
MemAvailable: 2288044 kB
Buffers: 115860 kB
Cached: 2834888 kB
SwapCached: 0 kB
Active: 1906908 kB
Inactive: 1581564 kB
Active(anon): 815556 kB
Inactive(anon): 387800 kB
Active(file): 1091352 kB
Inactive(file): 1193764 kB
Unevictable: 4748 kB
...
第二種是free命令,顯示的內容很少:
[user@VM_0_4_centos debug]$ free
total used free shared buff/cache available
Mem: 3882032 616920 147440 660756 3117672 2289708
Swap: 0 0 0
[user@VM_0_4_centos debug]$ free -h
total used free shared buff/cache available
Mem: 3.7G 604M 136M 645M 3.0G 2.2G
Swap: 0B 0B 0B
最後一個是dmidecode命令,使用"sudo dmidecode -t memory"即可打印內存相關的信息:
[user@VM_0_4_centos debug]$ sudo dmidecode -t memory
# dmidecode 2.12-dmifs
SMBIOS 2.4 present.
Handle 0x1000, DMI type 16, 15 bytes
Physical Memory Array
Location: Other
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 1
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: 4096 MB
Form Factor: DIMM
Set: None
Locator: DIMM 0
Bank Locator: Not Specified
Type: RAM
Type Detail: None
查看上面三個命令的輸出結果,可以看到/proc/meminfo文件和free命令的結果是一樣的,但是比dmidecode的值要小。即可見內存要比實際內存小,這是因爲系統從加電開始到引導完成,firmware/BIOS要保留一些內存,kernel本身要佔用一些內存,最後剩下可供kernel支配的內存纔是MemTotal的值。
所以我們要看系統可用內存應該用前兩種方式,看硬件配置的實際內存要用第三種方式。
3. 硬盤信息
硬盤信息可以用fdisk命令查看,輸出如下:
[user@VM_0_4_centos debug]$ sudo fdisk -l
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x0005fc9a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857566 52427759+ 83 Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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
如果我們要查看硬盤各個分區的使用情況,可以用df命令:
[user@VM_0_4_centos debug]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 50G 46G 1.3G 98% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 24K 1.9G 1% /dev/shm
tmpfs 1.9G 1.4M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0
tmpfs 380M 0 380M 0% /run/user/1001
/dev/vdb 493G 232G 236G 50% /home/user/log
如果想看當前目錄下目錄的大小,可以用du命令,-d選項用來設置遞歸顯示的深度,1時只所有子目錄的大小,2時則會顯示子目錄的子目錄的大小,以此類推:
[user@localhost conf]$ du -h -d 1
100K ./svr
96K ./comm
196K .
[user@localhost conf]$ du -h -d 2
100K ./svr
56K ./comm/words
96K ./comm
196K .
4. 網卡信息
網卡信息有兩種方式查看。
第一種方式先用ifconfig找到要查看的顯卡,然後再用ethtool命令查看網卡信息,ethtool輸出如下:
[user@localhost comm_conf]$ ethtool ens33
Settings for ens33:
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
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Cannot get wake-on-lan settings: Operation not permitted
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
上面的Speed項就是網卡的速率。
第二種方式就是lspci命令,該命令可以看到所有通過PCI接口接入的設備,我們grep出Ethernet相關的即可,輸出如下:
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
輸出中的Gigabit代表這是千兆的,與上面的1000Mb/s是一致的。
注意,對於雲服務器,上面的兩個命令都得不到信息的。