700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Linux日常运维管理技巧(一)监控系统状态 监控网卡流量 监控IO性能 查看系统进程

Linux日常运维管理技巧(一)监控系统状态 监控网卡流量 监控IO性能 查看系统进程

时间:2020-04-30 11:54:40

相关推荐

Linux日常运维管理技巧(一)监控系统状态 监控网卡流量 监控IO性能 查看系统进程

目录

监控系统状态

监控网卡流量

监控IO性能

查看系统进程

查看网络状态

Linux下抓包

Linux网络相关

监控系统状态

w/uptime查看系统负载

[root@zyshanlinux-01 ~]# w##当前系统时间,启动至今时间,目前登录用户数,系统负载:1分钟,5分钟,15分钟内系统负载是多少(单位时间内cpu使用的活动进程有多少个,不一定是整数,平均值)12:08:10 up 44 min, 2 users, load average: 0.06, 0.04, 0.05USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot tty1 11:47 20:58 0.03s 0.03s -bash ##本地登录的用户root pts/0 192.168.106.1 11:34 2.00s 0.05s 0.02s w ##远程登录的用户##登录的是谁,登录的终端(从网络远程登录来的就是pts/0,从本地登录就是tty1),从哪里登录来的(远程就是ip),用户登录的时间点,空闲了多少时间,使用CPU的时间,命令。[root@zyshanlinux-01 ~]# date 06月 10日 星期日 11:41:41 CST​[root@zyshanlinux-01 ~]# uptime ##和w命令是一样的。12:08:27 up 45 min, 2 users, load average: 0.04, 0.04, 0.05​##当系统中只有一个逻辑CPU的时候,load average: 0.00, 0.01, 0.05中在1分钟的时候数值为1是最理想的,不闲也没压力,即每个逻辑CPU有一个进程在占用它。第2、3个数值分别体现在5分钟和15分钟内逻辑CPU中进程占有量;1分钟的是最能体现当前系统的负载量的参数。

cat /proc/cpuinfo查看cpu核数

[root@zyshanlinux-01 ~]# cat /proc/cpuinfo ##查看系统有多少个逻辑CPUprocessor : 0 ##数字0代表有1颗逻辑CPU,数字1代表2颗逻辑CPU。vendor_id : GenuineIntelcpu family : 6model : 60model name : Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHzstepping : 3microcode : 0x22cpu MHz: 2393.631cache size : 6144 KBphysical id : 0siblings : 1core id: 0cpu cores : 1apicid: 0initial apicid : 0fpu: yesfpu_exception : yescpuid level : 13wp: yesflags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm epb fsgsbase smep xsaveopt dtherm ida arat pln ptsbogomips : 4788.92clflush size : 64cache_alignment : 64address sizes : 40 bits physical, 48 bits virtualpower management:

vmstat监控系统状态

[root@zyshanlinux-01 ~]# vmstatprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st2 0 0 1580752 2076 163592 0 0 1232 50 301 608 3 7 82 9 0

用法vmstat 1

[root@zyshanlinux-01 ~]# vmstat 1 ##动态每秒显示一次procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r b swpd free buff cache si so bi bo in cs us sy id wa st2 0 0 1580768 2076 163664 0 0 1094 45 281 555 2 6 84 8 00 0 0 1580752 2076 163664 0 0 0 0 111 130 0 0 100 0 00 0 0 1580752 2076 163664 0 0 0 0 100 123 0 0 100 0 00 0 0 1580752 2076 163664 0 0 0 0 80 107 0 1 99 0 0

关键的几列: r , b , swpd , si , so , bi , bo , us , wa

参数解析:

注:系统负载很高,us%可以很低或0(可能在等待或者不运行);us%很高,系统负载肯定会很高。

top查看进程使用资源情况

[root@zyshanlinux-01 ~]# toptop - 17:07:16 up 5:43, 2 users, load average: 0.00, 0.01, 0.05Tasks: 88 total, 2 running, 86 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 ##st被偷走的CPUKiB Mem : 1875480 total, 1542804 free, 145232 used, 187444 buff/cacheKiB Swap: 2097148 total, 2097148 free,0 used. 1545540 avail Mem ​PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND1 root 20 0 128208 6844 4084 S 0.0 0.4 0:01.77 systemd2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd3 root 20 0 0 0 0 S 0.0 0.0 0:00.24 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:02.64 kworker/u128:0

