Linux 不像 Windows,右键属性就可以看到大部分系统信息,而且大多数时候,做为服务器系统,Linux 是不带图形化界面的,这就要求使用者对查看、获取系统信息的命令了然于心,下面做个汇总介绍。
1、硬件
① CPU
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
2 Intel(R) Xeon(R) CPU E5-2609 v2 @ 2.50GHz
看到有 2 个逻辑 CPU, CPU 型号是 Intel(R) Xeon(R) CPU E5-2609 v2,频率是 2.50GHz。
# cat /proc/cpuinfo | grep physical | uniq -c
1 physical id : 0
1 address sizes : 40 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 40 bits physical, 48 bits virtual
说明实际上是两颗 1 核 CPU。
# getconf LONG_BIT
64
说明工作在 64 位 环境下。
要查看完整 CPU 信息,可以输入该命令:
# cat /proc/cpuinfo
② 网卡
# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.2.0.201 netmask 255.255.255.0 broadcast 10.2.0.255
inet6 fe80::6b14:d615:5c30:a165 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:25:19:56 txqueuelen 1000 (Ethernet)
RX packets 797476 bytes 495744087 (472.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 702443 bytes 446967124 (426.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 83 bytes 6675 (6.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 83 bytes 6675 (6.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
看到有两个接口,其中 lo 是本地环回接口。
# ethtool ens160
Settings for ens160:
Supported ports: [ TP ]
Supported link modes: 1000baseT/Full
10000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: No
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
MDI-X: Unknown
Supports Wake-on: uag
Wake-on: d
Link detected: yes
看到是 万兆全双工 (Supported link modes)网卡,此时工作在万兆网络(Speed)中。
# lspci | grep Ethernet
03:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
可以看到该网卡的制造商和型号。
③ 硬盘
# df -h | awk '$NF == "/" {print $2,$(NF-1),$NF}'
8.0G 42% /
可以看到硬盘大小及已使用情况。
# mount | column -t # 查看挂载的分区状态
# fdisk -l # 查看所有分区, df -h 亦可
# swapon -s # 查看所有交换分区
# du -sh <目录名> # 查看指定目录的大小
④ 内存
# free -m
total used free shared buff/cache available
Mem: 1994 314 1424 8 254 1470
Swap: 1023 0 1023
查看内存使用量和交换区使用量。
或者:
# grep Mem /proc/meminfo
MemTotal: 2042292 kB
MemFree: 1458656 kB
MemAvailable: 1505640 kB
# dmidecode -t memory|grep Size
Maximum Memory Module Size: 32768 MB
Maximum Total Memory Size: 491520 MB
Installed Size: 2048 MB (Single-bank Connection)
Enabled Size: 2048 MB (Single-bank Connection)
查看内存条数量,可能会有很多。
要查看完整 内存 信息,可以输入该命令:
# cat /proc/meminfo
⑤ 机器型号
# dmidecode | grep "Product Name"
Product Name: VMware Virtual Platform
Product Name: 440BX Desktop Reference Platform
⑥ 其他
# lspci -tv # 列出所有PCI设备
# lsusb -tv # 列出所有USB设备
2、系统
① 参数
# uname -r # 查看内核版本
4.13.9-1.el7.elrepo.x86_64
# cat /etc/redhat-release # 查看操作系统版本(CentOS)
CentOS Linux release 7.4.1708 (Core)
# cat lsb-release # 查看操作系统版本(Ubuntu)
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
# hostname # 查看计算机名
VirCloud
# lsmod # 列出加载的内核模块
# env # 查看环境变量
# iptables -L # 查看防火墙设置
# route -n # 查看路由表
# chkconfig --list # 列出所有系统服务
② 用户
# w # 查看活动用户
# id <用户名> # 查看指定用户信息
# last # 查看用户登录、启动日志
# cut -d: -f1 /etc/passwd # 查看系统所有用户
# cut -d: -f1 /etc/group # 查看系统所有用户组
# crontab -l # 查看当前用户的计划任务
③ 应用
# rpm -qa |grep kernel # 在所有安装的软件包中列出含有 kernel 的软件名
3、负载(使用情况)
① 负载
# uptime # 查看系统运行时间、用户数、负载
11:00:59 up 8 days, 16:09, 1 user, load average: 0.00, 0.00, 0.00
load average:统计最近 1,5,15 分钟的系统平均负载
也可以执行以下命令查看:
# cat /proc/loadavg # 查看系统负载
0.00 0.00 0.00 1/128 8292
② 网络
# netstat -lntp # 查看所有正在监听的 TCP 端口
# netstat -antp # 查看所有已经建立的连接
# cat /sys/class/net/`route -n | awk '$1 == "0.0.0.0" {print $8}' | head`/statistics/tx_bytes # 已产生网络流量(重启会置 0)
465619275
流量监控可参考之前的文章 《Linux 下流量监控统计工具 - Vnstat》 设置监控。
③ 进程
# ps -ef # 查看所有进程
# top # 实时显示进程状态
# ps auxw|head -1;ps auxw|sort -rn -k3|head -10 # CPU 占用最多的前 10 个进程
# ps auxw|head -1;ps auxw|sort -rn -k4|head -10 # 内存消耗最多的前 10 个进程
你可能还需要:
1、《Linux 下如何查看指定进程发起的所有连接信息》
2、《Linux 环境下可视化查看网络连接、流量、带宽》
参考文章:
1、《查询系统负载信息 Linux 命令详解》
2、《Linux 查看CPU信息,机器型号,内存等信息》
3、《HyperApp commands》
4、《linux下查看最消耗CPU、内存的进程》