技術(shù)員聯(lián)盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機(jī)純凈版,64位旗艦版,綠色軟件,免費(fèi)軟件下載基地!

當(dāng)前位置:主頁 > 教程 > 服務(wù)器類 >

Linux系統(tǒng)上安裝MRTG來監(jiān)控網(wǎng)絡(luò)流量

來源:技術(shù)員聯(lián)盟┆發(fā)布時(shí)間:2018-02-26 12:19┆點(diǎn)擊:

  Multi Router Traffic Grapher------MRTG是一個(gè)監(jiān)控網(wǎng)絡(luò)鏈路流量負(fù)載的工具軟件,通過snmp協(xié)議得到設(shè)備的流量信息,并將流量負(fù)載以包含PNG格式的圖形的HTML 文檔方式顯示給用戶,以非常直觀的形式顯示流量負(fù)載。

  SNMP(imple Network Management Protocol,簡單網(wǎng)絡(luò)管理協(xié)議)的前身是簡單網(wǎng)關(guān)監(jiān)控協(xié)議(SGMP),用來對(duì)通信線路進(jìn)行管理。隨后,人們對(duì)SGMP進(jìn)行了很大的修改,特別是加入了符合Internet定義的SMI和MIB:體系結(jié)構(gòu),改進(jìn)后的協(xié)議就是著名的SNMP。SNMP的目標(biāo)是管理互聯(lián)網(wǎng)Internet上眾多廠家生產(chǎn)的軟硬件平臺(tái),因此SNMP受Internet標(biāo)準(zhǔn)網(wǎng)絡(luò)管理框架的影響也很大?,F(xiàn)在SNMP已經(jīng)出到第三個(gè)版本的協(xié)議,其功能較以前已經(jīng)大大地加強(qiáng)和改進(jìn)了。