PID号可以通过命令来杀死对应PID号的进程。

参数解析:

top -c显示详细的进程信息

top -bn1静态显示所有进程,适合写脚本的时候用

q退出,数字1显示所有核cpu,大写字母M按内存使用排序

大写字母P按cpu使用排序

监控网卡流量

yum install -y sysstat

[root@zyshanlinux-01 ~]# sar ##没有这个命令,就需要安装一个包-bash: sar: 未找到命令[root@zyshanlinux-01 ~]# yum install -y sysstat已加载插件:fastestmirrorbase | 3.6 kB 00:00:00

[root@zyshanlinux-01 ~]# sar ##sar不加具体的选项或参数,它就会去调用它的历史文件无法打开 /var/log/sa/sa10: 没有那个文件或目录 ##sar特性,每次正点10分钟去抓取系统状态保存在该目录的文件里

sar -n DEV 网卡流量

[root@zyshanlinux-01 ~]# sar -n DEV 2 3 ##每隔2秒显示一次,仅显示3次Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)##时间网卡名字 接收数据包 发送数据包 接收数据量 发送数据量17时45分33秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s17时45分35秒lo 0.00 0.00 0.00 0.00 0.00 0.00 0.0017时45分35秒 ens33 0.50 0.50 0.03 0.10 0.00 0.00 0.00​17时45分35秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s17时45分37秒lo 0.00 0.00 0.00 0.00 0.00 0.00 0.0017时45分37秒 ens33 0.51 0.51 0.03 0.20 0.00 0.00 0.00​17时45分37秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s17时45分39秒lo 0.00 0.00 0.00 0.00 0.00 0.00 0.0017时45分39秒 ens33 0.51 0.51 0.03 0.20 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 0.50 0.50 0.03 0.17 0.00 0.00 0.00

注:接收数据包几千算是正常,上万或几十万的话就不正常,被攻击了。可以通过抓包工具验证是否被攻击。

[root@zyshanlinux-01 ~]# sarLinux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)​17时40分01秒 CPU %user %nice %system %iowait %steal %idle17时50分01秒 all 0.03 0.00 0.11 0.00 0.00 99.8618时00分01秒 all 0.03 0.00 0.10 0.00 0.00 99.8618时10分01秒 all 0.04 0.00 0.13 0.00 0.00 99.82

sar -f /var/log/sa/saxx 历史文件

[root@zyshanlinux-01 ~]# ls /var/log/sa/sa10​[root@zyshanlinux-01 ~]# sar -n DEV -f /var/log/sa/sa10Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)​17时40分01秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s17时50分01秒lo 0.00 0.00 0.00 0.00 0.00 0.00 0.0017时50分01秒 ens33 0.22 0.04 0.01 0.01 0.00 0.00 0.00

注:当天/var/log/sa/里面不仅有一个sa10的文件还有sar10的文件,但只有到明天这个文件才会出现,两者有什么区别呢,sa10是二进制文件不能用cat直接看只能用sar -n DEV查看,sar10可以用cat直接查看。

sar -q 系统负载

[root@zyshanlinux-01 ~]# sar -q 1 3 ##每秒显示1次,仅显示3次Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)​23时17分11秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked23时17分12秒0 105 0.02 0.07 0.05023时17分13秒0 105 0.02 0.07 0.05023时17分14秒0 105 0.02 0.07 0.050平均时间:0 105 0.02 0.07 0.050

sar -b 磁盘读写

[root@zyshanlinux-01 ~]# sar -b 1 3 ##每秒显示1次,仅显示3次Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)​23时18分37秒 tps rtps wtps bread/s bwrtn/s23时18分38秒 0.00 0.00 0.00 0.00 0.0023时18分39秒 0.00 0.00 0.00 0.00 0.0023时18分40秒 0.00 0.00 0.00 0.00 0.00平均时间: 0.00 0.00 0.00 0.00 0.00

nload命令

第一次用这个命令,会出现没有命令的错误,需要安装2个包才可以执行这个命令

yum install -y epel -release

yum install -y nload

