13款Linux運(yùn)維比較實(shí)用的工具
本文介紹幾款Linux運(yùn)維比較實(shí)用的工具,希望對Linux管理員有所幫助。
1、查看進(jìn)程占用帶寬情況-Nethogs
Nethogs 是一個(gè)終端下的網(wǎng)絡(luò)流量監(jiān)控工具可以直觀的顯示每個(gè)進(jìn)程占用的帶寬。
下載:http://sourceforge.net/projects/nethogs/files/nethogs/0.8/nethogs-0.8.0.tar.gz/download
- [root@localhost ~]#yum-y install libpcap-develncurses-devel
- [root@localhost ~]# tar zxvf nethogs-0.8.0.tar.gz
- [root@localhost ~]# cd nethogs
- [root@localhost nethogs]# make && make install
- [root@localhost nethogs]# nethogs eth0
2、硬盤讀取性能測試-IOZone
IOZone是一款Linux文件系統(tǒng)性能測試工具 可以測試不同的操作系統(tǒng)中文件系統(tǒng)的讀寫性能。
下載:http://www.iozone.org/src/current/
- [root@localhost current]# tar xvf iozone3_420.tar
- [root@localhost ~]# cd iozone3_420/src/current/
- [root@localhost current]# make linux
- [root@localhost current]# ./iozone -a -n 512m -g 16g -i 0 -i 1 -i 5 -f /mnt/iozone -Rb ./iozone.xls
- -a使用全自動(dòng)模式
- -n為自動(dòng)模式設(shè)置最小文件大小(Kbytes)。
- -g設(shè)置自動(dòng)模式可使用的最大文件大小Kbytes。
- -i用來指定運(yùn)行哪個(gè)測試。
- -f指定測試文件的名字完成后自動(dòng)刪除
- -R產(chǎn)生Excel到標(biāo)準(zhǔn)輸出
- -b指定輸出到指定文件上
3、實(shí)時(shí)監(jiān)控磁盤IO-IOTop
IOTop命令是專門顯示硬盤IO的命令,界面風(fēng)格類似top命令。
- [root@localhost ~]# yum -y install iotop
4、網(wǎng)絡(luò)流量監(jiān)控-IPtrafIPtraf是一個(gè)運(yùn)行在Linux下的簡單的網(wǎng)絡(luò)狀況分析工具。
- [root@localhost ~]# yum -y install iptraf
5、網(wǎng)絡(luò)流量監(jiān)控-IFTop
iftop是類似于linux下面top的實(shí)時(shí)流量監(jiān)控工具。比iptraf直觀些。
下載:http://www.ex-parrot.com/~pdw/iftop/
- [root@localhost ~]# tar zxvf iftop-0.17.tar.gz [root@localhost ~]# cd iftop-0.17 [root@localhost iftop-0.17]# ./configure [root@localhost iftop-0.17]# make && make install [root@localhost iftop-0.17]# iftop [root@localhost iftop-0.17]# iftop -i eth0#指定監(jiān)控網(wǎng)卡接口
- TX:發(fā)送流量
- RX:接收流量
- TOTAL:總流量
- Cumm:運(yùn)行iftop到目前時(shí)間的總流量
- peak:流量峰值
- rates:分別表示過去 2s 10s 40s 的平均流量
6、進(jìn)程實(shí)時(shí)監(jiān)控-HTop
HTop是一個(gè) Linux 下的交互式的進(jìn)程瀏覽器可以用來替換Linux下的top命令。
- rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm(安裝第三方Y(jié)UM源)
- [root@localhost ~]# yum -y install htop
7、系統(tǒng)資源監(jiān)控-NMON
NMON是一種在AIX與各種Linux操作系統(tǒng)上廣泛使用的監(jiān)控與分析工具
下載:
- http://sourceforge.jp/projects/sfnet_nmon/releases/
- [root@localhost ~]# chmod +x nmon_x86_64_rhel6
- [root@localhost ~]# mv nmon_x86_64_rhel6 /usr/sbin/nmon [root@localhost ~]# nmon
8、監(jiān)控多個(gè)日志-MultiTail
MultiTail是在控制臺打開多個(gè)窗口用來實(shí)現(xiàn)同時(shí)監(jiān)控多個(gè)日志文檔、類似tail命令的功能的軟件。
- rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm (安裝第三方Y(jié)UM源)
- [root@localhost ~]# yum -y installmultitail [root@localhost ~]# multitail -e "fail" /var/log/secure #篩選關(guān)鍵字進(jìn)行監(jiān)控 [root@localhost ~]# multitail -l "ping baidu.com" #監(jiān)控后面的命令-l將要執(zhí)行的命令 [root@localhost ~]# multitail -i /var/log/messages -i /var/log/secure #-i指定一個(gè)文件名
9、SSH暴力破解防護(hù)-Fail2ban
Fail2ban可以監(jiān)視你的系統(tǒng)日志然后匹配日志的錯(cuò)誤信息正則式匹配執(zhí)行相應(yīng)的屏蔽動(dòng)作一般情況下是調(diào)用防火墻屏蔽
下載:http://www.fail2ban.org/wiki/index.php/Downloads
- [root@localhost ~]# cd fail2ban-0.8.11
- [root@localhost fail2ban-0.8.11]# python setup.py install
- [root@localhost fail2ban-0.8.11]# cd files/
- [root@localhost files]# cp ./redhat-initd /etc/init.d/fail2ban [root@localhost files]# service fail2ban start
- [root@localhost files]# chkconfig --add fail2ban
- [root@localhost files]# chkconfig fail2ban on
注:需要配置iptables實(shí)用,如果重啟iptables了也要重啟fail2ban,因?yàn)閒ail2ban的原理是調(diào)用iptables實(shí)時(shí)阻擋外界的攻擊。
- [root@localhost ~]# grep -v "^#" /etc/fail2ban/jail.conf | grep -v "^$"
- [DEFAULT] ignoreip = 127.0.0.1/8
- #忽略本機(jī)IP bantime= 600
- #符合規(guī)則后封鎖時(shí)間 findtime= 600
- #在多長時(shí)間內(nèi)符合規(guī)則執(zhí)行封鎖如600秒達(dá)到3次則執(zhí)行 maxretry =
- #最大嘗試次數(shù) backend = auto
- #日志修改檢測日志gamin、polling和auto這三種 usedns = warn [ssh-iptables] enabled= true
- #默認(rèn)是禁用false filter = sshd action = iptables[name=SSH, port=ssh, protocol=tcp]
- # sendmail-whois[name=SSH,dest=收件人郵箱, sender=發(fā)件人郵箱, sendername="Fail2Ban"] logpath= /var/log/sshd.log
- #響應(yīng)的錯(cuò)誤日志一般在/var/log/secure maxretry = 5
- #嘗試錯(cuò)誤次數(shù)覆蓋全局中的maxretry
注:默認(rèn)所有的應(yīng)用防護(hù)都是關(guān)閉的,需要我們手動(dòng)開啟。fail2ban.conf文件是日志信息,jail.conf文件是保護(hù)的具體服務(wù)和動(dòng)作配置信息。
- [root@localhost ~]# touch /var/log/sshd.log
- [root@localhost ~]# service fail2ban restart
- [root@localhost ~]# fail2ban-client status#查看監(jiān)控已經(jīng)開啟
- Status
- |- Number of jail:1
- `- Jail list: ssh-iptables
- [root@localhost ~]# iptables -L iptables過濾表有fail2ban一條規(guī)則
- fail2ban-SSHtcp--anywhere anywheretcp dpt:ssh
10、連接會話終端持續(xù)化-Tmux
Tmux是一個(gè)優(yōu)秀的終端復(fù)用軟件類似GNU Screen比Screen更加方面、靈活和高效。為了確保連接SSH時(shí)掉線不影響任務(wù)運(yùn)行。
- rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm(安裝第三方Y(jié)UM源)
11、頁面顯示磁盤空間使用情況-Agedu
下載:http://www.chiark.greenend.org.uk/~sgtatham/agedu/
- [root@localhost ~]# tar zxvf agedu-r9723.tar.gz
- [root@localhost ~]# cd agedu-r9723
- [root@localhost ~]# ./configure
- [root@localhost ~]# make && make install
- [root@localhost ~]# agedu -s /#-s掃描
- [root@localhost ~]# agedu -w --address 192.168.0.10:80#-w輸入一個(gè)網(wǎng)頁鏈接
- [root@localhost ~]# agedu -w --address 192.168.0.108080 --auth none#--auth關(guān)閉認(rèn)證如果不加端口號會生成一個(gè)隨機(jī)的用瀏覽器訪問
12、安全掃描工具-NMap
NMap是Linux下的網(wǎng)絡(luò)連接掃描和嗅探工具包用來掃描網(wǎng)上電腦開放的網(wǎng)絡(luò)連接端。
下載:http://nmap.org/download.html
- [root@localhost ~]# tar jxvf nmap-6.40.tar.bz2
- [root@localhost nmap-6.40]# ./configure
- [root@localhost nmap-6.40]# make && make install
- [root@localhost ~]# nmap 192.168.0.10 #獲取基本信息
- [root@localhost ~]# nmap -O 192.168.0.10 #獲取系統(tǒng)版本信息
- [root@localhost ~]# nmap -A 192.168.0.10 #獲取系統(tǒng)綜合信息
- [root@localhost ~]# nmap 192.168.0.0/24#獲取一個(gè)網(wǎng)段工作設(shè)備基本信息
- -sSTCP掃描
- -sV系統(tǒng)版本檢測
13、Web壓力測試-Httperf
Httperf比ab更強(qiáng)大,能測試出web服務(wù)能承載的最大服務(wù)量及發(fā)現(xiàn)潛在問題;比如:內(nèi)存使用、穩(wěn)定性。最大優(yōu)勢:可以指定規(guī)律進(jìn)行壓力測試,模擬真實(shí)環(huán)境。
下載:http://code.google.com/p/httperf/downloads/list
- [root@localhost ~]# tar zxvf httperf-0.9.0.tar.gz
- [root@localhost ~]# cd httperf-0.9.0
- [root@localhost httperf-0.9.0]# ./configure
- [root@localhost httperf-0.9.0]# make && make install
- [root@localhost ~]# httperf --hog --server=192.168.0.202 --uri=/index.html --num-conns= 10000 --wsess=10,10,0.1