查看Linux服务器常用信息命令集

作者: 蓝鹰 分类: CentOS 发布时间: 2014-01-27 21:13 ė243 浏览数 6查看Linux服务器常用信息命令集已关闭评论

昨天公司要求摸底各服务器的CPU、内存、硬盘等情况,我对自己所管理的linux服务器也做了排查,在此梳理一下查看Linux服务器信息常用的命令,做个总结。
一、操作系统:

1、查看linux发行版名称:lsb_release -a
若系统中没有这个命令,作为一种替代,可使用下面的命令,但显示信息较为简略,且不推荐使用:
cat /etc/redhat-release(针对redhat系的linux分发)
cat /etc/issue(针对所有linux的分发)
2、查看系统内核版本:uname -r
3、查看系统是否为64位:uname -m,若出现x86_64,则为64位
二、CPU信息:
1、查看CPU型号、频率信息:grep 'model name' /proc/cpuinfo |uniq
2、查看物理CPU个数:grep 'physical id' /proc/cpuinfo |sort |uniq |wc -l
3、查看物理CPU的内核数:grep 'cpu cores' /proc/cpuinfo |uniq
4、查看逻辑CPU个数:grep processor /proc/cpuinfo |sort |uniq |wc -l
5、查看CPU当前运行模式是否为64位:getconf LONG_BIT
6、查看CPU是否支持64位技术:grep 'flags' /proc/cpuinfo,若flags信息中包含lm字段,则支持64位
三、内存信息:
1、查看内存类型、频率、条数、最大支持内存等信息:dmidecode -t memory,或dmidecode | grep -A16 "Memory Device$"
2、查看当前内存的使用情况:free -m
四、硬盘信息:
1、查看机器里有几块硬盘:fdisk -l
2、查看当前文件的使用情况:df -ha

脚本如下:

info.sh
#!/bin/bash 
#Print the information of the server 
# 
if [[ -f /usr/bin/lsb_release ]]; then 
OS=$(/usr/bin/lsb_release -a |grep Description |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 
else 
OS=$(cat /etc/issue |sed -n '1p') 
fi 

OS_version=$(uname -m) 
kernel_version=$(uname -r) 
CPU=$(grep 'model name' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ \t]*//g'  |sed 's/ \+/ /g') 
Counts=$(grep 'physical id' /proc/cpuinfo |sort |uniq |wc -l) 
Cores=$(grep 'cpu cores' /proc/cpuinfo |uniq |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 
PROCESSOR=$(grep 'processor' /proc/cpuinfo |sort |uniq |wc -l)
Mode=$(getconf LONG_BIT) 

Numbers=$(grep 'lm' /proc/cpuinfo |wc -l) 
if (( ${Numbers} > 0)); then lm=64 
else lm=32 
fi 

Total=$(cat /proc/meminfo |grep 'MemTotal' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
Number=$(dmidecode | grep -A16 "Memory Device$" |grep Size|sort |sed 's/^[ \t]*//g')
SwapTotal=$(cat /proc/meminfo |grep 'SwapTotal' |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 
Buffers=$(cat /proc/meminfo |grep 'Buffers' |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 
Cached=$(cat /proc/meminfo |grep '\<Cached\>' |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 
Available=$(free -m |grep - |awk -F : '{print $2}' |awk '{print $2}') 
Max_Capacity=$(dmidecode -t memory -q |grep 'Maximum Capacity' |awk -F : '{print $2}' |sed 's/^[ \t]*//g') 

Disk=$(fdisk -l |grep 'Disk' |awk -F , '{print $1}')
Partion=$(df -hlP |sed -n '2,$p')

Line='===========' 

echo -e "${Line}\nOS:\n${OS}\n${Line}" 
echo -e "OS_version:\n${OS_version}\n${Line}" 
echo -e "Kernel_version:\n${kernel_version}\n${Line}" 
echo -e "CPU model:\n${CPU}\n${Line}" 
echo -e "Total of physical CPU:\n${Counts}\n${Line}" 
echo -e "Number of CPU cores\n${Cores}\n${Line}" 
echo -e "Number of logical CPUs:\n${PROCESSOR}\n${Line}"
echo -e "Present Mode Of CPU:\n${Mode}\n${Line}" 
echo -e "Support Mode Of CPU:\n${lm}\n${Line}" 
echo -e "Total Memory:\n${Total}\n${Line}" 
echo -e "Total Swap:\n${SwapTotal}\n${Line}" 
echo -e "Buffers:\n${Buffers}\n${Line}" 
echo -e "Cached:\n${Cached}\n${Line}" 
echo -e "Available Memory:\n${Available} MB\n${Line}" 
echo -e "Maxinum Memory Capacity:\n${Max_Capacity}\n${Line}" 
echo -e "Number of Physical Memory:\n${Number}\n${Line}"
echo -e "Amount Of Disks:\n${Disk}\n${Line}"
echo -e "Usage Of partions:\n${Partion}\n${Line}"

本文出自 蓝鹰博客,转载时请注明出处及相应链接。

本文永久链接: http://www.lanyingblog.com/blog/1774.html

Ɣ回顶部