Skip to content
TrySitePrice

Centos Install and Configure MRTG

Best/Tutorial

MRTG (Multi Router Traffic Grapher) is a tool that can monitor and graph the traffic load on network links. Here are the steps to install and configure MRTG on CentOS:

  1. Install the required packages:

sudo yum install mrtg httpd httpd-tools net-snmp net-snmp-utils

  1. Create the MRTG configuration file /etc/mrtg/mrtg.cfg using the following command:

sudo cfgmaker --global 'WorkDir: /var/www/mrtg' --output=/etc/mrtg/mrtg.cfg public@localhost

This command creates a configuration file for monitoring the localhost using SNMP and sets the output directory to /var/www/mrtg.

  1. Create the log and data directory:

sudo mkdir /var/log/mrtg

sudo mkdir /var/lib/mrtg

sudo touch /var/log/mrtg/mrtg.log

  1. Set the permissions on the log and data directories:

sudo chown -R apache:apache /var/log/mrtg /var/lib/mrtg /var/www/mrtg

sudo chmod -R 755 /var/log/mrtg /var/lib/mrtg /var/www/mrtg

  1. Generate the first set of MRTG graphs by running the following command:

sudo env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

This command generates the first set of graphs and places them in /var/www/mrtg.

  1. Edit the Apache configuration file /etc/httpd/conf/httpd.conf and add the following lines:

Alias /mrtg /var/www/mrtg

<Directory "/var/www/mrtg">

 Options None

 AllowOverride None

 Order allow,deny

 Allow from all

</Directory>

This sets up an alias for the MRTG graphs and allows access to them from a web browser.

  1. Restart the Apache web server:

sudo systemctl restart httpd

After completing these steps, you should be able to access the MRTG graphs by browsing to http://your_server_ip/mrtg. The graphs should automatically update every 5 minutes.