[root@alexis-01 ~]# w
20:39:38 up 1 min, 1 user, load average: 0.47, 0.29, 0.12
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.194.1 20:39 2.00s 0.00s 0.00s w
1分钟内,5分钟内,15分钟内
负载值:平均时间内,有多少个活动的进程。数字越大越忙。
正在使用 CPU 或等待 CPU 都属于活动的进程,无论在排队还是正在使用都属于活动进程
[root@alexis-01 ~]# uptime
20:39:57 up 1 min, 1 user, load average: 0.34, 0.27, 0.11
[root@arslinux-01 ~]# top
top - 20:40:49 up 2 min, 1 user, load average: 0.14, 0.23, 0.11
Tasks: 103 total, 1 running, 102 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 1.0 sy, 0.0 ni, 98.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 995896 total, 266560 free, 581216 used, 148120 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 253124 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
25 root 20 0 0 0 0 S 0.3 0.0 0:00.27 kworker/0:1
32 root 39 19 0 0 0 S 0.3 0.0 0:00.07 khugepaged
2903 root 20 0 0 0 0 S 0.3 0.0 0:00.04 xfsaild/sda3
6152 root 20 0 301048 6488 5124 S 0.3 0.7 0:00.20 vmtoolsd
1 root 20 0 125308 3748 2564 S 0.0 0.4 0:01.08 systemd
略
按 q 退出
CPU 使用率 = 100% - id值
RES 进程占用物理内存的大小
top 命令不仅要关注 Tasks 、%CPU 列,同样要关注下方 %CPU、%MEM、RES 列
– 每 3 秒刷新一次
– 按 M 键更改未按内存使用率大小排列
– 按数字 1 可以查看所有 CPU 的使用率详情(多核)
[root@alexis-01 ~]# top -bn1
top - 20:42:28 up 4 min, 1 user, load average: 0.11, 0.18, 0.10
Tasks: 103 total, 1 running, 102 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 995896 total, 261884 free, 585892 used, 148120 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 248448 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125308 3748 2564 S 0.0 0.4 0:01.08 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.11 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kworker/u256:0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:00.42 rcu_sched
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
(内容过多不全显示)
– 静态显示进程信息方便与在脚本里使用
[root@alexis-01 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
stepping : 11
microcode : 0xa4
cpu MHz : 1799.999
cache size : 6144 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
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 syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
bogomips : 3599.99
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
[root@alexis-01 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
座: 1
NUMA 节点: 1
厂商 ID: GenuineIntel
CPU 系列: 6
型号: 142
型号名称: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
步进: 11
CPU MHz: 1799.999
BogoMIPS: 3599.99
超管理器厂商: VMware
虚拟化类型: 完全
L1d 缓存: 32K
L1i 缓存: 32K
L2 缓存: 256K
L3 缓存: 6144K
NUMA 节点0 CPU: 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat spec_ctrl intel_stibp flush_l1d arch_capabilities
[root@alexis-01 ~]# free
total used free shared buff/cache available
Mem: 995896 585696 261816 7860 148384 248512
Swap: 4194300 0 4194300
[root@alexis-01 ~]# free -m
total used free shared buff/cache available
Mem: 972 571 255 7 144 242
Swap: 4095 0 4095
[root@alexis-01 ~]# free -h
total used free shared buff/cache available
Mem: 972M 571M 255M 7.7M 144M 242M
Swap: 4.0G 0B 4.0G
[root@alexis-01 ~]# free -b
total used free shared buff/cache available
Mem: 1019797504 599580672 268251136 8048640 151965696 254640128
Swap: 4294963200 0 4294963200
只需关注 available,available = free + buff/cache 未使用的部分
内存不够用时,swap 会将内存里的内容交换到磁盘分区里
buffer: 从 CPU 产生,即将写入到磁盘里去的那部分数据
cached: 先从磁盘里读出来,然后临时存到内存里的那部分数据
[root@alexis-01 ~]# dd if=/dev/zero of=/bigfile bs=100M count=10
记录了10+0 的读入
记录了10+0 的写出
1048576000字节(1.0 GB)已复制,2.78826 秒,376 MB/秒
[root@alexis-01 ~]# du -sh /bigfile
1000M /bigfile
[root@alexis-01 ~]# mkswap /bigfile
正在设置交换空间版本 1,大小 = 1023996 KiB
无标签,UUID=c14ed140-f2d6-453a-aa53-01438bee2918
[root@alexis-01 ~]# chmod 600 /bigfile
[root@alexis-01 ~]# swapon /bigfile
[root@alexis-01 ~]# free
total used free shared buff/cache available
Mem: 995896 587880 185788 7860 222228 236824
Swap: 5218296 0 5218296
[root@alexis-01 ~]# iostat
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.43 0.00 1.16 0.05 0.00 98.36
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.77 135.38 597.09 243821 1075360
scd0 0.01 0.57 0.00 1028 0
[root@alexis-01 ~]# iostat 1
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.43 0.00 1.15 0.05 0.00 98.38
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.66 133.29 587.85 243821 1075360
scd0 0.01 0.56 0.00 1028 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 1.00 0.00 1.50 0 1
scd0 0.00 0.00 0.00 0 0
^C
[root@alexis-01 ~]# iostat -d
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.50 129.91 572.96 243821 1075396
scd0 0.01 0.55 0.00 1028 0
[root@alexis-01 ~]# iostat -dx 1
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 0.05 3.76 2.54 125.86 555.16 216.17 0.01 0.82 0.60 1.15 0.48 0.30
scd0 0.00 0.00 0.01 0.00 0.53 0.00 114.22 0.00 1.67 1.67 0.00 1.28 0.00
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
^C
关注 %util,磁盘的使用率
[root@alexis-01 ~]# iostat -d 1 2
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 6.11 121.98 538.12 243821 1075619
scd0 0.01 0.51 0.00 1028 0
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
[root@alexis-01 ~]# iotop
Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
6144 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % VGAuthService -s
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 22
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]
5 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]
6 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/u256:0]
7 rt/4 root 0.00 B/s 0.00 B/s 0.00 %
略
[root@alexis-01 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 264 138572 112 264484 0 0 118 506 81 220 0 1 98 0 0
[root@alexis-01 ~]# vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 264 138844 112 264516 0 0 116 498 80 218 0 1 99 0 0
0 0 264 138820 112 264516 0 0 0 0 44 85 0 1 99 0 0
0 0 264 138820 112 264516 0 0 0 0 39 76 0 0 100 0 0
CPU ——> id
memory——>swpd 非零 或 si so 非零(si = swap in从swap进到内存,so = swap out)
bi 磁盘读,bo 磁盘写
r = run,b =block
wa =wait 等待 CPU 的百分比
关注: r、b、si、so、bi、bo、id、wa
[root@alexis-01 ~]# sar
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
[root@alexis-01 ~]# sar -n DEV 1 3
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
21时16分09秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
21时16分10秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
21时16分10秒 ens33 1.01 1.01 0.06 0.17 0.00 0.00 0.00
21时16分10秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
21时16分11秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
21时16分11秒 ens33 1.00 1.00 0.06 0.38 0.00 0.00 0.00
21时16分11秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
21时16分12秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
21时16分12秒 ens33 1.00 2.00 0.06 0.46 0.00 0.00 0.00
平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: ens33 1.00 1.34 0.06 0.34 0.00 0.00 0.00
小常识:
bit 比特(带宽单位)
Byte 字节(速度传输单位)
8bit = 1Byte
/var/log/sa/saxx xx为日期
[root@alexis-01 ~]# sar -f /var/log/sa/sa12
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
21时10分01秒 CPU %user %nice %system %iowait %steal %idle
21时20分01秒 all 0.25 0.02 0.27 0.02 0.00 99.45
平均时间: all 0.25 0.02 0.27 0.02 0.00 99.45
– sar -n DEV -f /var/log/sa/sa14 只看具体日期的网卡流量
[root@alexis-01 ~]# sar -b
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
21时10分01秒 tps rtps wtps bread/s bwrtn/s
21时20分01秒 1.54 0.72 0.82 41.75 20.63
平均时间: 1.54 0.72 0.82 41.75 20.63
[root@alexis-01 ~]# sar -q
Linux 3.10.0-957.el7.x86_64 (alexis-01) 2019年11月12日 _x86_64_ (1 CPU)
21时10分01秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
21时20分01秒 1 138 0.00 0.01 0.05 0
平均时间: 1 138 0.00 0.01 0.05 0
[root@alexis-01 ~]# ethtool ens33
Settings for ens33:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
[root@alexis-01 ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok
[root@alexis-01 ~]# ps -eLf |grep mysql
root 6921 1 6921 0 1 20:38 ? 00:00:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/alexis-01.pid
mysql 7209 6921 7209 0 21 20:38 ? 00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7383 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7384 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7385 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7386 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7387 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7388 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7389 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7390 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7391 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7392 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7394 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7395 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7396 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7397 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7398 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7399 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7400 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7401 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7402 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
mysql 7209 6921 7403 0 21 20:38 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/alexis-01.pid --socket=/tmpmysql.sock
root 7891 7411 7891 0 1 21:29 pts/0 00:00:00 grep --color=auto mysql
S 处于休眠状态
R 正在运行中
s 父进程(有子进程)
l 多线程
< 优先级高
N 优先级低
扩展连接: https://www.cnblogs.com/huangmr0811/p/5570999.html
[root@alexis-01 ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6934/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6904/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7277/master
tcp6 0 0 :::3306 :::* LISTEN 7209/mysqld
tcp6 0 0 :::22 :::* LISTEN 6904/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7277/master
udp 0 0 192.168.194.128:123 0.0.0.0:* 6199/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 6199/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 6199/ntpd
udp6 0 0 fe80::44c7:9759:a31:123 :::* 6199/ntpd
udp6 0 0 ::1:123 :::* 6199/ntpd
udp6 0 0 :::123 :::* 6199/ntpd
raw6 0 0 :::58 :::* 7 6459/NetworkManager
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 33818 6144/VGAuthService /var/run/vmware/guestServicePipe
unix 2 [ ACC ] STREAM LISTENING 21018 1/systemd /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 38342 7277/master private/relay
unix 2 [ ACC ] STREAM LISTENING 38348 7277/master private/error
unix 2 [ ACC ] STREAM LISTENING 38351 7277/master private/retry
unix 2 [ ACC ] SEQPACKET LISTENING 21071 1/systemd /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 38321 7277/master private/defer
unix 2 [ ACC ] STREAM LISTENING 38354 7277/master private/discard
unix 2 [ ACC ] STREAM LISTENING 38324 7277/master private/trace
unix 2 [ ACC ] STREAM LISTENING 38327 7277/master private/verify
unix 2 [ ACC ] STREAM LISTENING 38357 7277/master private/local
unix 2 [ ACC ] STREAM LISTENING 38360 7277/master private/virtual
unix 2 [ ACC ] STREAM LISTENING 38363 7277/master private/lmtp
unix 2 [ ACC ] STREAM LISTENING 38366 7277/master private/anvil
unix 2 [ ACC ] STREAM LISTENING 38369 7277/master private/scache
unix 2 [ ACC ] STREAM LISTENING 32680 1/systemd /run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 38333 7277/master private/proxymap
unix 2 [ ACC ] STREAM LISTENING 38336 7277/master private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 38339 7277/master private/smtp
unix 2 [ ACC ] STREAM LISTENING 38301 7277/master public/pickup
unix 2 [ ACC ] STREAM LISTENING 38305 7277/master public/cleanup
unix 2 [ ACC ] STREAM LISTENING 38308 7277/master public/qmgr
unix 2 [ ACC ] STREAM LISTENING 38330 7277/master public/flush
unix 2 [ ACC ] STREAM LISTENING 38345 7277/master public/showq
unix 2 [ ACC ] STREAM LISTENING 38312 7277/master private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 38315 7277/master private/rewrite
unix 2 [ ACC ] STREAM LISTENING 38318 7277/master private/bounce
unix 2 [ ACC ] STREAM LISTENING 38641 7209/mysqld /tmp/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 8941 1/systemd /run/systemd/journal/stdout
[root@alexis-01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6934/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6904/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7277/master
tcp6 0 0 :::3306 :::* LISTEN 7209/mysqld
tcp6 0 0 :::22 :::* LISTEN 6904/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7277/master
netstat -lnup 只查看 udp 监听的连接状态
netstat -lntup 查看 tcp 和 udp 监听的连接状态
netstat -an 查看所有的网络连接,包括监听的,包括已连接的
ss -an 类似于 netstat -an,显示更快,如果 netstat -an 比较慢,可以尝试 ss -an
ESTABLISHED 建立连接
TIME_WAIT 要断还没断开就是
扩展连接: https://blog.csdn.net/m0_37556444/article/details/83000553
[root@alexis-01 ~]# tcpdump -nn -i ens33 port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
21:42:48.705174 IP 192.168.194.128.22 > 192.168.194.1.9569: Flags [P.], seq 656748:656904, ack 73, win 252, length 156
21:42:48.709009 IP 192.168.194.128.22 > 192.168.194.1.9569: Flags [P.], seq 656904:657164, ack 73, win 252, length 260
21:42:48.710931 IP 192.168.194.1.9569 > 192.168.194.128.22: Flags [.], ack 657164, win 4103, length 0
略
^C
4749 packets captured
4749 packets received by filter
0 packets dropped by kernel
tcpdump -r 读取 .cap 文件
可以用 windows上 wireshark 分析 .cap 文件
tshark 抓包工具(需要安装 wireshark 包)和 tcpdump 用法类似
[root@alexis-01 ~]# tshark -nn -i ens33
Running as user "root" and group "root". This could be dangerous.
Capturing on 'ens33'
1 0.000000000 192.168.194.1 -> 192.168.194.128 TCP 66 11132 > 22 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
2 0.000133141 192.168.194.128 -> 192.168.194.1 TCP 66 22 > 11132 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=128
3 0.000259471 192.168.194.1 -> 192.168.194.128 TCP 60 11132 > 22 [ACK] Seq=1 Ack=1 Win=1051136 Len=0
4 0.025717491 192.168.194.128 -> 192.168.194.1 SSH 75 Server Protocol: SSH-2.0-OpenSSH_7.4\r
5 0.066952217 192.168.194.1 -> 192.168.194.128 TCP 60 11132 > 22 [ACK] Seq=1 Ack=22 Win=1051136 Len=0
6 0.145306340 192.168.194.1 -> 192.168.194.128 SSH 104 Client Protocol: SSH-2.0-nsssh2_6.0.0024 NetSarang Computer, Inc.\r
7 0.145884553 192.168.194.128 -> 192.168.194.1 SSH 778 Encrypted response packet len=724
8 0.146052089 192.168.194.128 -> 192.168.194.1 TCP 54 22 > 11132 [ACK] Seq=22 Ack=51 Win=29312 Len=0
9 0.146402780 192.168.194.1 -> 192.168.194.128 SSHv2 1526 Client: Key Exchange Init
10 0.146425753 192.168.194.128 -> 192.168.194.1 TCP 54 22 > 11132 [ACK] Seq=22 Ack=1523 Win=32256 Len=0
tshark -i 端口号 -n -t a -R http.request -T fields -e “frame.time” -e “ip.src” -e “http.host” -e “http.request.method” -e "http.request.uri"
结果和访问日志一样