如何在Ubuntu 18.04上安装和配置MRTG
MRTG(多路由器流量Grapher)是用Perl编写的开源工具,用于监视和测量网络链路上的流量负载并以图形形式呈现数据。
此工具可在奇数小时内跟踪并解决网络流量尖峰等网络异常。
MRTG适用于支持SNMP协议的所有网络设备。
它监控SNMP网络设备并绘制漂亮的图片,显示每台接口过多的流量。
MRTG在UNIX/Linux,Windows和NetWare系统上运行。
在这篇文章中,我们将研究如何在Ubuntu 18.04上安装和配置MRTG。
MRTG准备工作
在计算机上运行MRTG之前,我们需要安装Apache。
在Ubuntu 18.04上,我们可以通过从官方存储库中拉包来轻松安装Apache。
$sudo apt-get install apache2
为Ubuntu安装SNMP软件包:
$sudo apt-get install snmpd snmp
配置SNMP(简单的网络管理协议)。
我喜欢从localhost启用完全访问权限。
$sudo vim /etc/snmp/snmpd.conf rocommunity public localhost
我们需要重新启动SNMPD服务以进行更改。
$sudo systemctl restart snmpd
在Ubuntu 18.04上安装MRTG
所有prereqs都可以,所以我们可以通过运行命令来安装mrtg:
$ sudo apt-get install mrtg
接受任何弹出提示,然后单击"是"以启动安装。
配置MRTG.
安装过程完成后,我们需要在开始监视目标设备之前配置它。
我们将将MRTG工作目录设置为/var/www/mrtg
# mkdir /var/www/mrtg
确保将此目录的所有者更改为"www-data"",这是Apache Web服务器的默认用户帐户。
# chown -R www-data:www-data /var/www/mrtg
然后编辑/etc/mrtg.conf设置工作目录:
# cat /etc/mrtg.cfg | grep -v "^#" WorkDir: /var/www/mrtg WriteExpires: Yes Title[^]: Traffic Analysis for
从修改文件重建MRTG配置:
# cfgmaker public@localhost > /etc/mrtg.cfg --base: Get Device Info on public@localhost: --base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10 --base: Populating confcache --base: Get Interface Info --base: Walking ifIndex --snpd: public@localhost: -> 1 -> ifIndex = 1 --snpd: public@localhost: -> 2 -> ifIndex = 2 --snpd: public@localhost: -> 3 -> ifIndex = 3 --base: Walking ifType --snpd: public@localhost: -> 1 -> ifType = 24 --snpd: public@localhost: -> 2 -> ifType = 6 --snpd: public@localhost: -> 3 -> ifType = 6 --base: Walking ifAdminStatus --snpd: public@localhost: -> 1 -> ifAdminStatus = 1 --snpd: public@localhost: -> 2 -> ifAdminStatus = 1 --snpd: public@localhost: -> 3 -> ifAdminStatus = 1 --base: Walking ifOperStatus --snpd: public@localhost: -> 1 -> ifOperStatus = 1 --snpd: public@localhost: -> 2 -> ifOperStatus = 1 --snpd: public@localhost: -> 3 -> ifOperStatus = 1 --base: Walking ifMtu --snpd: public@localhost: -> 1 -> ifMtu = 65536 --snpd: public@localhost: -> 2 -> ifMtu = 1500 --snpd: public@localhost: -> 3 -> ifMtu = 1500 --base: Walking ifSpeed --snpd: public@localhost: -> 1 -> ifSpeed = 10000000 --snpd: public@localhost: -> 2 -> ifSpeed = 0 --snpd: public@localhost: -> 3 -> ifSpeed = 0
# ls /var/www/mrtg/ index.html mrtg-l.png mrtg-m.png mrtg-r.png
为Web服务器创建索引文件:
# indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html
最后要做的是为创建一个VirtualHost文件。
# vim /etc/apache2/sites-available/mrtg.conf
将以下内容添加到此新文件中:
Alias /mrtg "/var/www/mrtg/" <Directory "/var/www/mrtg/"> Options None AllowOverride None Require all granted </Directory>
启用站点并重新加载Apache服务。
# sudo a2ensite mrtg
重新加载Apache服务:
# systemctl reload apache2
访问MRTG UI.
转到http://ip-address/mrgt或者http://servername/mrtg tp Access MRTG Web界面。
接口监控应开始显示流量:
默认情况下还有界面的默认日图。
我们可以配置MRTG以监控内存,CPU使用率,交换,磁盘等等其他内容。
将MRTG配置为每x分钟进行轮询指标。
我要创建一个Cron作业,检查配置文件的更改,并生成可以在Web界面上查看的新PNG图像。
确保将Cron作业创建为root用户。
# crontab -e
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg.cfg
这将每五分钟执行一次。