20151027120411784.png (643×602)

  下面來看一下其在Linux系統(tǒng)上的安裝方法:

  (1)必須安裝snmp

  復(fù)制代碼

  代碼如下:

  rpm -qa|grep snmp* //查看是否安裝了snmp

  yum -y install snmp* //安裝snmp

  #vim /etc/snmp/snmpd.conf

  rocommunity public //配置snmpv1模式

  disk / 13102744 //配置系統(tǒng)的大小

  disk /data 41279536 //配置數(shù)據(jù)盤的大小

  service snmpd start //配置開啟snmp

  chkconfig snmpd on //設(shè)置開機(jī)啟動(dòng)

  (2) 安裝mrtg

  復(fù)制代碼

  代碼如下:

  yum -y install mrtg*

  (3)配置mrtg

  復(fù)制代碼

  代碼如下:

  //配置就是一個(gè)模板,大家只要把IP修改成自己的 內(nèi)存修改成自己的大小就可以了 我是在本地測試的

  HtmlDir: /data/wwwroot/mrtg //這里是你網(wǎng)站的html地址 默認(rèn)為 /var/www/mrtg

  ImageDir: /data/wwwroot/mrtg //這里是存放地址 默認(rèn)為 /var/www/mrtg

  LogDir: /var/lib/mrtg

  ThreshDir: /var/lib/mrtg

  #

  #[網(wǎng)絡(luò)流入流出圖]

  #

  Target[eth0_lan]: /118.244.182.176:public@localhost

  Options[eth0_lan]:growright

  Language:utf8

  Directory[eth0_lan]:eth1

  MaxBytes[eth0_lan]: 5000000

  Title[eth0_lan]: eht0流入流出圖

  Kmg[eth0_lan]:K,M,G

  YLegend[eth0_lan]:Bytes per Second

  ShortLegend[eth0_lan]:B/s

  Legend1[eth0_lan]:每秒流入量

  legend2[eth0_lan]:每秒流出量

  legendI[eth0_lan]:流入

  legendO[eth0_lan]:流出

  PageTop[eth0_lan]:

  網(wǎng)卡流入流程圖

  PageFoot[eth0_lan]:jb51 Inc

  #

  #[CPU的負(fù)載]

  #

  Target[cpuload]:.1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:public@localhost:

  Options[cpuload]:nopercent,growright

  Language:utf8

  Directory[cpuload]:cpu

  MaxBytes[cpuload]:100

  Unscaled[cpuload]:dwym

  Ylegend[cpuload]:CPU Utilization

  Shortlegend[cpuload]:%

  legend1[cpuload]:CPU用戶負(fù)載(%)

  legend2[cpuload]:CPU閑置(%)

  legendI[cpuload]:用戶

  legendO[cpuload]:閑置

  Title[cpuload]:CPU負(fù)載

  PageTop[cpuload]:

  Cpu負(fù)載【用戶+閑置】

  PageFoot[cpuload]:jb51 Inc

  #

  #[內(nèi)存使用]

  #

  Target[memory]:.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@localhost:

  Options[memory]:gauge,growright

  Directory[memory]:mem

  Language:utf8

  MaxBytes1[memory]:514908

  MaxBytes2[memory]:2096472

  Kmg[memory]:K,M,G

  kilo[memory]:1024

  Unscaled[memory]:dwym

  YLegend[memory]:Memory Btyes

  ShortLegend[memory]:B

  Legend1[memory]:已用Mem(Bytes)

  Legend2[memory]:已用Swap(Bytes)

  LegendI[memory]:已用Mem:

  LegendO[memory]:已用Swap

  Title[memory]:內(nèi)存使用率

  PageTop[memory]:

  內(nèi)存使用量(Mem+Swap)

  PageFoot[memory]:jb51 Inc

  #

  #[硬盤使用率]

  #

  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

  Language:utf8

  Directory[disk]:disk

  MaxBytes1[disk]:13102744

  MaxBytes2[disk]:41279536

  Kmg[disk]:K,M,G

  Kilo[disk]:1024

  Ylegend[disk]:Disk Bytes

  Shortlegend[disk]:B

  legend1[disk]:系統(tǒng)磁盤已用空間

  legend2[disk]:數(shù)據(jù)盤已用空間

  legendI[disk]:系統(tǒng)已用

  legendO[disk]:數(shù)據(jù)已用

  Title[disk]:硬盤空間使用率

  PageTop[disk]:

  硬盤空間[系統(tǒng)盤+數(shù)據(jù)盤]

  PageFoot[disk]:jb51 Inc

  #================================================================================

  #監(jiān)控系統(tǒng)負(fù)載[1分鐘+15分鐘]

  #================================================================================

  Target[systemload]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:public@localhost:

  Options[systemload]: gauge,nopercent,growright

  Directory[systemload]: load

  MaxBytes[systemload]: 3000

  YLegend[systemload]: System Load

  ShortLegend[systemload]:

  Legend1[systemload]: 最近1分鐘系統(tǒng)負(fù)載(x100)

  Legend2[systemload]: 最近15分鐘系統(tǒng)負(fù)載(x100)

  LegendI[systemload]: 1分鐘負(fù)載:

  LegendO[systemload]: 15分鐘負(fù)載:

  Title[systemload]: 系統(tǒng)負(fù)載(x100)[1分鐘+15分鐘]

  PageTop[systemload]:

  系統(tǒng)負(fù)載(x100)[1分鐘+15分鐘]

  #================================================================================

  #監(jiān)控打開的TCP連接數(shù)[TCP連接數(shù)]

  #================================================================================

  Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@localhost:

  Options[tcpopen]: gauge,nopercent,growright

  Directory[tcpopen]: tcpopen

  MaxBytes[tcpopen]: 1000

  YLegend[tcpopen]: Tcp Connections

  ShortLegend[tcpopen]: 個(gè)

  Legend1[tcpopen]: 打開的TCP連接數(shù)(個(gè))

  Legend2[tcpopen]:

  LegendI[tcpopen]: TCP連接數(shù):

  LegendO[tcpopen]:

  Title[tcpopen]: TCP連接數(shù)[TCP連接數(shù)]

  PageTop[tcpopen]:

  TCP連接數(shù)[TCP連接數(shù)]

  (4)設(shè)置啟動(dòng)和corntab

  mrtg安裝好后就已經(jīng)在 /etc/cron.d/下有一個(gè)mrtg的文件了 我們只需要修改

  復(fù)制代碼

  代碼如下:

  */2 * * * * root 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 //每兩分鐘 執(zhí)行一次

  第一次執(zhí)行會(huì)有錯(cuò)誤 所以我們必須手動(dòng)執(zhí)行三次 沒錯(cuò)誤就可以了

  復(fù)制代碼

  代碼如下:

  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

  (5)我們到目錄下生成index文件

  復(fù)制代碼

  代碼如下:

  /usr/local/mrtg/bin/indexmaker /etc/mrtg/mrtg.cfg --output=http://www.3lian.com/data/wwwroot/mrtg/index.html --title="自己起名"

  效果如下

20151027120534128.png (300×151)