本篇博客将介绍在Linux系统下查看服务器的各类硬件信息,文中的命令均由我自己编写整理并测试,如有问题,请及时告知,谢谢!
一、查看服务器的SN
dmidecode 命令可以查看系统中一些硬件的信息,包括主板、内存、 BIOS等一些信息
方法一:使用文本处理三剑客(各司其职)取出机器的SN,此种方法看上去有点长,但适用于所有dmidecode版本
dmidecode | grep -A10 'System Information' | grep -o 'Serial Number: .*'
dmidecode | sed -n '/System Information/,/Serial Number: /s@^[[:space:]]@@p' | sed '/Serial Number/!d'
dmidecode | awk '/System Information/,/Serial Number: /' | awk '/Serial Number: /' | awk -F'Serial Number: ' '{print $NF}'
........还有很多,我就不一一列举了
方法二:使用dmidecode的专用选项直接取出机器的SN,此种方法比较简单,但是dmidecode部分版本不支持该选项
dmidecode -s system-serial-number
dmidecode -s system-serial-number | sed '/^#/d'
方法三:使用dmidecode的选项+grep工具过滤出机器的SN,dmidecode部分版本不支持该选项
dmidecode -t system | grep -i 'serial number'
二、查看IPMI的SN
ipmitool fru print | grep "Product Serial"
ipmitool fru print | awk '/Product Serial/' | awk -F 'Product Serial[[:space:]]*[:][[:space:]]+' '{print $NF}'
三、查看服务器的厂商和型号
dmidecode | awk '/System Information/,/Product Name: /' | sed 's|^[[:space:]]*||'
dmidecode | sed -n '/System Information/,/Product Name: /p' | egrep -o 'Manufacturer.*|Product Name.*'
四、查看CPU信息
查看CPU型号
grep 'model name' /proc/cpuinfo | uniq
查看CPU数量(主板上实际插入的CPU数量)
grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l
查看CPU制造商
awk -F: '/vendor_id/{print $2}' /proc/cpuinfo | uniq
grep 'vendor_id' /proc/cpuinfo | uniq | awk -F: '{print $2}'
查看每颗物理CPU的核心数
grep 'cores' /proc/cpuinfo | uniq
查看CPU主频
grep 'cpu MHz' /proc/cpuinfo | uniq
查看CPU二级缓存
grep 'cache size' /proc/cpuinfo
查看是否开启超线程
egrep 'cpu cores|siblings' /proc/cpuinfo | sort | uniq
如果cpu cores数量和siblings数量一致,则没有启用超线程,如果cpu cores是siblings数量的二倍,则表示超线程已启用
查看逻辑CPU数量
grep 'processor' /proc/cpuinfo
grep 'processor' /proc/cpuinfo | wc -l
查看CPU全部信息
cat /proc/cpuinfo
lscpu
五、查看内存信息
查看内存使用情况
free -m/-g
查看内存详细信息
cat /proc/meminfo
查看已使用的内存槽位
dmidecode | grep -i 'Locator' | grep -v -i 'Bank' | grep -v -i 'NO DIMM'
dmidecode | grep -i 'Locator.*' | egrep -v -i '(Bank|NO DIMM)' | sed 's@[[:space:]]*@@'
dmidecode | awk '/Memory Device/,/DMI type/' | sed '/Bank Locator/d' | xargs | awk 'BEGIN{ RS="Memory Device" } {print $0}' | sed '/NO DIMM/d' | awk ' /Serial Number:/' | grep -o '\<Locator: [[:alnum:]_]*'
dmidecode | awk '/Memory Device$/,/Size:/' | sed '/No Module Installed/d' | grep 'Size'
查看内存数量和内存容量
dmidecode | awk '/Memory Device/,/DMI type/' | grep -o 'Range Size:.*'
dmidecode | awk '/Memory Device/,/DMI type/' | grep 'Size' | grep -v 'No Module Installed' | grep -o 'Range Size:.*'
dmidecode | awk '/Memory Device$/,/DMI type/' | grep -v 'No Module Installed' | egrep -o '^([[:space:]])*Size:.*'
dmidecode | awk '/Memory Device$/,/DMI type/' | grep 'Size' | grep -v 'No Module Installed'
查看已识别的内存的SN(文本处理三剑客,各司其职)
dmidecode | grep -A14 'Memory Device$' | grep -o 'Serial Numbe.*' | egrep -v '(NO DIMM|Unknown|SerNum|Not|Bank)'
dmidecode | sed -n '/Memory Device$/,/Serial Number/p' | sed -n '/Serial Numbe/p' | sed -r '/Serial Number: NO DIMM|Battery/d' | sed 's@^[[:space:]]*@@g' | sed -r '/Not|Bank/d'
dmidecode | awk '/Memory Device$/,/DMI type/' | awk '/Serial Number: [^NO DIMM|Unknown|Bank]/'
dmidecode | awk '/Memory Device$/,/DMI type/' | awk '/Serial Number: [^NO DIMM|Unknown|Bank]/' | awk -F: '{print $NF}' | xargs | awk '{gsub(" ",", ",$0);print}'
查看最大支持多大内存
dmidecode | grep 'Maximum Capacity'
dmidecode | grep 'Maximum Total Memory Size'
查看内存大小、接口、频率、SN信息
dmidecode | awk '/Memory Device$/,/DMI type/' | egrep '(Memory Device|Size:|Locator:|Speed:|Serial Number:)' | xargs | awk 'BEGIN{ RS="Memory Device" } {print $0}' | sed -r '/NO DIMM|No Module/d' | sed 's|^[[:space:]]\+||'
dmidecode | awk '/Memory Device$/,/DMI type/' | awk '/Memory Device|Size|Locator|Bank Locator|Speed|Serial Number/' | xargs | awk 'BEGIN{ RS="Memory Device" }{if ( $0 !~ /NO DIMM|No Module Installed/ ) print $0}' | awk '{ gsub ("^ ","",$0); print}'
dmidecode | sed -n '/Memory Device$/,/DMI type/p' | sed -nr '/(Memory Device|Size:|Locator:|Speed:|Serial Number:)/p' | sed ':a;N;$!ba;s|\n||g' | sed 's|Memory Device|\n|g' | sed -r '/(NO DIMM|No Module Installed)/d'
六、查看硬盘信息
查看磁盘分区信息
fdisk -l
parted -ls
查看硬盘挂载情况
mount
cat /proc/mounts
df -hT
查看单个分区信息
fdisk -l /dev/sdX
parted /dev/sdX print
查看系统已识别的磁盘大小
fdisk -l | grep 'Disk'
parted -ls | grep 'Disk'
查看系统已识别的硬盘的SN
for D in $(parted -ls | grep Disk | awk -F': ' '{print $1}' | awk '{print $2}');do echo $D;smartctl -i $D | grep '^Serial Number' | awk -F'Serial Number:[[:space:]]*' '{print $NF}' ;done
for D in $(parted -ls | grep Disk | awk -F': ' '{print $1}' | awk '{print $2}');do smartctl -i $D | grep '^Serial Number' | awk -F'Serial Number:[[:space:]]*' '{print $NF}' ;done | nl
for D in $(parted -ls | grep Disk | awk -F': ' '{print $1}' | awk '{print $2}');do smartctl -i $D | grep '^Serial Number' | awk -F'Serial Number:[[:space:]]*' '{print $NF}' ;done | xargs | awk '{gsub(" ",", ",$0);print}'
查看单个硬盘的SN
smartctl -i /dev/sdX | grep '^Serial Number'
查看硬盘型号
smartctl -i /dev/sdX | grep '^Device Model: '
判断硬盘是HDD还是SSD
for Device in $(ls /dev/ | egrep '^sd' | tr -d [0-9] | uniq);do echo ------ $Device ------ ; Type=$(cat /sys/block/$Device/queue/rotational); [ $Type -eq 0 ] && echo 'SSD' || echo 'HHD' ; done
七、查看陈列卡
LSI陈列卡使用MegaCli和storcli工具
查看RAID卡信息
MegaCli -AdpAllInfo -aALL
MegaCli -LdInfo -LALL -aAll
storcli show all
查看RAID中硬盘信息
MegaCli -PDList –aALL
storcli /c0 show // 0为第1个RAID卡
注意:MegaCli命令是Linux命令中为数不多的由大小写字母组成的命令
HP的服务器使用hpacucli工具
查看RAID卡信息
hpacucli ctrl all show
hpacucli ctrl all show detail
查看RAID中硬盘信息
hpacucli
hpacucli
八、查看GPU(显卡)
查看系统上所有GPU的SN
nvidia-smi -a | grep -o 'Serial Number.*.*'
nvidia-smi -q | grep -o 'Serial Number.*.*'
nvidia-smi -a | awk '/Serial Number/' | awk -F': ' '{print $NF}'
nvidia-smi -q | awk '/Serial Number/' | awk -F': ' '{print $NF}'
查看指定的GPU的SN
nvidia-smi -q -i GPU_NUMBER | grep -o 'Serial Number.*.*' // GPU_NUMBER 为GPU的编号(Minor Number),从0开始
nvidia-smi -q -i 0 | grep -o 'Serial Number.*.*' // 查看第一块GPU的SN
nvidia-smi -q -i 0,2 | grep -o 'Serial Number.*.*' // 查看第一块和第三块GPU的SN
查看系统上的识别的GPU数量和对应的UUID
lspci | grep -i 'NVIDIA'
nvidia-smi -L
nvidia-smi --list-gpus
显示所需信息
nvidia-smi -q | sed -r '/\<(GPU 00000000|Attached GPUs|Serial Number|GPU UUID|Product Name|Product Brand|Driver Model|Minor Number|VBIOS Version|Fan Speed)\>/!d;/GPU 00000000.*/i\ '
九、查看网卡
查看系统是否已识别网卡
lspci | grep -i eth
lspci | grep net
查看网卡驱动信息
ethtool -i DEVICE_NAME // DEVICE_NAME为网卡名称,如eth0、em0、ens ......
ethtool -i DEVICE_NAME | grep 'driver'
查看网卡固件版本
ethtool -i DEVICE_NAME | grep 'firmware-version'
查看系统所有已激活(UP)状态的网卡信息
ifconfig
查看系统单个已激活(UP)状态的网卡信息
ifconfig DEVICE_NAME
查看系统上所有网卡信息(包含已激活和未激活的)
ifconfig -a
ip a
查看网卡收发包信息
ethtool -S DEVICE_NAME
查看网卡速率
ethtool DEVICE_NAME | grep 'Speed'
查看网卡链路状态
ethtool DEVICE_NAME | grep 'Link detected'
十、查看电源SN
dmidecode | awk '/System Power Supply/,/Serial Number: /' | awk '/Serial Number: /' | awk -F'Serial Number: ' '{print $NF}'
十一、查看光模块SN
ethtool -m DEVICE_NAME | grep 'Vendor SN'
未完待续 ....