擴充:
tcp三次握手四次揮手
<a href="http://www.doc88.com/p-9913773324388.html">http://www.doc88.com/p-9913773324388.html</a>
tshark幾個用法:
<a href="http://www.aminglinux.com/bbs/thread-995-1-1.html">http://www.aminglinux.com/bbs/thread-995-1-1.html</a>
10.6 監控io性能
安裝iostat指令(也是安裝這個包) :
[root@hao-01 ~]# yum install -y sysstat
1. (監控)檢視 磁盤io使用情況:iostat -x
重要關注:%util 值 表示io磁盤使用多少占用cpu的!
[root@hao-01 ~]# iostat -x
[root@hao-01 ~]# iostat -x 1
2. 安裝iotop指令 :
[root@hao-01 ~]# yum install -y iotop
3. (監控)檢視 程序使用磁盤io百分比(哪個程序使用磁盤比較大) :iotop
重要關注:IO> 下的值(數值越大,排名越前)
[root@hao-01 ~]# iotop
10.7 free指令
1. 檢視内容使用情況(預設機關:kb):free
[root@hao-01 ~]# free
2. 檢視内容使用情況(指定機關:mb):free -m
[root@hao-01 ~]# free -m
3. 檢視内容使用情況(直覺機關):free -h
[root@hao-01 ~]# free -h
Mem(記憶體使用):total used free shared buff/cache
total(記憶體總大小)
used(使用記憶體)
free(剩餘記憶體)
shared(共享記憶體)
buff/cache(緩沖/緩存)
磁盤讀出來的資料——經過記憶體(cache緩存)——到CPU處理
CPU處理完的資料——經過記憶體(buffer緩沖)——放到磁盤裡
公式:total=used+free+buff/cache
avaliable包含free和buff/cache剩餘部分
Swap(交換分區):如果Swap不足了,需要考慮增加記憶體了(或者是記憶體洩漏程式有bug需要排查了)!
10.8 ps指令
1. 檢視系統目前所有程序:ps -elf
列出系統目前所有程序 :ps aux
[root@hao-01 ~]# ps aux
USER(運作使用者名稱)
PID(程序id号)
%CPU(使用cpu百分比)
%MEM(使用磁盤百分比)
STAT部分說明:
D 不能中斷的程序
R run狀态的程序(某一個時間段内使用cpu的)
S sleep狀态的程序(自動停止暫停,自動激活啟動的)
T 暫停的程序(Ctrl c 的程序)
Z 僵屍程序(系統比較多僵屍程序,需要殺死)
< 高優先級程序
N 低優先級程序
L 記憶體中被鎖了記憶體分頁(極少見)
s 主程序
l 多線程程序
+ 前台程序
2. 檢視指定程序是否運作: ps aux |grep 指定程序名稱
[root@hao-01 ~]# ps aux |grep mysql
[root@hao-01 ~]# ps aux |grep nginx
3. 殺死指定程序(不要随意殺死程序哦):
[root@hao-01 ~]# kill 程序Pid
ps aux |grep ps aux
4. 檢視程序是在哪個檔案啟動的 :ls -l /proc/程序Pdi/
[root@hao-01 ~]# ls -l /proc/3406/
10.9 檢視網絡狀态
1. 檢視網絡狀态: netstat
[root@hao-01 ~]# netstat
2. 檢視監聽端口 :netstat -lnp
[root@hao-01 ~]# netstat -lnp
3. 隻檢視tcp的監聽端口(不包含socket):
[root@hao-01 ~]# netstat -lntp
4. 檢視tcp和udp的監聽端口(不包含socket):
[root@hao-01 ~]# netstat -lntup
5. 檢視系統的網絡連接配接狀态(無法顯示程序名字):ss -an
檢視系統的網絡連接配接狀态:netstat -an
[root@hao-01 ~]# netstat -an
tcp三次握手四次揮手(重要,需了解,面試可能會問到)
6. 檢視所有狀态的數字:
[root@hao-01 ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
ESTABLISHED:用戶端和服務端在通信數量(1000以内都是正常的)
10.10 Linux下抓包
1. 安裝tcpdump抓包指令:
[root@hao-01 ~]# yum install -y tcpdump
2. 抓包: tcpdump -nn -i 網卡名稱
[root@hao-01 ~]# tcpdump -nn -i ens33
原本地ip位址原端口号 >到 資料包ip 資料包ip端口
3. 抓包 指定端口:tcpdump -nn -i 網卡名稱 port 端口号
[root@hao-01 ~]# tcpdump -nn -i ens33 port 22
4. 抓包 排除指定端口:tcpdump -nn -i 網卡名稱 ont port 端口号
[root@hao-01 ~]# tcpdump -nn -i ens33 not port 22
5. 抓包 排除指定端口,并指定ip的資料包:
tcpdump -nn -i 網卡名稱 ont port 端口号 and host 指定ip
[root@hao-01 ~]# tcpdump -nn -i ens33 not port 22 and host 192.168.47.1
6. 指定抓包數量,并儲存到指定檔案内:
tcpdump -nn -i 網卡名稱 -c 抓包數量 -w 存放檔案位址
[root@hao-01 ~]# tcpdump -nn -i ens33 -c 10 -w /tmp/1.cap
7. 安裝tshark抓包指令:
[root@hao-01 ~]# yum install -y wireshark
8. tshark 檢視指定網卡,80端口的通路情況:
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"
本文轉自 主内安詳 51CTO部落格,原文連結:http://blog.51cto.com/zhuneianxiang/2064312,如需轉載請自行聯系原作者