Centos下安裝Mrtg配置的步驟詳解

來源:互聯網
上載者:User


以下是筆記:

1、檢查系統是否安裝了mrtg軟體
# rpm -qa | grep mrtg*

安裝mrtg軟體
# yum -y install mrtg*

2、mrtg設定檔(以下是mrtg設定檔內容是詳細說明)
提供我們鵬飛微服務的設定檔給大家下載參考:http://url.cn/PT118T [檔案名稱自己設定]

# vi /etc/mrtg/mrtg.cfg
以下是配置內容解釋:
HtmlDir:/var/www/mrtg   //html存放目錄
ImageDir:/var/www/mrtg  //圖片產生存放目錄
LogDir:/var/www/mrtg      //日誌存放目錄
ThreshDir:/var/lib/mrtg

##監視eth1網卡(串連公網的),其他監控和這個類似
Target[eth1_lan]:/192.168.1.68:public@localhost:      //mrtg使用snmp協議,通過public鑰匙來監控localhost伺服器的點/介面(192.168.1.68)上的流量
Options[eth1_lan]:growright  //圖片靠右對齊
Directory[eth1_lan]:eth1                      //此網卡統計圖片存放的目錄;存放產生的流量統計圖片
Maxbytes[eth1_lan]: 100000000           //網卡最大值,多少位元組
Kmg[eth1_lan]:K,M,G  //Y軸上的單位,k,m,g
YLegend[eth1_lan]:Bytes per Second        //Y軸標題
ShortLegend[eth1_lan]:B/s                        //Y軸單位大小

#以下是網頁裡面的小標題;在網頁最下方
Legend1[eth1_lan]:每秒流入量(單位Bytes)
Legend2[eth1_lan]:每秒流出量(單位Bytes)
LegendI[eth1_lan]:流入              //入input 標記顏色
LegendO[eth1_lan]:流出             //出out 標記顏色
Title[eth1_lan]:eth1 網路流量[流入+流出]            //網頁標題
PageTop[eth1_lan]:<h1>eth1 網路流量[流入+流出]</h1>    //子頁面H1,必須要<h1></h1>標籤,否則無法產生首頁

##監視CPU負載[使用者+閑置],和上面的類似
Target[cpuload]:.1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:public@localhost:      //mrtg使用snmp協議,通過public鑰匙來監控localhost伺服器的點/介面(cpu負載率和空閑率)
Options[cpuload]:nopercent,growright  //圖片靠右對齊
Directory[cpuload]:cpu    //統計圖片存放的目錄
Maxbytes[cpuload]: 100           //CPU最大值
YLegend[cpuload]:CPU Utilization        //Y軸標題
ShortLegend[cpuload]:%                        //Y軸單位大小

#以下是網頁裡面的小標題;在網頁最下方
Legend1[cpuload]:CPU使用者負載(%)
Legend2[cpuload]:CPU閑置(%)
LegendI[cpuload]:使用者        //標記顏色
LegendO[cpuload]:閑置        //標記顏色
Title[cpuload]:CPU負載[使用者+閑置]            //網頁標題
PageTop[cpuload]:<h1>CPU負載[使用者+閑置]</h1>   //子頁面H1標籤,必須要<h1></h1>標籤,否則無法產生首頁

##監視記憶體使用量量[Mem+Swap]
Target[memory]: .1.3.6.1.2.1.25.2.3.1.6.2&.1.3.6.1.2.1.25.23.1.6.3:public@localhost:
Options[memory]:gauge,growright
Directory[memory]:mem
MaxBytes1[memory]:255412    //記憶體最大值,這裡的值必須是  free -k 裡面獲得的最大值,如下圖
MaxBytes2[memory]:524280    //swap最大值,這裡的值必須是  free -k 裡面獲得的最大值,如下圖
Kmg[memory]:K,M,G
Kilo[memory]:1024
Unscaled[memory]:dwym
YLegend[memory]:Men Bytes
ShortLegend[memory]:B
Legend1[memory]:已用Men(Bytes)
Legend2[memory]:已用Swap(Bytes)
LegendI[memory]:已用Mem:
LegendO[memory]:已用Swap:
Title[memory]:記憶體使用量量[Mem+Swap]
PageTop[memory]:記憶體使用量量[Mem+Swap]


##監視硬碟空間[系統硬碟+資料盤]
Target[disk]: .1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.2:public@localhost:
Options[disk]:gauge,growright
Directory[disk]:disk
MaxBytes1[disk]:19679908
MaxBytes2[disk]:101086
Kmg[disk]:K,M,G
Kilo[disk]:1024
Unscaled[disk]:dwym
YLegend[disk]:Disk Bytes
ShortLegend[disk]:B
Legend1[disk]:系統硬碟已用空間
Legend2[disk]:資料盤已用空間
LegendI[disk]:系統已用:
LegendO[disk]:資料已用:
Title[disk]:硬碟空間[系統硬碟+資料盤]
PageTop[disk]:<h1>硬碟空間[系統硬碟+資料盤]</h1>

用mrtg產生監控圖片
# /usr/bin/mrtg   /etc/mrtg/mrtg.cfg      //載入這個設定檔;
會出現錯誤
在執行三次
# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
即可,除非你的mrtg.cfg有語法錯誤;執行一次就產生一次圖片

設定crontab自動執行指令碼:
/etc/cron/ 下面指令碼會被cron自動執行,會執行裡面的任務計劃
在這裡mrtg自動產生了一個mrtg檔案計劃任務檔案,在裡面寫設定任務計劃
vi /etc/cron.d/mrtg
裡面已經設定好了任務計劃,把5分鐘一次,改成2分鐘一次
*/2 * * * *
連續執行三次的過程中,這個命令也在這個檔案裡面獲得,root 後面的命令。
產生的網頁有亂碼,是因為編碼不支援中文。需要修改產生的原始碼來設定產生的網頁代碼,或者每次觀看自己設定瀏覽器編碼為UTF-8;
如何修改原始碼
# vi /usr/bin/mrtg
找到
<meta http-equiv="content-type" content="text/html; charset='.&$LOC('iso-8859-1') . "\" />\n";
替換成
<meta http-equiv="content-type" content="text/html; charset='.&$LOC('utf-8') . "\" />\n";
產生的子頁面不會是亂碼了

產生監控首頁檔案
用indexmaker產生mrtg監控首頁檔案;執行後立刻產生
# indexmaker --output /var/www/mrtg/index.html --title="鵬飛微服務伺服器監控" /etc/mrtg/mrtg.cfg
首頁預設不支援中文,需要修改產生源碼
# vi /usr/bin/indexmaker
找到
<meta http-equiv="content-type" content="text/html; charset= iso-8859-15 " >
替換成
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
然後在產生,就沒亂碼了


設定apach或者nginx配置,設定可以通過網站訪問,方法各異。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.