[root@zyshanlinux-01 ~]# nload​Device ens33 [192.168.106.128] (1/2):===========================================================================================================Incoming: ##进来的流量,被攻击的话,这个流量就会变得很大​​​​​​Curr: 944.00 Bit/sAvg: 1.05 kBit/sMin: 944.00 Bit/sMax: 1.87 kBit/sTtl: 7.73 MByteOutgoing: ##出去的流量,买了100的带宽跑到70多了还是正常,跑满的就证明带宽不够了​​​​​Curr: 8.29 kBit/sAvg: 8.30 kBit/sMin: 4.27 kBit/sMax: 8.78 kBit/sTtl: 3.33 MByte

监控IO性能

iostat -x 磁盘使用

iostat和sar是同一个安装包的,都是sysstat,安装了这个包后,2个命令都可以用了。

[root@zyshanlinux-01 ~]# iostat -x 1 1 ##每秒显示1次,仅显示1次Linux 3.10.0-693.el7.x86_64 (zyshanlinux-01) 06月10日_x86_64_ (1 CPU)​avg-cpu: %user %nice %system %iowait %steal %idle0.08 0.00 0.18 0.06 0.00 99.67​Device:rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util ##%util重点参数,CPU等待IO硬盘时间的百分比,越大硬盘越差,硬盘太慢。这个参数和硬盘的读写参数是相关联的,这个百分比大读写数据也大,如果读写几乎为0,这个百分比仍然很大,硬盘异常sdb 0.00 0.00 0.01 0.00 0.10 0.00 28.99 0.00 2.75 2.75 0.00 2.05 0.00sda 0.00 0.01 0.16 0.09 6.86 3.25 80.63 0.02 74.62 14.22 177.01 11.07 0.28scd0 0.00 0.00 0.00 0.00 0.03 0.00 114.22 0.00 0.83 0.83 0.00 0.72 0.00dm-0 0.00 0.00 0.00 0.00 0.03 0.00 48.19 0.00 6.42 6.42 0.00 5.63 0.00

iotop 磁盘使用,查看占用磁盘最高的是哪个进程

[root@zyshanlinux-01 ~]# iotop ##命令没有,需要安装下面的包才可以执行这个命令-bash: iotop: 未找到命令[root@zyshanlinux-01 ~]# yum install -y iotop​[root@zyshanlinux-01 ~]# iotop​Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/sActual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/sTID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 1 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root~system --deserialize 212 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]3 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]5 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H]7 rt/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0]8 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh]9 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched]10 rt/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [watchdog/0]12 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kdevtmpfs]13 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [netns]14 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [khungtaskd]15 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [writeback]16 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kintegrityd]17 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [bioset]18 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kblockd]19 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [md]25 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kswapd0]26 be/5 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksmd]27 be/7 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [khugepaged]28 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [crypto]547 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd-logind36 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthrotld]549 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % VGAuthService -s550 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % vmtoolsd39 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kpsmoused]41 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [ipv6_addrconf]557 be/4 chrony 0.00 B/s 0.00 B/s 0.00 % 0.00 % chronyd564 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % rsyslogd -n [in:imjournal]565 be/4 root0.00 B/s 0.00 B/s 0.00 % 0.00 % rsyslogd -n [rs:main Q:Reg]566 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [kdmflush]567 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [bioset]60 be/0 root0.00 B/s 0.00 B/s 0.00 % 0.00 % [deferwq]522 be/3 root0.00 B/s 0.00 B/s 0.00 % 0.00 % auditd

free查看内存使用情况

[root@zyshanlinux-01 ~]# freetotalusedfree shared buff/cache availableMem:1875480 145684 13636248800 366172 1537304Swap: 20971480 2097148

free -m / -g / -h

[root@zyshanlinux-01 ~]# free -mtotalusedfree shared buff/cache availableMem:1831142133183571501Swap:204702047[root@zyshanlinux-01 ~]# free -htotalusedfree shared buff/cache availableMem:1.8G142M1.3G8.6M357M1.5GSwap:2.0G0B2.0G[root@zyshanlinux-01 ~]# free -gtotalusedfree shared buff/cache availableMem: 101001Swap: 101

buffer/cache区别

