How to Install MRTG on Ubuntu
Guide on how to install and configure MRTG (Multi Router Traffic Grapher) on Ubuntu for server and network traffic monitoring.
This post is written as a personal memo, and it's made public in hopes it might help others in need.
Test Server Environment
- Home server, connection via hub (fiber optic), Ubuntu Server Edition 10.04.2 LTS x64. (IP configuration with localhost is possible)
- Home server, direct connection (fiber optic), Ubuntu Server Edition 10.10 x64 (IP configuration with localhost is possible)
- VPS, Ubuntu Server 10.10 (IP configuration required)
Necessary Package Installation
sudo apt-get -y install snmp snmpd mrtg
Modify /etc/snmp/snmpd.conf
com2sec public localhost public
com2sec public 127.0.0.1 public
# If not localhost, directly specify the server IP.
# com2sec public server IP public
group public v1 public
group public v2c public
view all included .1
access public "" any noauth exact all none none
syslocation "Server Location"
syscontact "Contact Info"
sudo /etc/init.d/snmpd restart
Procedure
Create and run the following script. Don't forget to adjust permissions with chmod +x.
#!/bin/bash
MM_HOST="localhost" # Use IP if localhost doesn't work.
cd ~
mkdir mrtg
cd ~/mrtg
mkdir http
echo "cd /home/${USER}/mrtg;env LANG=C /usr/bin/mrtg /home/${USER}/mrtg/mrtg.cfg">mrtg.sh
echo "indexmaker /home/${USER}/mrtg/mrtg.cfg > /home/${USER}/mrtg/http/index.html">maker.sh
chmod +x maker.sh mrtg.sh
cfgmaker --global "WorkDir: /home/${USER}/mrtg/http/" --global 'Language: korean' --global 'Options[_]: bits,growright' --output mrtg.cfg public@${MM_HOST}
If you're not already in the ~/mrtg directory, move with cd ~/mrtg.
Next, open mrtg.cfg with:
vi mrtg.cfg
And comment out the automatically generated WorkDir at the top.
./maker.sh;
sudo ./mrtg.sh;
If it works, installation is successful (ignore errors and try running sudo ./mrtg.sh a few times; if no errors, it's functioning).
Add to crontab
Gain root access with sudo su and add to crontab -e
* * * * * /home/username/mrtg/mrtg.sh
Acknowledgments
Special thanks to Lative Studio.
Leveraging Perl and Shell Scripts for Enhanced MRTG Monitoring
Explore a collection of Perl and Shell scripts designed for MRTG to monitor server metrics like load average, mail log size, TCP connections, and system uptime efficiently.
When Rsync Runs Slow Even on a 1Gbps Line
Learn how to significantly boost your rsync transfer speeds on a 1Gbps connection by adjusting your command-line options for optimal performance.
Resolving 'Failed to Open Stream: Permission Denied' in Apache + PHP
Resolve 'failed to open stream: Permission Denied' in Apache+PHP environments by adjusting security context using chcon.