如何安装mrtg并创建自定义监控措施 - Linux系统mrtg详细安装、设置说明

   抖音SEO    
MRTG的安装和配置教程 MRTG是一个非常实用的网络监控工具,可以帮助用户监测网络链路流量负载,以 PNG 格式的图像的 HTML 文档的方式直观地展现给用户。本文将向您介绍在 Linux 系统下安装和配置MRTG的详细步骤。

安装SNMP相关工具

在安装和配置MRTG之前,需要先安装SNMP相关工具。以下是安装步骤:

1、1 安装SNMP相关工具

sudo apt-get update
sudo apt-get install snmp snmpd libsnmp-dev

1、2 配置SNMP

编辑 /etc/snmp/snmpd.conf 文件,修改或添加以下内容:
rocommunity public  localhost
rocommunity public  your_network_address
保存并退出。

安装MRTG

安装SNMP相关工具后,现在可以安装MRTG了。以下是安装步骤:

2、1 下载MRTG源码包

wget http://www.cacti.net/downloads/mrtg/mrtg-2.17.tar.gz

2、2 解压源码包

tar zxvf mrtg-2.17.tar.gz

2、3 进入解压后的目录

cd mrtg-2.17

2、4 编译和安装MRTG

make clean all
sudo make install

配置MRTG

安装MRTG之后,需要配置一些参数才能正常工作。以下是配置步骤:

3、1 创建MRTG配置文件目录

sudo mkdir /etc/mrtg
sudo chmod 777 /etc/mrtg

3、2 创建默认配置文件模板

sudo cp /usr/local/share/mrtg/mrtg.cfg.example /etc/mrtg/mrtg.cfg

3、3 编辑MRTG配置文件

使用任何文本编辑器打开/etc/mrtg/mrtg.cfg文件,修改或添加以下内容:
Run as this userid: (required)
set grunuser root

The following options can be used to customize the appearance of the graphs: (optional)
set gtitle "Your Network" #标题名称
set glogo "/path/to/your/logo" #Logo路径(如果需要的话)

The following options define which interfaces should be monitored: (mandatory)
include "interfaces" #包含的文件名,通常为"interfaces",该文件定义了要监控的网络接口。

The following options define which targets to send data to: (mandatory)
include "targets" #包含的文件名,通常为"targets",该文件定义了将数据发送到的目标服务器。
保存并退出。

3、4 创建MRTG接口配置文件目录和模板文件

sudo mkdir /etc/mrtg/interfaces
sudo chmod 777 /etc/mrtg/interfaces
sudo touch /etc/mrtg/interfaces/all
sudo chmod 666 /etc/mrtg/interfaces/all

3、5 编辑MRTG接口配置文件

使用任何文本编辑器打开 /etc/mrtg/interfaces/all 文件,修改或添加以下内容:
Run as this userid: (required)
set daemon 20 # interval in seconds between each round of stats collection, default is every 15 minutes (900 seconds)

include "workstations" # include files for devices on this network
include "printers" # include files for devices on this network
include "servers" # include files for devices on this network
include "switches" # include files for devices on this network
include "routers" # include files for devices on this network
include "firewalls" # include files for devices on this network
include "loadbalancers" # include files for devices on this network
include "vpn" # include files for devices on this network
include "peers" # include files for devices on this network
include "misc" # include files for devices on this network

target "my_network_monitoring_system" # name of target to send data to
unwatched # do not create a graph entry for these devices, they are included by other files
device "Workstations" url "/workstationsgraph.png" text "Workstations" icon "/workstationsicon.png" # device description template

device_description "Workstations: $hostname ($location)" # device variables template
device_vars "Workstations: $uptime$down{$ifdescr}" # device fetch template
device_fetch "Workstations: workstationsconfig.pl host $hostname port $rrd_port name $device_descr $location template $template file $datafile" # device images directory
device_imagedir "/path/to/your/images" # device log directory
device_logdir "/var/log/mrtg" # device rrd database filename
device_rrdfilename "workstationsrrd.rrd" # device rrd database update interval in seconds
device_rrdupdate "600" # device rrd database heartbeat interval in seconds
device_heartbeat "18000" # device rrd database DST adjustment factor
device_dstfactor "0" # device rrd database low value threshold in bytes
device_lowvalue "0" # device rrd database high value threshold in bytes
device_highvalue "0" # device rrd database retention period in days (default is 30)
device_rrdretention "30" # device rrd database archive file name template
device_archivename "workstationsarchive%Y%m%d%H%M%S.png" # device rrd database archive directory template
device_archivedir "/path/to/your/archive" # device rrd database archive URL template
device_archiveurl "/path/to/your/archive%Y%m%d%H%M%S.png"

target {Workstations} systemWorkstations url "/workstationsgraph.png" text "System Workstations" icon "/workstationsicon.png" imagedir "/path/to/your/images" logdir "/var/log/mrtg" rrdfilename "workstationsrrd.rrd" rrdupdate "600" heartbeat "18000" dstfactor "0" lowvalue "0" highvalue "0" rrdretention "30" archivename "workstationsarchive%Y%m%d%H%M%S.png" archivedir "/path/to/your/archive" archiveurl "/path/to/your/archive%Y%m%d%H%M%S.png"

target {Workstations} internetWorkstations url "/internetworkstationsgraph.png" text "Internet Workstations" icon "/internetworkstationsicon.png" imagedir "/path/to/your/images" logdir "/var/log/mrtg" rrdfilename "internetworkstationsrrd.rrd" rrdupdate "600" heartbeat "18000" dstfactor "0" lowvalue "0" highvalue "0

结尾

以上是在 Linux 系统下安装和配置MRTG的详细步骤。通过MRTG,用户可以轻松地监测网络链路流量负载,以便更好地维护和管理网络。 如果您在设置过程中遇到了问题,请在评论区留言,我们会尽快回复并提供帮助。感谢您的阅读,希望此篇文章对您有所帮助。请记得点赞、评论和关注我们,以获取更多精彩内容。

评论留言

我要留言

欢迎参与讨论,请在这里发表您的看法、交流您的观点。