缓冲/缓存,cpu运算速度快,磁盘很慢,所以需要内存进行缓冲,以下就是数据不同流向的区别[root@zyshanlinux-01 ~]# 0000(磁盘)-->内存(cache)-->cpu^C[root@zyshanlinux-01 ~]# cpu(00000) -->内存(buffer)--> 磁盘 ^C

公式:total=used+free+buff/cache

availabel(真正的剩余物理内存)包含free和buffer/cache剩余部分

查看系统进程

ps查看系统进程

把你当前进程的快照打印出来,ps是一次性静态的把系统进程列出来,top则是实时动态的。

用法:ps aux、ps -elf

[root@zyshanlinux-01 ~]# ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot1 0.1 0.3 128208 6844 ?Ss 23:08 0:01 /usr/lib/systemd/systemd --switched-root -root2 0.0 0.0 0 0 ?S 23:08 0:00 [kthreadd]root3 0.0 0.0 0 0 ?S 23:08 0:00 [ksoftirqd/0]root4 0.2 0.0 0 0 ?S 23:08 0:01 [kworker/0:0]root5 0.0 0.0 0 0 ?S< 23:08 0:00 [kworker/0:0H]root6 0.0 0.0 0 0 ?S 23:08 0:00 [kworker/u128:0]root7 0.0 0.0 0 0 ?S 23:08 0:00 [migration/0]​[root@zyshanlinux-01 ~]# ps -elfF S UIDPID PPID C PRI NI ADDR SZ WCHAN STIME TTYTIME CMD4 S root1 0 0 80 0 - 32052 ep_pol 23:08 ?00:00:01 /usr/lib/systemd/systemd --switc1 S root2 0 0 80 0 - 0 kthrea 23:08 ?00:00:00 [kthreadd]1 S root3 2 0 80 0 - 0 smpboo 23:08 ?00:00:00 [ksoftirqd/0]1 S root4 2 0 80 0 - 0 worker 23:08 ?00:00:01 [kworker/0:0]1 S root5 2 0 60 -20 - 0 worker 23:08 ?00:00:00 [kworker/0:0H]

[root@zyshanlinux-01 ~]# ps aux |grep mysql ##查看该进程是否在运行root 1298 0.0 0.0 112720 972 pts/0 R+ 23:22 0:00 grep --color=auto mysql[root@zyshanlinux-01 ~]# kill 1132 ##用PID号可以杀死该进程[root@zyshanlinux-01 ~]# ps aux |grep qmgr ##确认该进程确实是被杀死postfix 1157 0.0 0.2 89756 4048 ?S 23:08 0:00 qmgr -l -t unix -uroot 1300 0.0 0.0 112720 972 pts/0 R+ 23:23 0:00 grep --color=auto qmgr

[root@zyshanlinux-01 ~]# ls -l /proc/521/ ##proc加上数字的文件夹就是进程的PID号总用量 0dr-xr-xr-x. 2 root root 0 6月 10 23:08 attr-rw-r--r--. 1 root root 0 6月 10 23:23 autogroup-r--------. 1 root root 0 6月 10 23:23 auxv

STAT部分说明

D 不能中断的进程

R run状态的进程

S sleep状态的进程

[root@zyshanlinux-01 ~]# ps aux |grep vmstatroot 1307 0.0 0.0 148356 1352 pts/0 S+ 23:27 0:00 vmstat 1root 1309 0.0 0.0 112720 972 pts/1 R+ 23:27 0:00 grep --color=auto vmstat

T 暂停的进程

[root@zyshanlinux-01 ~]# ps aux |grep vmstatroot 1307 0.0 0.0 148356 1352 pts/0 T 23:27 0:00 vmstat 1root 1311 0.0 0.0 112720 968 pts/1 R+ 23:27 0:00 grep --color=auto vmstat

Z僵尸进程

数量较少,有就用命令杀死它。

< 高优先级进程

N 低优先级进程

L 内存中被锁了内存分页

s主进程

l 多线程进程

+ 前台进程,都是在终端中显示

[root@zyshanlinux-01 ~]# ps aux |grep vmstatroot 1307 0.0 0.0 148356 1352 pts/0 S+ 23:27 0:00 vmstat 1root 1313 0.0 0.0 112720 968 pts/1 R+ 23:28 0:00 grep --color=auto vmstat

