系统管理
uptime - 显示系统的运行时间及负载
有时候我们怀疑系统被人重启过,需要看下系统从啥时候开机的,运行了多少天了?
uptime --help
[root@dp27m1 ~]# uptime
09:09:42 up 31 days, 5:34, 2 users, load average: 0.00, 0.01, 0.05
[root@dp27m1 ~]# uptime -s
2020-02-18 03:34:52
free - 查看系统内存信息
free --help
man free
free -h
free -h
[root@dp27m1 ~]# free -h
total used free shared buff/cache available
Mem: 15G 506M 12G 49M 3.0G 14G
Swap: 0B 0B 0B
一般我们看系统的剩余内存,只需要看available的容量即可,每个字段的具体解释可参考man help
# buffer 和 cache 有什么区别 ?
buffer 缓冲区 cache 缓存,读cache,写buffer
buffer和cache是内存中的2个不同的区域。
buffer 把数据写入到内存的buffer区域,写buffer或者叫做,写缓冲
cache缓存区 从内存中的cache区域进行读取,读cache,读缓存
df - 查看磁盘剩余空间
man df
df --help
[root@dp27m1 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.9G 0 7.9G 0% /dev
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 7.9G 50M 7.8G 1% /run
tmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda2 xfs 30G 1.8G 28G 6% /
/dev/sda1 xfs 497M 64M 433M 13% /boot
/dev/sdb1 ext4 32G 49M 30G 1% /mnt/resource
/dev/sdc ext4 252G 6.7G 233G 3% /data
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/1000
vmstat - 虚拟内存统计
vmstat --help
[root@dp27m1 ~]# vmstat -d -w
disk- -------------------reads------------------- -------------------writes------------------ ------IO-------
total merged sectors ms total merged sectors ms cur sec
fd0 0 0 0 0 0 0 0 0 0 0
sdb 469 0 33242 582 1397 33630 68427144 287924 0 2
sr0 39 0 248 43 0 0 0 0 0 0
sdc 1319553 22040 147411378 167502122 194337422 133816139 4362182776 1570284439 0 615174
sda 462686 358 75929054 65008658 3218992 23000 36004558 9527545 0 1856
[root@dp27m1 ~]# vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 12757292 194064 2942496 0 0 11 185 4 4 6 5 84 5 0
上面字段的详细含义可参考 man vmstat
mpstat - CPU信息统计
[root@dp27m1 ~]# mpstat
Linux 3.10.0-1062.9.1.el7.x86_64 (dp27m1) 03/20/2020 _x86_64_ (4 CPU)
09:50:14 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:50:14 AM all 6.04 0.00 3.86 5.02 0.00 1.21 0.00 0.00 0.00 83.87
iostat - I/O信息统计
[root@dp27m1 ~]# iostat
Linux 3.10.0-1062.9.1.el7.x86_64 (dp27m1) 03/20/2020 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
6.04 0.00 5.07 5.02 0.00 83.87
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sdb 0.00 0.01 12.67 16637 34213632
scd0 0.00 0.00 0.00 124 0
sdc 72.44 27.29 807.50 73705689 2181091388
sda 1.36 14.06 6.67 37964743 18005693
查看vda磁盘速度
iostat 1 -d -h -y -k -p vda
百分比显示
iostat -dxm 1
iostat -xm 1
iotop - 动态显示磁盘I/O统计信息
yum install iotop
iostat -k
这个工具用来快速显示磁盘读写速度还是挺方便的
sar - 收集系统历史负载
sar -h
sar --help
https://abdussamad.com/archives/167-CPU-load-average-history-in-Linux.html
sar -q
/var/log/sa
ls -lrht --full-time /var/log/sa
sar -q -s 22:00:00 -e 00:00:00 -f /var/log/sa/sa10
2020-03-19 22:00~00:00 历史负载情况
[root@xingyongsheng sa]# sar -q -s 22:00:00 -e 00:00:00 -f /var/log/sa/sa19
Linux 3.10.0-957.1.3.el7.x86_64 (xingyongsheng) 03/19/2020 _x86_64_ (2 CPU)
10:00:01 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
10:10:01 PM 7 1288 0.20 0.27 0.28 0
10:20:01 PM 5 1288 0.12 0.29 0.31 0
10:30:01 PM 4 1288 0.23 0.34 0.33 0
10:40:01 PM 1 1288 0.15 0.19 0.25 0
10:50:01 PM 1 1288 0.31 0.20 0.23 0
11:00:01 PM 4 1288 0.02 0.17 0.22 0
11:10:01 PM 7 1288 0.26 0.43 0.34 0
11:20:01 PM 4 1289 0.31 0.35 0.34 0
11:30:01 PM 2 1288 0.38 0.33 0.32 0
11:40:01 PM 5 1288 0.36 0.32 0.32 0
11:50:01 PM 3 1289 0.38 0.47 0.41 0
Average: 4 1288 0.25 0.31 0.30 0
chkconfig - 管理开机服务
[root@node1 ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
chkconfig --level 3 sshd off
chkconfig --list sshd
chkconfig --level 3 sshd on
ethtool eth0
[root@node1 ~]# mii-tool eth0
eth0: no autonegotiation, 1000baseT-FD flow-control, link ok
dmidecode - 查询系统硬件信息
[root@xingyongsheng ~]# dmidecode -s
dmidecode: option requires an argument -- 's'
String keyword expected
Valid string keywords are:
bios-vendor
bios-version
bios-release-date
system-manufacturer
system-product-name
system-version
system-serial-number
system-uuid
system-family
baseboard-manufacturer
baseboard-product-name
baseboard-version
baseboard-serial-number
baseboard-asset-tag
chassis-manufacturer
chassis-type
chassis-version
chassis-serial-number
chassis-asset-tag
processor-family
processor-manufacturer
processor-version
processor-frequency
[root@xingyongsheng ~]#
[root@xingyongsheng ~]# dmidecode -s system-product-name
Alibaba Cloud ECS
[root@xingyongsheng ~]# dmidecode -s system-version
pc-i440fx-2.1
[root@xingyongsheng ~]# dmidecode -s processor-frequency
Unknown
[root@xingyongsheng ~]# dmidecode -t bios
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
Vendor: SeaBIOS
Version: 8c24b4c
Release Date: 04/01/2014
Address: 0xE8000
Runtime Size: 96 kB
ROM Size: 64 kB
Characteristics:
BIOS characteristics not supported
Targeted content distribution is supported
BIOS Revision: 0.0
lspci - 显示所有PCI设备
[root@xingyongsheng ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:04.0 Communication controller: Red Hat, Inc. Virtio console
00:05.0 SCSI storage controller: Red Hat, Inc. Virtio block device
00:06.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
ipcs - 显示进程间通信设施的状态
[root@xingyongsheng ~]# ipcs
------ Message Queues --------
key msqid owner perms used-bytes messages
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
------ Semaphore Arrays --------
key semid owner perms nsems
0x002fa327 0 root 600 2
ipcrm - 清楚ipc相关信息
没什么暖用
dstat
[root@qp174.qq /data2/rpm-local]# dstat
----total-cpu-usage---- -dsk/total- ---load-avg--- ------memory-usage----- -net/total- ---procs--- ----swap--- ---system--
usr sys idl wai hiq siq| read writ| 1m 5m 15m | used buff cach free| recv send|run blk new| used free| int csw
0 0 100 0 0 0| 615B 184k|0.04 0.09 0.06|1748M 1066M 3730M 40.6G| 0 0 | 0 0 12| 0 8192M| 624 547
0 0 100 0 0 0| 0 4096B|0.04 0.08 0.06|1747M 1066M 3730M 40.6G| 916k 11k| 0 0 0| 0 8192M| 585 489
0 0 100 0 0 0| 0 2576k|0.04 0.08 0.06|1748M 1066M 3731M 40.6G| 486k 7147B| 0 0 1.0| 0 8192M| 494 451
0 0 100 0 0 0| 0 0 |0.04 0.08 0.06|1747M 1066M 3731M 40.6G| 306k 4423B| 0 0 0| 0 8192M| 403 382
0 0 100 0 0 0| 0 0 |0.04 0.08 0.06|1748M 1066M 3731M 40.6G| 693k 8360B| 0 0 2.0| 0 8192M| 565 490
0 0 100 0 0 0| 0 0 |0.04 0.08 0.06|1748M 1066M 3733M 40.6G| 721k 8684B|1.0 0 0| 0 8192M| 616 493
0 0 99 0 0 0| 0 24k|0.04 0.08 0.06|1748M 1066M 3736M 40.6G|4378k 28k| 0 0 1.0| 0 8192M|1481 1074
0 0 100 0 0 0| 0 1756k|0.04 0.08 0.06|1747M 1066M 3737M 40.6G| 632k 8275B| 0 0 0| 0 8192M| 743 1180
0 0 100 0 0 0| 0 0 |0.04 0.08 0.06|1748M 1066M 3739M 40.6G|1424k 15k| 0 0 5.0| 0 8192M| 953 693
0 0 99 0 0 0| 0 0 |0.04 0.08 0.06|1748M 1066M 3741M 40.6G|3255k 29k| 0 0 0| 0 8192M|1088 674
0 0 100 0 0 0| 0 0 |0.04 0.08 0.06|1748M 1066M 3742M 40.6G| 56k 6056B| 0 0 0| 0 8192M| 365 365
0 0 100 0 0 0| 0 0 |0.03 0.08 0.06|1748M 1066M 3742M 40.6G| 204k 4913B| 0 0 0| 0 8192M| 404 393
0 0 100 0 0 0| 0 18M|0.03 0.08 0.06|1748M 1066M 3744M 40.6G|1600k 15k| 0 0 0| 0 8192M| 968 640
0 0 100 0 0 0| 0 0 |0.03 0.08 0.06|1748M 1066M 3746M 40.6G|2176k 19k| 0 0 1.0| 0 8192M| 762 560
0 0 100 0 0 0| 0 0 |0.03 0.08 0.06|1748M 1066M 3748M 40.6G|2949k 24k| 0 0 1.0| 0 8192M|1054 828 ^C