学习linux14
学习任务
监控系统状态
w/uptime 查看系统负载
[[email protected] ~]# w
15:26:23 up 18:38, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts/0 192.168.18.1 六21 7.00s 0.11s 0.05s w
上面第一行 显示系统时间, 当前的运行时间,目前登录的用户几个, load average: 0.00, 0.01, 0.05系统的负载,三个数字分别表示1分钟 5分钟 15分钟之内 系统的负载值是多少 单位时间段内使用cpu活动的进程有多少个
FROM表示从哪里来
[email protected]表示登陆时间
IDLE空闲了多长时间
JCPU PCUP使用了cpu的时间 WHAT命令
uptime和w命令类似
[[email protected] ~]# uptime
15:41:54 up 18:53, 1 user, load average: 0.00, 0.01, 0.05
cat /proc/cpuinfo查看cpu核数
[[email protected] ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping : 9
microcode : 0x84
cpu MHz : 2712.001
cache size : 3072 KB
physical id : 0
siblings : 1
其中processor数值 表示本机cpu核数 如果是0 说明有1颗cpu 如果是1 说明有2个
vmastat监控系统状态
[[email protected] ~]# vmstat
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 0 705696 2076 157288 0 0 2 0 27 41 0 0 100 0 0
用法 vmstat1 每一秒查看一次系统状态 ctrl+c停止
[[email protected] ~]# vmstat 1
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 0 705696 2076 157288 0 0 2 0 27 41 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 28 42 0 1 99 0 0
0 0 0 705672 2076 157288 0 0 0 0 28 37 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 24 32 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 34 43 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 26 36 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 31 41 0 0 100 0 0
vmstat 1 5 每一秒查看一次系统状态 查看5次
[[email protected] ~]# vmstat 1 5
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 0 705696 2076 157288 0 0 2 0 27 41 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 28 39 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 32 42 0 0 100 0 0
1 0 0 705672 2076 157288 0 0 0 0 28 38 0 0 100 0 0
0 0 0 705672 2076 157288 0 0 0 0 32 40 0 1 99 0 0
关键的几例:r,b,swpd,si,so ,bi,bo,us,wa
r(run)表示有多少进程处于运行状态,当有多个进程,只有一个cpu 那么久要排队使用,一个时间点只允许一个进程运行
b(block)有多少个进程在等待
swpd表示当内存不够使,系统可以拿出内存中的一部分数据放到swpd交换分区去,如果swpd值一直变换,说明交换分区和内存在频繁的交换数据,代表内存不够用
si表示有多少k的数据块 从swpd进入到内存 so有多少K的数据块 从内存进入到swapbi表示有多少k的数据从磁盘进入到内存 bo有多少数据从内存写到磁盘
us用户级别的,表示用户的资源占用cpu百分比, 如果数字大于50 说明系统资源不够
sy系统本身的一些进程 服务占用资源百分比
id表示空闲 us+sy+wa=100
wa(wait)表示有多少进程等待cpu百分比 如果这一列数字很大 s说明cpu不够用
top查看进程使用资源情况
top 3秒显示一次
[[email protected] ~]# top
top - 16:13:51 up 19:25, 1 user, load average: 0.01, 0.03, 0.05
Tasks: 98 total, 2 running, 96 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1005628 total, 704576 free, 140996 used, 160056 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 692600 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11 root rt 0 0 0 0 S 0.3 0.0 0:01.64 watchdog/0
5515 root 20 0 301020 6560 5112 S 0.3 0.7 3:23.00 vmtoolsd
6372 root 20 0 158760 5596 4252 S 0.3 0.6 0:01.04 sshd
6978 root 20 0 161880 2184 1568 R 0.3 0.2 0:00.17 top
1 root 20 0 128020 6564 4136 S 0.0 0.7 0:02.70 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.03 ksoftirqd/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:06.67 kworker/u128: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:02.79 rcu_sched
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
上面第一列 和w命令第一行相同
第二列: 有多少个任务 ,多少个正在运行的进程,有多少休眠的进程 ,多少个停止的进程,多少个僵尸进程
第三行:cpu百分比 us数值越大说明负载越高
第四行:表示物理内存 第五行;表示交换内存 下面部分按照cpu百分比排序,使用最多排在前面
RES 物理内存大小 单位是k字节 如果想按照内存排序,按大写M。 按cpu排序按大写P 按数字1 列出所有cpu使用率 再按一次可以切换
退出 按q PID进程号,可以使用杀死进程,kil+pid号杀死进程
top –c显示详细的进程信息 全局路径
[[email protected] ~]# top -c
top - 16:33:43 up 19:45, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 98 total, 1 running, 97 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1005628 total, 704444 free, 141120 used, 160064 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 692468 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5515 root 20 0 301020 6560 5112 S 0.7 0.7 3:26.33 /usr/bin/vmtoolsd
6987 root 20 0 161908 2280 1652 R 0.3 0.2 0:00.02 top -c
1 root 20 0 128020 6564 4136 S 0.0 0.7 0:02.70 /usr/lib/systemd/systemd --switched-root --system --+
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 [kthreadd]
3 root 20 0 0 0 0 S 0.0 0.0 0:01.12 [ksoftirqd/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:06.81 [kworker/u128: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:02.84 [rcu_sched]
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [lru-add-drain]
11 root rt 0 0 0 0 S 0.0 0.0 0:01.67 [watchdog/0]
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kdevtmpfs]
14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [netns]
top –bn1静态显示所有进程
[[email protected] ~]# top -bn1
top - 16:35:18 up 19:47, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 98 total, 1 running, 97 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 : 1005628 total, 704584 free, 140992 used, 160052 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 692612 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 128020 6564 4136 S 0.0 0.7 0:02.70 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.12 ksoftirqd/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:06.82 kworker/u128: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:02.84 rcu_sched
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
11 root rt 0 0 0 0 S 0.0 0.0 0:01.67 watchdog/0
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
15 root 20 0 0 0 0 S 0.0 0.0 0:00.04 khungtaskd
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 edac-poller
24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 watchdogd
30 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kswapd0
31 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
32 root 39 19 0 0 0 S 0.0 0.0 0:00.70 khugepaged
33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
41 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld
42 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kworker/u128:1
43 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kmpath_rdacd
44 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kaluad
45 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kpsmoused
sar命令
安装sar命令
#yum install -y sysstat
sar命令如果不加具体选项,默认会调用系统李保留的一个历史文件
,在/var/log/sa目录下,sar每个十分钟会把系统的状态过滤一遍,保存在目录文件里
sar –n DEV 查看网卡流量 和vmastat类似,表示每隔1面显示一次 显示10次
[[email protected] ~]# sar -n DEV 1 10
Linux 3.10.0-957.el7.x86_64 (qklinux-01) 2019年04月14日 _x86_64_ (1 CPU)
16时44分09秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
16时44分10秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
16时44分10秒 ens33 2.00 1.00 0.12 0.18 0.00 0.00 0.00
16时44分10秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
16时44分11秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
16时44分11秒 ens33 1.01 1.01 0.06 0.40 0.00 0.00 0.00
第一列显示的是时间
第二列显示的是网卡名字
第三列rxpck/s表示接收到的数据包,单位个数,数据包几千正常 上万了不正常
第四列txpck/s发出去的数据包 第五列rxkB/接收的数据量,单位KB 第六列txkB/S发送的数据量
查看一天的历史数据 目录下数据最多保留一个月 17代表当天的日期
#sar -n DEV -f /var/log/sa/sa17
sar –q查看系统负载
[[email protected] ~]# sar -q 1 10
Linux 3.10.0-957.el7.x86_64 (qklinux-01) 2019年04月14日 _x86_64_ (1 CPU)
16时55分29秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
16时55分30秒 1 117 0.00 0.01 0.05 0
16时55分31秒 1 117 0.00 0.01 0.05 0
16时55分32秒 2 117 0.00 0.01 0.05 0
查看其它时间的负载
#sar -q -f /var/log/sa/sa06
sar –b查看磁盘读写
[[email protected] ~]# sar -b 1 5
Linux 3.10.0-957.el7.x86_64 (qklinux-01) 2019年04月14日 _x86_64_ (1 CPU)
16时59分26秒 tps rtps wtps bread/s bwrtn/s
16时59分27秒 0.00 0.00 0.00 0.00 0.00
16时59分28秒 0.00 0.00 0.00 0.00 0.00
16时59分29秒 0.00 0.00 0.00 0.00 0.00
nload命令
安装命令# yum install -y nload
nload命令动态的显示网卡实时速度
第一行会显示网卡名字 ip 显示其中一个网卡 按方向键向右可以切换其他网卡 按q退出 incoming 表示进来的带宽 Outgoing出去的带宽
监控io性能
iostat在安装sysstat是已将安装
[[email protected] ~]# iostat
Linux 3.10.0-957.el7.x86_64 (qklinux-01) 2019年04月14日 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.08 0.00 0.16 0.01 0.00 99.75
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
scd0 0.00 0.01 0.00 1028 0
sda 0.19 3.13 1.29 228221 93902
sdb 0.00 0.06 0.00 4336 0
dm-0 0.00 0.01 0.00 1036 0
iostat –x 磁盘使用
[[email protected] ~]# iostat -x
Linux 3.10.0-957.el7.x86_64 (qklinux-01) 2019年04月14日 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.08 0.00 0.16 0.01 0.00 99.75
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
scd0 0.00 0.00 0.00 0.00 0.01 0.00 114.22 0.00 1.67 1.67 0.00 1.33 0.00
主要看%util 主要表示磁盘使用百分比,意思是磁盘使用有多少时间占用cpu 如果数字很大 说明磁盘繁忙 读写很定也很大,如果读写不大,说明磁盘有问题
iotop磁盘使用 也是动态显示
安装命令# yum install -y 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
2560 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [xfs-log/sda3]
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/u128:0]
7 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0]
8 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh]
9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched]
free命令
free查看内存使用情况
[[email protected] ~]# free
total used free shared buff/cache available
Mem: 1005628 141804 526728 7628 337096 675136
Swap: 2097148 0 2097148
第一行是说明
第二行是内存使用情况
第三行是swap使用情况
第一列:total内存总大小 单位是kb 也可以使用free –m free–h加上具体单位
第二列:used内存已用大小
第三列free内存剩余大小
第四列shared共享大小
第五列buff/cache 缓冲/缓存 linux系统中会有一部分空间给buff/cache
第六列available 是free剩余加上buff/cache剩余的
公式:total=used+free+buff/cache
ps命令
ps查看系统进程
用法:ps aux(ps -elf)静态的把当前系统使用 一次性的列出所有进程
[[email protected] ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.6 128164 6688 ? Ss 4月13 0:03 /usr/lib/systemd/systemd --switched-root --system --des
root 2 0.0 0.0 0 0 ? S 4月13 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 4月13 0:01 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 4月13 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 4月13 0:07 [kworker/u128:0]
root 7 0.0 0.0 0 0 ? S 4月13 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 4月13 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R 4月13 0:03 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 4月13 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 4月13 0:01 [watchdog/0]
root 13 0.0 0.0 0 0 ? S 4月13 0:00 [kdevtmpfs]
root 14 0.0 0.0 0 0 ? S< 4月13 0:00 [netns]
root 15 0.0 0.0 0 0 ? S 4月13 0:00 [khungtaskd]
root 16 0.0 0.0 0 0 ? S< 4月13 0:00 [writeback]
第一列是用户 kil pid杀死进程
STAT部分说明
D不能中断的进程
R run状态的进程
S sleep状态的进程
T 暂停的进程
Z僵尸进程
<高级优先进程
N低优先进程
L内存中被锁了内存分页
s 主进程
|多线程进程
+前台进程
查看网络状态
netstat查看网络状态tcpip的状态
netstat –lnp 查看监听端口
[[email protected] ~]# 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:53 0.0.0.0:* LISTEN 6083/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6085/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6247/master
tcp6 0 0 :::53 :::* LISTEN 6083/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 6085/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6247/master
udp 0 0 0.0.0.0:53 0.0.0.0:* 6083/dnsmasq
udp 0 0 127.0.0.1:323 0.0.0.0:* 5544/chronyd
udp6 0 0 :::53 :::* 6083/dnsmasq
udp6 0 0 ::1:323 :::* 5544/chronyd
raw6 0 0 :::58 :::* 7 5604/NetworkManager
netstat –an 查看系统的网络连接状况
[[email protected] ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 52 192.168.18.138:22 192.168.18.1:64807 ESTABLISHED
tcp6 0 0 :::53 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
udp 0 0 0.0.0.0:53 0.0.0.0:*
udp 0 0 127.0.0.1:323 0.0.0.0:*
udp6 0 0 :::53 :::*
udp6 0 0 ::1:323 :::*
raw6 0 0 :::58 :::* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 19742 /run/systemd/shutdownd
unix 2 [ ] DGRAM 31533 /var/run/chrony/chronyd.sock
unix 2 [ ACC ] STREAM LISTENING 19285 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 35545 private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 35534 public/pickup
unix 2 [ ACC ] STREAM LISTENING 35548 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 35538 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 31872 /var/run/vmware/guestServicePipe
unix 2 [ ACC ] STREAM LISTENING 35551 private/bounce
netstat –lntp 只查看tcp的 不包含socket
[[email protected] ~]# 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:53 0.0.0.0:* LISTEN 6083/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6085/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6247/master
tcp6 0 0 :::53 :::* LISTEN 6083/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 6085/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6247/master
同时查看tcp和udp端口
[[email protected] ~]# netstat -ltunp
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:53 0.0.0.0:* LISTEN 6083/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6085/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6247/master
tcp6 0 0 :::53 :::* LISTEN 6083/dnsmasq
tcp6 0 0 :::22 :::* LISTEN 6085/sshd
tcp6 0 0 ::1:25 :::* LISTEN 6247/master
udp 0 0 0.0.0.0:53 0.0.0.0:* 6083/dnsmasq
udp 0 0 127.0.0.1:323 0.0.0.0:* 5544/chronyd
udp6 0 0 :::53 :::* 6083/dnsmasq
udp6 0 0 ::1:323 :::* 5544/chronyd
查看所有状态数字
#netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
LISTEN 6
ESTABLISHED 1
如果ESTABLISHED数值很大 说明系统很繁忙
ss –an 和netstat一样
查看listen 不会显示进程名
[[email protected] ~]# ss -an |grep -i listen
u_str LISTEN 0 128 /run/systemd/private 19285 * 0
u_str LISTEN 0 100 private/tlsmgr 35545 * 0
u_str LISTEN 0 100 public/pickup 35534 * 0
u_str LISTEN 0 100 private/rewrite 35548 * 0
u_str LISTEN 0 100 public/cleanup 35538 * 0
u_str LISTEN 0 32 /var/run/vmware/guestServicePipe 31872 * 0
u_str LISTEN 0 100 private/bounce 35551 * 0
u_str LISTEN 0 100 public/qmgr 35541 * 0
u_str LISTEN 0 100 public/flush 35563 * 0
u_str LISTEN 0 100 private/defer 35554 * 0
u_str LISTEN 0 100 public/showq 35578 * 0
u_str LISTEN 0 100 private/trace 35557 * 0
u_str LISTEN 0 100 private/verify 35560 * 0
linux下抓包
tcpdump抓包工具
安装# yum install -y tcpdump
常用的命令选项
tcpdump –nn
tcpdump -nn -i 网卡名字
tcpdump –nn port 80 指定端口
#tcpdump -nn not port and host ip地址
不要22端口且只要这个ip的包
#tcpdump -nn -c 100 -w 1.cap
指定100个数据包并存放到1.cap
[[email protected] ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
10 packets captured
11 packets received by filter
0 packets dropped by kernel
查看1.cap
[[email protected] ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap
tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
10 packets captured
11 packets received by filter
0 packets dropped by kernel
使用tcpdump –r/tmp/1.cap查看
[[email protected] ~]# tcpdump -r /tmp/1.cap
reading from file /tmp/1.cap, link-type EN10MB (Ethernet)
19:01:19.575761 IP qklinux-01.ssh > 192.168.18.1.64807: Flags [P.], seq 4292631954:4292632102, ack 2161090727, win 294, length 148
19:01:19.576163 IP 192.168.18.1.64807 > qklinux-01.ssh: Flags [.], ack 148, win 2050, length 0
19:01:26.132377 IP 192.168.18.1.64807 > qklinux-01.ssh: Flags [P.], seq 1:85, ack 148, win 2050, length 84
19:01:26.172695 IP qklinux-01.ssh > 192.168.18.1.64807: Flags [.], ack 85, win 294, length 0
19:01:32.067075 IP 192.168.18.1.64807 > qklinux-01.ssh: Flags [P.], seq 85:169, ack 148, win 2050, length 84
19:01:32.067688 IP qklinux-01.ssh > 192.168.18.1.64807: Flags [.], ack 169, win 294, length 0
tshark命令
安装 # yum -y install wireshark
使用tshark 查看指定网卡端口的web访问情况
tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.requrst.method" -e "http.request.uri"
linux网络相关
ifconfig查看网卡ip
yum install net-tools 安装
[[email protected] ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.18.138 netmask 255.255.255.0 broadcast 192.168.18.255
inet6 fe80::7d86:46ee:b26a:62e4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:00:0e:e4 txqueuelen 1000 (Ethernet)
RX packets 79285 bytes 34391994 (32.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122903 bytes 32370680 (30.8 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 32 bytes 2592 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 2592 (2.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifconfig –a 这个命令是当网卡down掉的时候,一般不会显示 加上-a全部显示
ifup ens33/ifdown ens33 启用或关闭网卡,一般在对网卡进行更更改时使用
[[email protected] ~]# ifdown ens33 && ifup ens33
成功断开设备 'ens33'。
连接已成功**(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
**设定虚拟网卡
-
在网卡配置文件目录里复制ens33配置文件**
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls
ifcfg-ens33 ifdown-Team ifup-post
ifcfg-lo ifdown-TeamPort ifup-ppp
ifdown ifdown-tunnel ifup-routes
ifdown-bnep ifup ifup-sit
ifdown-eth ifup-aliases ifup-Team
ifdown-ippp ifup-bnep ifup-TeamPort
ifdown-ipv6 ifup-eth ifup-tunnel
ifdown-isdn ifup-ippp ifup-wireless
ifdown-post ifup-ipv6 init.ipv6-global
ifdown-ppp ifup-isdn network-functions
ifdown-routes ifup-plip network-functions-ipv6
ifdown-sit ifup-plusb
[[email protected] network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
编辑虚拟网卡配置文件
[[email protected] network-scripts]# vi !$
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33:0
UUID=2222136d-6fbd-4a14-bd1e-16e378907700
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.18.141
NETMASK=255.255.255.0
断掉重新连接 查看网卡
[[email protected] network-scripts]# ifdown ens33 && ifup ens33
成功断开设备 'ens33'。
连接已成功**(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/3)
[[email protected] network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.18.138 netmask 255.255.255.0 broadcast 192.168.18.255
inet6 fe80::7d86:46ee:b26a:62e4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:00:0e:e4 txqueuelen 1000 (Ethernet)
RX packets 79863 bytes 34441097 (32.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 123241 bytes 32411660 (30.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.18.141 netmask 255.255.255.0 broadcast 192.168.18.255
ether 00:0c:29:00:0e:e4 txqueuelen 1000 (Ethernet)
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 32 bytes 2592 (2.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32 bytes 2592 (2.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
mii-tool ens33查看网卡是否链接
[[email protected] ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok
ethtool ens33也可以查看网卡连接
[[email protected] ~]# 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
更改主机名
hostnamectl set-hostname
DSN配置文件/etc/resolv.conf 可以临时的编辑这个文件 重启网卡会被覆盖
[[email protected] ~]# cat /etc/resolv.conf
#Generated by NetworkManager
nameserver 119.29.29.29
/etc/hosts文件
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
如果我们ping一个域名 比如qq 会解析出公网ip,如果我们在hosts文件利配置此域名,就会解析到我们配置的ip上
[[email protected] ~]# ping www.qq.com
PING https.qq.com (123.151.137.18) 56(84) bytes of data.
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=1 ttl=128 time=25.5 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=2 ttl=128 time=129 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=3 ttl=128 time=26.7 ms
[email protected] ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.18.141 www.qq.com
[[email protected] ~]# ping www.qq.com
PING www.qq.com (192.168.18.141) 56(84) bytes of data.
64 bytes from www.qq.com (192.168.18.141): icmp_seq=1 ttl=64 time=0.158 ms
64 bytes from www.qq.com (192.168.18.141): icmp_seq=2 ttl=64 time=0.251 ms
配置只在本机生效 支持一个ip配多个域名
一个域名只有一个Ip生效
直播扩展
tcp三次握手和四次挥手
http://www.doc88.com/p-9913773324388.html
ip命令使用
1. 设置和删除IP
ip addr add 192.168.10.10/24 dev eth0
ip addr show eth0
ip addr del 192.168.10.10/24 dev eth0
2. 路由相关设置
ip route show
ip route add default via 192.168.10.1
ip route add 192.168.5.0/24 dev eth0
ip route del 192.168.10.1
用route命令来管理路由:
(a)、网络路由
route add -net 192.168.1.0/24 gw 172.16.1.106
(b)、主机路由
route add -host 192.168.1.110 gw 172.16.1.106
(c)、默认路由
route add default gw 172.16.1.106
或
route add -net 0.0.0.0 gw 172.16.1.106
(d)、删除路由
route del -host 192.168.1.110
route del -net 192.168.1.0/24
3. 显示网络统计数据
ip -s link
ip -s -s link ls eth0
3. 停止开启网卡
ip link set eth0 down
ip linke set eth0 up
更改网卡名字
ip link set ens37 name eth1