查看网络状态

netstat 查看网络状态

netstat -lnp 查看监听端口

[root@zyshanlinux-01 ~]# netstat -lnpActive Internet connections (only servers)Proto Recv-Q Send-Q Local AddressForeign AddressState PID/Program name tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN 912/sshdtcp0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1130/mastertcp6 0 0 :::22:::* LISTEN 912/sshdtcp6 0 0 ::1:25:::* LISTEN 1130/masterudp0 0 127.0.0.1:3230.0.0.0:* 557/chronydudp6 0 0 ::1:323 :::* 557/chronydraw6 0 0 :::58:::* 7610/NetworkManager Active UNIX domain sockets (only servers)Proto RefCnt Flags Type StateI-Node PID/Program name Path

netstat -an 查看系统tcp的网络连接状况

[root@zyshanlinux-01 ~]# netstat -anActive Internet connections (servers and established)Proto Recv-Q Send-Q Local AddressForeign AddressState tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp0 52 192.168.106.128:22 192.168.106.1:14605 ESTABLISHEDtcp6 0 0 :::22:::* LISTEN tcp6 0 0 ::1:25:::* LISTEN udp0 0 127.0.0.1:3230.0.0.0:* udp6 0 0 ::1:323 :::*raw6 0 0 :::58:::* 7Active UNIX domain sockets (servers and established)Proto RefCnt Flags Type StateI-Node Pathunix 2 [ ACC ] STREAM LISTENING 15871 /var/run/vmware/guestServicePipeunix 2 [ ACC ] STREAM LISTENING 18867 private/proxymap

nestat -lntp 只看出tcp的,不包含socket

unix 2 [ ACC ] STREAM LISTENING 11901 1/systemd /run/lvm/lvmpolld.socketunix 2 [ ACC ] STREAM LISTENING 11915 1/systemd /run/lvm/lvmetad.socket

[root@zyshanlinux-01 ~]# netstat -ltnpActive Internet connections (only servers)Proto Recv-Q Send-Q Local AddressForeign AddressState PID/Program name tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN 912/sshdtcp0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1130/mastertcp6 0 0 :::22:::* LISTEN 912/sshdtcp6 0 0 ::1:25:::* LISTEN 1130/master[root@zyshanlinux-01 ~]# netstat -ltunpActive Internet connections (only servers)Proto Recv-Q Send-Q Local AddressForeign AddressState PID/Program name tcp0 0 0.0.0.0:22 0.0.0.0:* LISTEN 912/sshdtcp0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1130/mastertcp6 0 0 :::22:::* LISTEN 912/sshdtcp6 0 0 ::1:25:::* LISTEN 1130/masterudp0 0 127.0.0.1:3230.0.0.0:* 557/chronydudp6 0 0 ::1:323 :::*

ss -an 和nestat 异曲同工,不足是不会显示进程的名字

[root@zyshanlinux-01 ~]# ss -an |grep -i listenu_str LISTEN 0 32 /var/run/vmware/guestServicePipe 15871 * 0 u_str LISTEN 0 100 private/proxymap 18867 * 0 u_str LISTEN 0 100 private/proxywrite 18870 * 0 u_seq LISTEN 0 128 /run/udev/control 12110 * 0 u_str LISTEN 0 128 /run/systemd/private 11855 * 0 u_str LISTEN 0 128 /var/run/dbus/system_bus_socket 14716 * 0 u_str LISTEN 0 128 /run/lvm/lvmpolld.socket 11901 * 0 u_str LISTEN 0 128 /run/lvm/lvmetad.socket 11915 * 0 u_str LISTEN 0 100 public/pickup 18835 * 0 u_str LISTEN 0 100 public/cleanup 18839 * 0 u_str LISTEN 0 100 public/qmgr 18842 * 0 u_str LISTEN 0 100 public/flush 18864 * 0 u_str LISTEN 0 100 public/showq 18879 * 0 u_str LISTEN 0 100 private/smtp 18873 * 0 u_str LISTEN 0 100 private/tlsmgr 18846 * 0 u_str LISTEN 0 100 private/rewrite 18849 * 0 u_str LISTEN 0 100 private/bounce 18852 * 0 u_str LISTEN 0 100 private/defer 18855 * 0 u_str LISTEN 0 100 private/trace 18858 * 0 u_str LISTEN 0 100 private/verify 18861 * 0 u_str LISTEN 0 100 private/relay 18876 * 0 u_str LISTEN 0 100 private/error 18882 * 0 u_str LISTEN 0 100 private/retry 18885 * 0 u_str LISTEN 0 100 private/discard 18888 * 0 u_str LISTEN 0 100 private/local 18891 * 0 u_str LISTEN 0 100 private/virtual 18894 * 0 u_str LISTEN 0 100 private/lmtp 18897 * 0 u_str LISTEN 0 100 private/anvil 18900 * 0 u_str LISTEN 0 100 private/scache 18903 * 0 u_str LISTEN 0 128 /run/systemd/journal/stdout 7665* 0 tcp LISTEN 0 128 *:22 *:* tcp LISTEN 0 100 127.0.0.1:25 *:* tcp LISTEN 0 128 :::22:::* tcp LISTEN 0 100 ::1:25:::*

