The system used in this article is RH9.0, and the IP address of the machine is 192.168.1.6
1. MRTG needs to be based on SNMP service, so please make sure that your system has enabled this service.
1. Please make sure that the following software packages are installed on your system
net-snmp-5.0.6-17
net-snmp-devel-5.0.6-17
net-snmp-utils-5.0.6-17
2. Modify /etc/snmp/
Remove the comments on the following line
view mib2 included .-2 fc
Add the following line at about 55 lines
view systemview included .1.3.6.1.2.1.2
Put the following line
access notConfigGroup "" any noauth exact systemview none none
Revised:
access notConfigGroup "" any noauth exact mib2 none none
3. Enable snmpd service
#service snmpd start
#chkconfig --levle 2345 snmpd on
4. Check the port opening status
# netstat -tunlp |grep snmp
tcp 0 0 0.0.0.0:199 0.0.0.0:* LISTEN 4973/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 4973/snmpd
2. MRTG generation for browsing images requires support from httpd service, and also requires support from three software packages gd, libpng and zlib. The normal operation of gd also requires several other software. Install them together.
1. Install zlib-1.2.3
#tar zxvf zlib-1.2.
#cd zlib-1.2.3
#./configure --prefix=/usr/local/zlib
#make
#make install
2. Install httpd-2.2.4
#tar zxvf httpd-2.2.
#cd httpd-2.2.4
#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-track-vars --enable-rewrite --with-z-dir=/usr/local/zlib
#make
#make install
Start httpd
/usr/local/apache/bin/apachectl -k start
3. Install libpng-1.2.14
#tar zxvf libpng-1.2.
# cd libpng-1.2.14
# cp scripts/ makefile
# make (If you are prompted that you cannot find the zlib library file or header file, it is most likely that the default path of zlib in the makefile file is incorrect. You can edit the makefile file, find the zlib item and re-specify the path to /usr/local/zlib/lib and /usr/local/zlib/include).
# make install
4. Install freetype-2.1.10
# tar -zvxf freetype-2.1.
# cd freetype-2.1.10
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make;make install
5. Install jpegsrc.v6b
jpeg does not build a directory by default, so it needs to manually create a directory:
# mkdir -pv /usr/local/jpeg6/{,bin,lib,include,man/{,man1},man1}
Install
#tar zxvf jpegsrc.
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
# make install-lib
6. Install libxml2-2.6.19
# tar -zxf libxml2-2.6.
# cd libxml2-2.6.19
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make; make install
#cp xml2-config /usr/bin
7. Install the GD-2.0.33 library
# tar -zvxf gd-2.0.
# mkdir -p /usr/local/gd2
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
# make
# make install
3. Install and configure MRTG
1. Download mrtg, the latest version is mrtg-2.15.1
/mrtg/pub/mrtg-2.15.
2. Install mrtg-2.15.1
#tar zxvf mrtg-2.15.
# cd mrtg-2.15.1
# ./configure --prefix=/usr/local/mrtg --sysconfdir=/etc/mrtg --with-gd=/usr/local/gd2/include --with-gd-lib=/usr/local/gd2/lib --with-gd-inc=/usr/local/gd2/include --with-png=/usr/local/include --with-png-lib=/usr/local/lib --with-png-inc=/usr/local/include --with-zlib=/usr/local/zlib/include --with-zlib-lib=/usr/local/zlib/include --with-zlib-inc=/usr/local/zlib/include
# make
# make install
3. Basic configuration
Generate the main configuration file
#/usr/local/mrtg/cfgmaker public@localhost > /etc/mrtg/
Edit /etc/mrtg/
Will
#WorkDir:/home/http/mrtg
Remove the comments and change to
WorkDir: /usr/local/apache/htdocs/mrtg (This is your httpd default home directory)
Remove the comments in the following lines
# Options[_]: growright, bits
Add the following line to realize the display of Chinese characters in the web page
Language:gb2312
Generate the MRTG web page homepage file
#/usr/local/mrtg/bin/indexmaker /etc/mrtg/ --output=/usr/local/apache/htdocs/mrtg/ --title="My MRTG"
4. Start MRTG
#env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/
This command will output some error messages, which can generally be ignored safely, and only execute this command three times in a row.
The generated web page is static. In order to make it refresh continuously, the above command needs to be added to crontab.
#crontab -e
Add the following line
*/3 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/
Note: This line indicates that it refreshes every three minutes, and you can modify the refresh time interval according to your needs.
6. After the installation is completed, you can check the results. Enter the following address in the browser
http://192.168.1.6/mrtg (The IP address is your machine IP)
4. An example: memory usage monitoring
1. Create a new folder to store scripts
#mkdir -pv /usr/local/apache/htdocs/mrtgsh
2. Create a script file
#vi /usr/local/apache/htdocs/mrtgsh/
Add the following script:
#!/bin/bash
# run this script to check the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
UPtime=`/usr/bin/uptime | awk '{print $3""$4""$5}'`
echo $totalmem
echo $usedmem
echo $UPtime
Let it have operation permissions
#chmod 755 /usr/local/apache/htdocs/mrtgsh/
3. Edit /etc/mrtg/
Add the following content
Target[memory]: `/usr/local/apache/htdocs/mrtgsh/`
MaxBytes[memory]: 4096000
Title[memory]:Memory Usages
ShortLegend[memory]: &
kmg[memory]:kB,MB
kilo[memory]:1024
YLegend[memory]: Memory Usage :
Legend1[memory]: Total Memory :
Legend2[memory]: Used Memory :
LegendI[memory]: Total Memory :
LegendO[memory]: Used Memory :
Options[memory]: growright,gauge,nopercent
PageTop[memory]:<H1>Memory Usages</H1>
4. Regenerate the main page file
#/usr/local/mrtg/bin/indexmaker /etc/mrtg/ --output=/usr/local/apache/htdocs/mrtg/ --title="My MRTG"
5. You can restart MRTG according to the situation, and then you can view the effect.
This article is reproduced from
1. MRTG needs to be based on SNMP service, so please make sure that your system has enabled this service.
1. Please make sure that the following software packages are installed on your system
net-snmp-5.0.6-17
net-snmp-devel-5.0.6-17
net-snmp-utils-5.0.6-17
2. Modify /etc/snmp/
Remove the comments on the following line
view mib2 included .-2 fc
Add the following line at about 55 lines
view systemview included .1.3.6.1.2.1.2
Put the following line
access notConfigGroup "" any noauth exact systemview none none
Revised:
access notConfigGroup "" any noauth exact mib2 none none
3. Enable snmpd service
#service snmpd start
#chkconfig --levle 2345 snmpd on
4. Check the port opening status
# netstat -tunlp |grep snmp
tcp 0 0 0.0.0.0:199 0.0.0.0:* LISTEN 4973/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 4973/snmpd
2. MRTG generation for browsing images requires support from httpd service, and also requires support from three software packages gd, libpng and zlib. The normal operation of gd also requires several other software. Install them together.
1. Install zlib-1.2.3
#tar zxvf zlib-1.2.
#cd zlib-1.2.3
#./configure --prefix=/usr/local/zlib
#make
#make install
2. Install httpd-2.2.4
#tar zxvf httpd-2.2.
#cd httpd-2.2.4
#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-track-vars --enable-rewrite --with-z-dir=/usr/local/zlib
#make
#make install
Start httpd
/usr/local/apache/bin/apachectl -k start
3. Install libpng-1.2.14
#tar zxvf libpng-1.2.
# cd libpng-1.2.14
# cp scripts/ makefile
# make (If you are prompted that you cannot find the zlib library file or header file, it is most likely that the default path of zlib in the makefile file is incorrect. You can edit the makefile file, find the zlib item and re-specify the path to /usr/local/zlib/lib and /usr/local/zlib/include).
# make install
4. Install freetype-2.1.10
# tar -zvxf freetype-2.1.
# cd freetype-2.1.10
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make;make install
5. Install jpegsrc.v6b
jpeg does not build a directory by default, so it needs to manually create a directory:
# mkdir -pv /usr/local/jpeg6/{,bin,lib,include,man/{,man1},man1}
Install
#tar zxvf jpegsrc.
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
# make install-lib
6. Install libxml2-2.6.19
# tar -zxf libxml2-2.6.
# cd libxml2-2.6.19
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make; make install
#cp xml2-config /usr/bin
7. Install the GD-2.0.33 library
# tar -zvxf gd-2.0.
# mkdir -p /usr/local/gd2
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
# make
# make install
3. Install and configure MRTG
1. Download mrtg, the latest version is mrtg-2.15.1
/mrtg/pub/mrtg-2.15.
2. Install mrtg-2.15.1
#tar zxvf mrtg-2.15.
# cd mrtg-2.15.1
# ./configure --prefix=/usr/local/mrtg --sysconfdir=/etc/mrtg --with-gd=/usr/local/gd2/include --with-gd-lib=/usr/local/gd2/lib --with-gd-inc=/usr/local/gd2/include --with-png=/usr/local/include --with-png-lib=/usr/local/lib --with-png-inc=/usr/local/include --with-zlib=/usr/local/zlib/include --with-zlib-lib=/usr/local/zlib/include --with-zlib-inc=/usr/local/zlib/include
# make
# make install
3. Basic configuration
Generate the main configuration file
#/usr/local/mrtg/cfgmaker public@localhost > /etc/mrtg/
Edit /etc/mrtg/
Will
#WorkDir:/home/http/mrtg
Remove the comments and change to
WorkDir: /usr/local/apache/htdocs/mrtg (This is your httpd default home directory)
Remove the comments in the following lines
# Options[_]: growright, bits
Add the following line to realize the display of Chinese characters in the web page
Language:gb2312
Generate the MRTG web page homepage file
#/usr/local/mrtg/bin/indexmaker /etc/mrtg/ --output=/usr/local/apache/htdocs/mrtg/ --title="My MRTG"
4. Start MRTG
#env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/
This command will output some error messages, which can generally be ignored safely, and only execute this command three times in a row.
The generated web page is static. In order to make it refresh continuously, the above command needs to be added to crontab.
#crontab -e
Add the following line
*/3 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/
Note: This line indicates that it refreshes every three minutes, and you can modify the refresh time interval according to your needs.
6. After the installation is completed, you can check the results. Enter the following address in the browser
http://192.168.1.6/mrtg (The IP address is your machine IP)
4. An example: memory usage monitoring
1. Create a new folder to store scripts
#mkdir -pv /usr/local/apache/htdocs/mrtgsh
2. Create a script file
#vi /usr/local/apache/htdocs/mrtgsh/
Add the following script:
#!/bin/bash
# run this script to check the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
UPtime=`/usr/bin/uptime | awk '{print $3""$4""$5}'`
echo $totalmem
echo $usedmem
echo $UPtime
Let it have operation permissions
#chmod 755 /usr/local/apache/htdocs/mrtgsh/
3. Edit /etc/mrtg/
Add the following content
Target[memory]: `/usr/local/apache/htdocs/mrtgsh/`
MaxBytes[memory]: 4096000
Title[memory]:Memory Usages
ShortLegend[memory]: &
kmg[memory]:kB,MB
kilo[memory]:1024
YLegend[memory]: Memory Usage :
Legend1[memory]: Total Memory :
Legend2[memory]: Used Memory :
LegendI[memory]: Total Memory :
LegendO[memory]: Used Memory :
Options[memory]: growright,gauge,nopercent
PageTop[memory]:<H1>Memory Usages</H1>
4. Regenerate the main page file
#/usr/local/mrtg/bin/indexmaker /etc/mrtg/ --output=/usr/local/apache/htdocs/mrtg/ --title="My MRTG"
5. You can restart MRTG according to the situation, and then you can view the effect.
This article is reproduced from