干貨:Linux查詢 OS、CPU、內(nèi)存、硬盤信息
一.前言
當(dāng)我們接手了一臺(tái)或者幾臺(tái)服務(wù)器的時(shí)候,首先我們有必要對(duì)服務(wù)器的基本配置有所認(rèn)識(shí),這樣才可以對(duì)癥下藥,對(duì)以后的軟件部署,系統(tǒng)運(yùn)維會(huì)有事半功倍的效果。
二.關(guān)于服務(wù)器基本配置
查詢服務(wù)器的基本配置一般查詢操作系統(tǒng),CPU,內(nèi)存,硬盤,下面進(jìn)行逐一講解。
2.1 操作系統(tǒng)基本配置查詢
查看操作系統(tǒng)版本
- #cat /etc/redhat-release這個(gè)命令主要是查看紅帽發(fā)行的操作系統(tǒng)的版本號(hào)
- [root@node5 ~]# cat /etc/redhat-release
- CentOS Linux release 7.4.1708 (Core)
- #cat /etc/issue這個(gè)命令適用于大多數(shù)linux發(fā)行版
- [root@node5 ~]# cat /etc/issue
- \S
- Kernel \r on an \m
查看操作系統(tǒng)內(nèi)核版本
- [root@node5 ~]# uname -r
- 3.10.0-693.el7.x86_64
查看操作系統(tǒng)詳細(xì)信息
- [root@node5 ~]# uname -a
- Linux node5 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
- #從上面這段輸出可以看出,該服務(wù)器主機(jī)名是node5,linux內(nèi)核版本是3.10.0-693.el7.x86_64,CPU是x86架構(gòu)
- #該命令可以查看更多信息
- [root@node5 ~]# more /etc/*release
- ::::::::::::::
- /etc/centos-release
- ::::::::::::::
- CentOS Linux release 7.4.1708 (Core)
- ::::::::::::::
- /etc/os-release
- ::::::::::::::
- NAME="CentOS Linux"
- VERSION="7 (Core)"
- ID="centos"
- ID_LIKE="rhel fedora"
- VERSION_ID="7"
- PRETTY_NAME="CentOS Linux 7 (Core)"
- ANSI_COLOR="0;31"
- CPE_NAME="cpe:/o:centos:centos:7"
- HOME_URL="https://www.centos.org/"
- BUG_REPORT_URL="https://bugs.centos.org/"
- CENTOS_MANTISBT_PROJECT="CentOS-7"
- CENTOS_MANTISBT_PROJECT_VERSION="7"
- REDHAT_SUPPORT_PRODUCT="centos"
- REDHAT_SUPPORT_PRODUCT_VERSION="7"
- ::::::::::::::
- /etc/redhat-release
- ::::::::::::::
- CentOS Linux release 7.4.1708 (Core)
- ::::::::::::::
- /etc/system-release
- ::::::::::::::
- CentOS Linux release 7.4.1708 (Core)
2.2 CPU基本配置查詢
名詞解釋
名詞 | 含義 |
---|---|
CPU物理個(gè)數(shù) | 主板上實(shí)際插入的cpu數(shù)量 |
CPU核心數(shù) | 單塊CPU上面能處理數(shù)據(jù)的芯片組的數(shù)量,如雙核、四核等 (cpu cores) |
邏輯CPU數(shù)/線程數(shù) | 一般情況下,邏輯cpu=物理CPU個(gè)數(shù)×每顆核數(shù),如果不相等的話,則表示服務(wù)器的CPU支持超線程技術(shù) |
查看 CPU 物理個(gè)數(shù)
- [root@node5 ~]# grep 'physical id' /proc/cpuinfo | sort -u | wc -l
- 1
查看 CPU 核心數(shù)量
- [root@node5 ~]# grep 'core id' /proc/cpuinfo | sort -u | wc -l
- 4
查看 CPU 線程數(shù)
- #邏輯cpu數(shù):一般情況下,邏輯cpu=物理CPU個(gè)數(shù)×每顆核數(shù),如果不相等的話,則表示服務(wù)器的CPU支持超線程技術(shù)(HT:簡(jiǎn)單來說,它可使處理#器中的1 顆內(nèi)核如2 顆內(nèi)核那樣在操作系統(tǒng)中發(fā)揮作用。這樣一來,操作系統(tǒng)可使用的執(zhí)行資源擴(kuò)大了一倍,大幅提高了系統(tǒng)的整體性能,此時(shí)邏#輯cpu=物理CPU個(gè)數(shù)×每顆核數(shù)x2)
- [root@node5 ~]# cat /proc/cpuinfo| grep "processor"|wc -l
- 4
- [root@node5 ~]# grep 'processor' /proc/cpuinfo | sort -u | wc -l
- 4
查看 CPU 型號(hào)
- [root@node5 ~]# cat /proc/cpuinfo | grep name | sort | uniq
- model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- [root@node5 ~]# dmidecode -s processor-version | uniq #使用uniq進(jìn)行去重
- Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
查看 CPU 的詳細(xì)信息
- #CPU有幾個(gè)核,就會(huì)輸出幾個(gè)重復(fù)的信息
- [root@node5 ~]# cat /proc/cpuinfo
- processor : 0
- vendor_id : GenuineIntel
- cpu family : 6
- model : 142
- model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- stepping : 10
- microcode : 0x96
- cpu MHz : 2000.921
- cache size : 8192 KB
- physical id : 0
- siblings : 4
- core id : 0
- cpu cores : 4
- apicid : 0
- initial apicid : 0
- fpu : yes
- fpu_exception : yes
- cpuid level : 22
- 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 pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat
- bogomips : 4002.00
- clflush size : 64
- cache_alignment : 64
- address sizes : 43 bits physical, 48 bits virtual
- power management:
查看CPU的詳細(xì)信息
- [root@node5 ~]# lscpu
- Architecture: x86_64
- CPU op-mode(s): 32-bit, 64-bit
- Byte Order: Little Endian
- CPU(s): 4
- On-line CPU(s) list: 0-3
- Thread(s) per core: 1
- Core(s) per socket: 4
- Socket(s): 1
- NUMA node(s): 1
- Vendor ID: GenuineIntel
- CPU family: 6
- Model: 142
- Model name: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
- Stepping: 10
- CPU MHz: 2000.921
- BogoMIPS: 4002.00
- Virtualization: VT-x
- Hypervisor vendor: VMware
- Virtualization type: full
- L1d cache: 32K
- L1i cache: 32K
- L2 cache: 256K
- L3 cache: 8192K
- NUMA node0 CPU(s): 0-3
- 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 pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat
CPU配置總結(jié)
通過以上的查詢,我們可以知道該服務(wù)器是1路4核的CPU ,CPU型號(hào)是Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz,該CPU沒有超線程。
2.3 內(nèi)存基本配置查詢
名詞解釋
名詞 | 含義 |
---|---|
Mem | 內(nèi)存的使用情況總覽表 |
Swap | 虛擬內(nèi)存。即可以把數(shù)據(jù)存放在硬盤上的數(shù)據(jù),當(dāng)物理內(nèi)存不足時(shí),拿出部分硬盤空間當(dāng)SWAP分區(qū)(虛擬成內(nèi)存)使用,從而解決內(nèi)存容量不足的情況。SWAP意思是交換,顧名思義,當(dāng)某進(jìn)程向OS請(qǐng)求內(nèi)存發(fā)現(xiàn)不足時(shí),OS會(huì)把內(nèi)存中暫時(shí)不用的數(shù)據(jù)交換出去,放在SWAP分區(qū)中,這個(gè)過程稱為SWAP OUT。當(dāng)某進(jìn)程又需要這些數(shù)據(jù)且OS發(fā)現(xiàn)還有空閑物理內(nèi)存時(shí),又會(huì)把SWAP分區(qū)中的數(shù)據(jù)交換回物理內(nèi)存中,這個(gè)過程稱為SWAP IN。當(dāng)然,swap大小是有上限的,一旦swap使用完,操作系統(tǒng)會(huì)觸發(fā)OOM-Killer機(jī)制,把消耗內(nèi)存最多的進(jìn)程kill掉以釋放內(nèi)存。 |
shared | 共享內(nèi)存,即和普通用戶共享的物理內(nèi)存值, 主要用于進(jìn)程間通信 |
buffers | 用于存放要輸出到disk(塊設(shè)備)的數(shù)據(jù)的 |
cached | 存放從disk上讀出的數(shù)據(jù) |
total | 總的物理內(nèi)存,total=used+free |
used | 使用掉的內(nèi)存 |
free | 空閑的內(nèi)存 |
查詢服務(wù)器內(nèi)存
- [root@node5 ~]# free -m
- total used free shared buff/cache available
- Mem: 3941 286 3446 19 208 3407
- Swap: 2047 0 2047
- #注釋
- #linux的內(nèi)存管理機(jī)制的思想包括(不敢說就是)內(nèi)存利用率最大化。內(nèi)核會(huì)把剩余的內(nèi)存申請(qǐng)為cached,而cached不屬于free范疇。當(dāng)系統(tǒng)運(yùn)#行時(shí)間較久,會(huì)發(fā)現(xiàn)cached很大,對(duì)于有頻繁文件讀寫操作的系統(tǒng),這種現(xiàn)象會(huì)更加明顯。直觀的看,此時(shí)free的內(nèi)存會(huì)非常小,但并不代表可##用的內(nèi)存小,當(dāng)一個(gè)程序需要申請(qǐng)較大的內(nèi)存時(shí),如果free的內(nèi)存不夠,內(nèi)核會(huì)把部分cached的內(nèi)存回收,回收的內(nèi)存再分配給應(yīng)用程序。所以#對(duì)于linux系統(tǒng),可用于分配的內(nèi)存不只是free的內(nèi)存,還包括cached的內(nèi)存(其實(shí)還包括buffers)。
- #對(duì)于操作系統(tǒng):
- #MemFree=total-used
- #MemUsed = MemTotal - MemFree
- #對(duì)于應(yīng)用程序:
- #MemFree=buffers+cached+free
每隔3秒查詢一下內(nèi)存
- [root@node5 ~]# free -s 3
- total used free shared buff/cache available
- Mem: 4036316 361144 3458272 19536 216900 3419776
- Swap: 2097148 0 2097148
- total used free shared buff/cache available
- Mem: 4036316 361144 3458272 19536 216900 3419776
- Swap: 2097148 0 2097148
- total used free shared buff/cache available
- Mem: 4036316 361144 3458272 19536 216900 3419776
- Swap: 2097148 0 2097148
2.4 硬盤基本配置查詢
查詢磁盤整體使用情況
- [root@node5 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 17G 4.1G 13G 24% /
- devtmpfs 2.0G 0 2.0G 0% /dev
- tmpfs 2.0G 8.0K 2.0G 1% /dev/shm
- tmpfs 2.0G 8.7M 2.0G 1% /run
- tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
- /dev/sda1 1014M 125M 890M 13% /boot
- tmpfs 395M 0 395M 0% /run/user/0
- #命令拓展
- #df -a 顯示全部的文件系統(tǒng)的使用情況
- #df -i顯示inode信息
- #df -k 已字節(jié)數(shù)顯示區(qū)塊占用情況
- #df -T 顯示文件系統(tǒng)的類型
查詢某個(gè)目錄磁盤占用情況
- #命令拓展
- #du -s 指定目錄大小匯總
- #du -h帶計(jì)量單位
- #du -a 含文件
- #du --max-depth=1 子目錄深度
- #du -c 列出明細(xì)的同時(shí),增加匯總值
- [root@node5 ~]# du -sh /home/
- 1.7G /home/
- [root@node5 ~]# du -ach --max-depth=2 /home/
- 4.0K /home/www/.bash_logout
- 4.0K /home/www/.bash_profile
- 4.0K /home/www/.bashrc
- 4.0K /home/www/web
- 16K /home/www
- 4.0K /home/nginx/.bash_logout
- 4.0K /home/nginx/.bash_profile
- 4.0K /home/nginx/.bashrc
- 12K /home/nginx
- 4.0K /home/esnode/.bash_logout
- 4.0K /home/esnode/.bash_profile
- 4.0K /home/esnode/.bashrc
- 4.0K /home/esnode/.oracle_jre_usage
- 4.3M /home/esnode/elasticsearch-analysis-ik-6.2.2.zip
- 80M /home/esnode/kibana-6.2.2-linux-x86_64.tar.gz
- 300M /home/esnode/x-pack-6.2.2.zip
- 28M /home/esnode/elasticsearch-6.2.2.tar.gz
- 4.0K /home/esnode/.bash_history
- 294M /home/esnode/elasticsearch-6.2.2
- 4.0K /home/esnode/.ssh
- 4.0K /home/esnode/x-pack生成的秘鑰.txt
- 1014M /home/esnode/kibana-6.2.2-linux-x86_64
- 8.0K /home/esnode/.viminfo
- 1.7G /home/esnode
- 1.7G /home/
- 1.7G total
查看目錄結(jié)構(gòu)
- #tree命令默認(rèn)沒有安裝,需要手動(dòng)安裝一下
- [root@node5 ~]# yum -y install tree
- #-L指定目錄深度
- [root@node5 ~]# tree -L 2 /home/
- /home/
- ├── esnode
- │ ├── elasticsearch-6.2.2
- │ ├── elasticsearch-6.2.2.tar.gz
- │ ├── elasticsearch-analysis-ik-6.2.2.zip
- │ ├── kibana-6.2.2-linux-x86_64
- │ ├── kibana-6.2.2-linux-x86_64.tar.gz
- │ ├── x-pack-6.2.2.zip
- │ └── x-pack\347\224\237\346\210\220\347\232\204\347\247\230\351\222\245.txt
- ├── nginx
- └── www
- └── web
- 6 directories, 5 files
以樹狀的格式顯示所有可用的塊設(shè)備信息
- [root@node5 ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 20G 0 disk
- ├─sda1 8:1 0 1G 0 part /boot
- └─sda2 8:2 0 19G 0 part
- ├─centos-root 253:0 0 17G 0 lvm /
- └─centos-swap 253:1 0 2G 0 lvm [SWAP]
- sdb 8:16 0 1G 0 disk
- └─sdb1 8:17 0 200M 0 part
- sr0 11:0 1 1024M 0 rom
- #注釋
- #NAME —— 設(shè)備的名稱
- #MAJ:MIN —— Linux 操作系統(tǒng)中的每個(gè)設(shè)備都以一個(gè)文件表示,對(duì)塊(磁盤)設(shè)備來說,這里用主次設(shè)備編號(hào)來描述設(shè)備。
- #RM —— 可移動(dòng)設(shè)備。如果這是一個(gè)可移動(dòng)設(shè)備將顯示 1,否則顯示 0。
- #TYPE —— 設(shè)備的類型
- #MOUNTPOINT —— 設(shè)備掛載的位置
- #RO —— 對(duì)于只讀文件系統(tǒng),這里會(huì)顯示 1,否則顯示 0。
- #SIZE —— 設(shè)備的容量
列出所有可用的設(shè)備、通用唯一識(shí)別碼(UUID)、文件系統(tǒng)類型以及卷標(biāo)
- [root@node5 ~]# blkid
- /dev/sda1: UUID="6503b4ad-2975-4152-a824-feb7bea1b622" TYPE="xfs"
- /dev/sda2: UUID="nqZ4uJ-ksnN-KzYS-N42b-00m3-Ohc2-BJXunP" TYPE="LVM2_member"
- /dev/sdb1: UUID="94396e17-4821-4957-aa76-d41f33958ff5" TYPE="xfs"
- /dev/mapper/centos-root: UUID="c1d38b37-821d-48e7-8727-3937ccc657a4" TYPE="xfs"
- /dev/mapper/centos-swap: UUID="c2fcaf11-42d8-4e4c-bf9e-6464f0777198" TYPE="swap"
【編輯推薦】