一个小技巧:直接查看以下数据的并发量。

netstat -an |awk '/^tcp/{++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'

[root@zyshanlinux-01 ~]# netstat -an |awk '/^tcp/{++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'LISTEN 4ESTABLISHED1

Linux下抓包

抓包工具tcpdump

[root@zyshanlinux-01 ~]# yum install -y tcpdump ##第一次运行这个命令要安装这个包

用法:tcpdump -nn

tcpdump -nn -i ens33

[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 ##特殊的设备需要加上网卡名08:41:31.158670 IP 192.168.106.1.1512 > 192.168.106.128.22: Flags [.], ack 802176, win 2048, length 008:41:31.158683 IP 192.168.106.128.22 > 192.168.106.1.1512: Flags [P.], seq 802356:802536, ack 157, win 251, length 180##得出的结果都是数据包的流向,成对出现,还要关注一个重要参数length 180,长度参数。有种攻击是DDos,即udp flood洪水攻击,可以发出几百G流量攻击,只能用防攻击的设备或服务。

tcpdump -nn port 80

[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 port 22 ##指定22端口的[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 not port 22 ##排除22端口的

tcpdump -nn not port 22 and host 192.168.0.100

[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 not port 22 and host 192.168.106.1 ##排除22端口,只要192.168.106.1 ip的

tcpdump -nn -c 100 -w 1.cap

[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 -c 10 ##只抓前10条​[root@zyshanlinux-01 ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap ##抓10个包写入1.cap里面,单开一个终端时这条命令可能会卡住,因为没有数据流动,所以没产生包,命令就卡住,可以重新开个终端运行写top或vmstat 1的命令产生些包,这条命令就会很快完成抓包任务。tcpdump: listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes10 packets captured10 packets received by filter0 packets dropped by kerne​[root@zyshanlinux-01 ~]# file /tmp/1.cap ##可以用file查看/tmp/1.cap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144)[root@zyshanlinux-01 ~]# cat /tmp/1.cap ##因为是抓的数据包,包的内容,cat你是看不懂得​[root@zyshanlinux-01 ~]# tcpdump -r /tmp/1.cap ##可以用-r来看,就是读数据流;但实际上1.cap中是真真正正得写入数据包reading from file /tmp/1.cap, link-type EN10MB (Ethernet)08:59:45.166244 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 3728788926:3728789074, ack 2081729664, win 251, length 14808:59:45.166661 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 148, win 2047, length 008:59:51.222568 IP 192.168.106.1.49249 > 239.255.255.250.ssdp: UDP, length 12908:59:51.323252 IP 192.168.106.1.49249 > 239.255.255.250.ssdp: UDP, length 12908:59:52.388207 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [P.], seq 1:53, ack 148, win 2047, length 5208:59:52.388769 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 148:200, ack 53, win 251, length 5208:59:52.430645 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 200, win 2053, length 008:59:52.508157 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [P.], seq 53:105, ack 200, win 2053, length 5208:59:52.508666 IP zyshanlinux-01.ssh > 192.168.106.1.wins: Flags [P.], seq 200:252, ack 105, win 251, length 5208:59:52.549433 IP 192.168.106.1.wins > zyshanlinux-01.ssh: Flags [.], ack 252, win 2052, length 0

yum install -y wireshark

[root@zyshanlinux-01 ~]# yum install -y wireshark ##第1次运行该命令需要安装

tshark -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"

[root@zyshanlinux-01 ~]# tshark -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" ##需要线上的系统才能抓到,tshark: -R without -2 is deprecated. For single-pass filtering use -Y.Running as user "root" and group "root". This could be dangerous.Capturing on 'nflog'^C0 packets captured

Linux网络相关

ifconfig 查看网卡ip(yum install net-tools)

[root@zyshanlinux-01 ~]# ifconfig -a ##加-a选项,如果网卡宕机或者没有ip的时候是不显示的。

ifup ens33/ifdown ens33 启动或关闭ens33网卡,关闭网卡终端就会断开,需要到本地再次启动才行。应用场景:当某个网卡需要更改配置,就要重启服务,但又不想重启所有的网卡时,就可以用该命令指定网卡重启。

如果你的机房在国外,你单独执行关闭网卡命令,你就要去国外重启网卡;这时你就应该关闭和重启服务一起执行。

[root@zyshanlinux-01 ~]# ifdown ens33 && ifup ens33成功断开设备 'ens33'。连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33成功断开设备 'ens33'。连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)

设定虚拟网卡ens33:1

[root@zyshanlinux-01 ~]# cd /etc/sysconfig/network-scripts/[root@zyshanlinux-01 network-scripts]# lsifcfg-ens33 ifdown-ippp ifdown-routes ifupifup-ipv6 ifup-ppp ifup-tunnelifcfg-lo ifdown-ipv6 ifdown-sit ifup-aliases ifup-isdn ifup-routes ifup-wirelessifdown ifdown-isdn ifdown-Team ifup-bnep ifup-plip ifup-sit init.ipv6-globalifdown-bnep ifdown-post ifdown-TeamPort ifup-eth ifup-plusb ifup-Team network-functionsifdown-eth ifdown-ppp ifdown-tunnel ifup-ippp ifup-post ifup-TeamPort network-functions-ipv6[root@zyshanlinux-01 network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0[root@zyshanlinux-01 network-scripts]# vi !$vi ifcfg-ens33\:0[root@zyshanlinux-01 network-scripts]# ifdown ens33;ifup ens33成功断开设备 'ens33'。连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/8)[root@zyshanlinux-01 network-scripts]# ifconfig ##多出新的虚拟网卡ens33:0:ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.106.128 netmask 255.255.255.0 broadcast 192.168.106.255inet6 fe80::8fc3:bbdf:ba89:22a7 prefixlen 64 scopeid 0x20<link>ether 00:0c:29:a1:d4:eb txqueuelen 1000 (Ethernet)RX packets 54409 bytes 25525816 (24.3 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 209646 bytes 52121081 (49.7 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0​ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.106.150 netmask 255.255.255.0 broadcast 192.168.106.255ether 00:0c:29:a1:d4:eb txqueuelen 1000 (Ethernet)​lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

mii-tool ens33 查看网卡是否连接

[root@zyshanlinux-01 network-scripts]# mii-tool ens33ens33: negotiated 1000baseT-FD flow-control, link ok ##ok正常连接网线

ethtool ens33 也可以查看网卡是否连接

[root@zyshanlinux-01 network-scripts]# ethtool ens33Settings for ens33:Supported ports: [ TP ]Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: NoSupports auto-negotiation: YesAdvertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: NoAdvertised auto-negotiation: YesSpeed: 1000Mb/sDuplex: FullPort: Twisted PairPHYAD: 0Transceiver: internalAuto-negotiation: onMDI-X: off (auto)Supports Wake-on: dWake-on: dCurrent message level: 0x00000007 (7)drv probe linkLink detected: yes ##yes正常连接网线

更改主机名 hostnamectl set-hostname aminglinux

[root@zyshanlinux-01 ~]# hostnamectl set-hostname zyshanlinux-001 [root@zyshanlinux-01 ~]# hostname ##更改主机名需要退出再重新登录,或者用hostname命令查看zyshanlinux-001[root@zyshanlinux-01 ~]# bash ##用子shell也可查看[root@zyshanlinux-001 ~]# exitexit[root@zyshanlinux-01 ~]# cat /etc/hostname ##主机名的配置文件zyshanlinux-001

DNS配置文件/etc/resolv.conf

[root@zyshanlinux-01 ~]# cat /etc/resolv.conf ##查看DNS# Generated by NetworkManagernameserver 119.29.29.29[root@zyshanlinux-01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 ##网卡的配置文件##增加谷歌的DNS2=8.8.8.8[root@zyshanlinux-01 ~]# ifdown ens33;ifup ens33成功断开设备 'ens33'。连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/9)[root@zyshanlinux-01 ~]# cat /etc/resolv.conf# Generated by NetworkManagernameserver 119.29.29.29nameserver 8.8.8.8 ##可以看到新增的DNS[root@zyshanlinux-01 ~]# vim /etc/resolv.conf ##可以临时更改DNS,但重启后会被网卡的DNS配置文件覆盖

/etc/hosts文件

[root@zyshanlinux-01 ~]# cat /etc/hosts ##查看配置文件127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1localhost localhost.localdomain localhost6 localhost6.localdomain6[root@zyshanlinux-01 ~]# ping ##公网IPPING (140.206.160.207) 56(84) bytes of data.64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=1 ttl=128 time=54.0 ms64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=2 ttl=128 time=115 ms64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=3 ttl=128 time=109 ms64 bytes from 211.155.235.108 (211.155.235.108): icmp_seq=4 ttl=128 time=51.3 ms^C--- ping statistics ---4 packets transmitted, 4 received, 0% packet loss, time 3007msrtt min/avg/max/mdev = 51.387/82.591/115.483/29.951 ms[root@zyshanlinux-01 ~]# vi /etc/hosts ##可以指定自定义IP,多个域名指向一个IP空格隔开,多个IP指向一个域名只执行最后一个IP,以行为单位,不能换行。127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.106.150 127.0.0.1 ​[root@zyshanlinux-01 ~]# ping PING (192.168.106.150) 56(84) bytes of data.64 bytes from (192.168.106.150): icmp_seq=1 ttl=64 time=0.084 ms64 bytes from (192.168.106.150): icmp_seq=2 ttl=64 time=0.102 ms64 bytes from (192.168.106.150): icmp_seq=3 ttl=64 time=0.105 ms64 bytes from (192.168.106.150): icmp_seq=4 ttl=64 time=0.104 ms64 bytes from (192.168.106.150): icmp_seq=5 ttl=64 time=0.102 ms^C--- ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4000msrtt min/avg/max/mdev = 0.084/0.099/0.105/0.011 ms[root@zyshanlinux-01 ~]# ping ##只执行最后一个IPPING (127.0.0.1) 56(84) bytes of data.64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.044 ms64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.098 ms64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.097 ms^C--- ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2000msrtt min/avg/max/mdev = 0.044/0.079/0.098/0.027 ms

在window下不生效,只在linux本机下才能生效

C:\Users\zhengyushan>ping ​正在 Ping [211.155.235.108] 具有 32 字节的数据:来自 211.155.235.108 的回复: 字节=32 时间=49ms TTL=226来自 211.155.235.108 的回复: 字节=32 时间=57ms TTL=226来自 211.155.235.108 的回复: 字节=32 时间=55ms TTL=226来自 211.155.235.108 的回复: 字节=32 时间=54ms TTL=226​211.155.235.108 的 Ping 统计信息:数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位):最短 = 49ms,最长 = 57ms,平均 = 53ms​C:\Users\zhengyushan>'' 不是内部或外部命令,也不是可运行的程序或批处理文件。

拓展阅读:

tcp三次握手四次挥手(重点) /p-9913773324388.html

tshark几个用法 /question/995

延伸阅读 :

TCP 三次握手和四次挥手/qq_25677349/article/details/80468409

TCP 之三次握手和四次挥手/s?id=1600656878316112806&wfr=spider&for=pc

TCP、UDP以及HTTP的简单讲解/xiohao/p/4439164.html

认识cpu、核、进程与线程——备忘篇/zhengyshan/article/details/80641770

Linux日常运维管理技巧(一)监控系统状态 监控网卡流量 监控IO性能 查看系统进程 查看网络状态 Linux下抓包tcpdump Linux网络相关 DNS配置

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。