Installation details for MRTG under Linux (CentOS)
MRTG is very powerful, he can control your server for a move, and web-style presented to you, to tell you the network, CPU, memory, hard plate and other uses, but the configuration of this software is actually very troublesome.
To install this software and configure it, I went to the internet to check the two days information, finishing the final summary of this complete out, share to everyone, hope to be useful to everyone. If you want to download, please indicate the www.7di.net
First, the pre-prepare
(1) MRTG needs to be based on the SNMP service, so make sure that your system has this service enabled and modify the SNMP configuration:
#vi/etc/snmp/snmpd.conf
Remove the comment symbol # in front of line 89th and turn it into
View MIB2 included. Iso.org.dod.internet.mgmt.mib-2 FC
Add 62 rows:
Access Notconfiggroup "" Any noauth exact systemview none None
Switch
Access Notconfiggroup "" Any noauth exact mib2 none None
(2) Linux MRTG Monitoring host traffic starts the HTTP service and SNMP service:
First see if two services are turned on at system startup
#chkconfig--list | grep nginx
Do not start if you need to modify under what startup mode to start it yourself:
# chkconfig--level
Use the same settings for the SNMPD service, and now manually start the next
#service Nginx Start
#service snmpd Start
It's best to use Setup to configure the service so that it's automatically self-activating.
Check the port's status to see if it has been activated
# 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
(3) MRTG generates the support for the HTTP service required for the browse image, but also requires the support of GD, Libpng, and zlib three packages, while the normal operation of GD requires a few other software, (the system implicitly, if not, we need to install it manually)
1. Installing zlib-1.2.3
#tar ZXVF zlib-1.2.3.tar.gz
#cd zlib-1.2.3
#./configure--prefix=/usr/local/zlib
#make
#make Install
2. Installing httpd-2.2.4
#tar ZXVF httpd-2.2.4.tar.gz
#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. Installing libpng-1.2.14
#tar ZXVF libpng-1.2.14.tar.gz
# CD libpng-1.2.14
# CP Scripts/makefile.linux Makefile
# make (if you are not prompted to find the Zlib library file or header file, most of the makefile file zlib default path is wrong.) You can edit the makefile file, locate the Zlib key, and reassign the path to/usr/local/zlib/lib and/usr/local/zlib/include).
# make Install
4. Installing freetype-2.1.10
# TAR-ZVXF Freetype-2.1.10.tar.gz
# CD freetype-2.1.10
# mkdir-p/usr/local/freetype
#./configure--prefix=/usr/local/freetype
# Make;make Install
5. Installing jpegsrc.v6b
JPEG does not self-build the directory by default, so you need to create the directory manually:
# Mkdir-pv/usr/local/jpeg6/{,bin,lib,include,man/{,man1},man1}
Installation
#tar ZXVF jpegsrc.v6b.tar.gz
#./configure--prefix=/usr/local/jpeg6/--enable-shared--enable-static
# make
# make Install
# Make Install-lib
6. Installing libxml2-2.6.19
# TAR-ZXF Libxml2-2.6.19.tar.gz
# CD libxml2-2.6.19
# mkdir-p/USR/LOCAL/LIBXML2
#./configure--PREFIX=/USR/LOCAL/LIBXML2
# make; Make install
#cp Xml2-config/usr/bin
7. Installing the GD-2.0.33 Library
# TAR-ZVXF Gd-2.0.33.tar.gz
# 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
(4) Modify the system language configuration
#vi/etc/profile
Add the following two lines
Lc_all=c
Language=on
Second, start the installation
(1) Start installation of MRTG
#cd/USR/LOCAL/SRC
#tar ZVXF mrtg-2.14.5.tar.gz
#cd mrtg-2.14.5
#./configure--PREFIX=/USR/LOCAL/MRTG Note: "--PREFIX=/USR/LOCAL/MRTG" is the specified installation path
#make
#make Install
(2) Configuration MRTG
First set up a directory for MRTG's homepage under Web Catalog, if the Web catalogue is:/home/wwwroot/
Create a new directory under this directory MRTG and SH are:
#cd/home/wwwroot/
#mkdir MRTG
#cd MRTG
#mkdir SH
To duplicate some of the pictures.
#cd/usr/local/src/mrtg-2.14.5
#cp./images/*.*/root/mrtg/
If the path is too long to feel inconvenient, you can build a software connection:
#cd/root
#ln –S/HOME/WWWROOT/MRTG MRTG
#ln –s/usr/local/mrtg/bin Mrtgbin
Then you need to create a configuration file:
#/root/mrtgbin/cfgmaker [email protected] Change the cost IP--output=/root/mrtg/lxy.cfg
To modify a configuration file:
#vi/root/mrtg/lxy.cfg
#WorkDir:/home/http/mrtg Remove comments and change to Workdir:/home/wwwroot/mrtg (here is MRTG web directory)
Will #Options [_]: Growright, bits in front of the # removed, left-justified
Add Language:big5 at the end, then save
(3) Modify the. sh file to allow it to be executed (. sh files are below)
#cd/root/mrtg/sh
#chmod 0755 *.sh
#chmod 0755 *.pl
(4) Test configuration files
Lang=c/root/mrtgbin/mrtg/root/mrtg/lxy.cfg
(5) Generate MRTG Web site home file: Already in the root directory
#/root/mrtgbin/indexmaker--output=/root/mrtg/index.html--title= "Lidalin ' s MRTG"/root/mrtg/lxy.cfg
(6) Next Run the program
#/root/mrtgbin/mrtg/root/mrtg/lxy.cfg Some people use this method to activate #env lang=c/root/mrtgbin/mrtg/mrtg/lxy.cfg
If there are warnings or bugs, run multiple times, and when warnings or bugs no longer appear, OK.
(7) MRTG generated Web page is static, in order to keep it constantly refreshed, need to add the above command into the crontab
#crontab-E
Add the following line
*/1 * * * */root/mrtgbin/mrtg/root/mrtg/lxy.cfg
Save, and then reboot
Open the browser, enter/HTTP//To change the cost of the machine IP/MRTG should be able to see the network usage curve, a minute later to see more accurate!
Note: If you set up a mid-level firewall without opening 80 port access, you need to edit/etc/sysconfig/iptables allow others to access port 80
Third, the meaning of mrtg.cfg inside parameters
Target: Is the script to execute
Xsize: Generate Horizontal width of chart (max. 600)
Ysize: Generate Vertical height of chart (max. 200)
Title: Caption
Kmg:change the default multiplier prefixes
Ytics: vertically divided into several blocks (lattice)
MaxBytes: Maximum upper limit of chart longitudinal values
PageTop: Tips above the page
Kilo: Generally write 1024, if necessary, is 1000 units in the computer
Legendi: The first of the data returned from the shell
Legendo: The second of the data returned from the shell
Options:growright, indicating that the chart is stretched to the right
Iv. Configuration of other examples
Note: Modifications to the configuration must be repeated in the second Stride (3) (4) (5) (6) Step
All other configurations are placed in this folder
#cd/root/mrtg/sh
(1) Video memory usage
Creating a script file
#vi mem.sh
Add the following script:
#!/bin/bash
# Run this script to check the MEM usage.
Totalmem= '/usr/bin/free |grep Mem |awk ' {print $} '
Usedmem= '/usr/bin/free |grep Mem |awk ' {print $} '
Uptime= '/usr/bin/uptime | awk ' {print $ ' "$4" "$ $"
Echo $totalmem
Echo $usedmem
Echo $UPtime
You want to have permission to execute after you save it.
#chmod 755/root/mrtg/sh/mem.sh
(2) Edit the/mrtg/lxy.cfg and add the following:
Target[memory]: '/root/mrtg/sh/mem.sh
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]:
Five, each shell (after modifying the configuration to regenerate the first page, and then re-activate)
(1) MEMORY:mem.sh
#!/bin/bash
# This script to monitor the mem usage.
Totalmem= '/usr/bin/free |grep Mem |awk ' {print $} '
Usedmem= '/usr/bin/free |grep Mem |awk ' {print $} '
echo "$totalmem"
echo "$usedmem"
edit MRTG's configuration file: MaxBytes values are modified by the actual situation
# Mem
Target[memory]: '/root/mrtg/ Sh/mem.sh '
Unscaled[memory]: Dwym
Maxbytes[memory]: 2048000
title[memory]:memory
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]: (2) SWAP:swap.sh
#!/bin/bash
# This script to monitor the swap usage.
totalswap= '/usr/bin/free |grep swap |awk ' {print $} '
usedswap= '/usr/bin/free |grep swap |awk ' {print $} '
Echo ' $totalswap "
Echo" $usedswap "
edit MRTG configuration file: MaxBytes change the
# Swap
Target[swap]: '/root/mrtg/sh/ Swap.sh '
Unscaled[swap]: Dwym
Maxbytes[swap]: 3048000
Title[swap]:swap
Shortlegend[swap]: &
KMG[SWAP]:KB,MB
kilo[swap]:1024
Ylegend[swap]: Swap Usage
Legend1[swap]: Total swap
Legend2[swap]: Used Swap
Legendi[swap]: Total swap
Legendo[swap]: Used swap
Options[swap]: growright,gauge,nopercent
Pagetop[swap]: (3) CPU:cpu.sh
#!/bin/bash
# Run this script to check the MEM usage.
Totalmem= '/usr/bin/free |grep mem |awk ' {print $} '
usedmem= '/usr/bin/free |grep mem |awk ' {print $} '
Uptime= '/ Usr/bin/uptime | awk ' {print $ ' "$4" "$ $"
Echo $totalmem
Echo $usedmem
echo $UPtime
hostname
edit MRTG configuration file: MaxBytes. Modify
# Cpu
Target[cpu]: '/root/mrtg/sh/ Cpu.sh '
Maxbytes[cpu]: +
Title[cpu]: CPU
OPTIONS[CPU]: Gauge,nopercent,growright
Ylegend[cpu]: CPU Loading (%)
shortlegend[cpu]:%
Legendo[cpu]: & CPU USER
Legendi[cpu]: & CPU SYSTEM
Pagetop[cpu]: (4) Magnetic disc occupies: df.pl
#!/usr/bin/perl
# output (DF-KL) looks like this:
# Filesystem 1k-blocks used Available use% mounted on
#/dev/md0 95645100 30401312 64272080 33%/
#/dev/hde1 14119 1159 12231 9% /Boot
#
# in which case, this script returns:
# 95659219
# 30402503
# when run.
foreach $filesystem (' df-kl | grep-v ' FileSystem "') {
@df = Split (/\s+/, $filesystem);
$total + = $DF [1];
$usage + = $DF [2];
}
Print "$total \ n";
print "$usage \ n";
Hostname
edit MRTG configuration file: MaxBytes, modify
# Disk used
Target[disk]: '/ROOT/MRTG /sh/df.pl '
Title[disk]: Disk Space
Unscaled[disk]: Dwym
Maxbytes[disk]: 115247550
Kmg[disk]: KB,MB,GB
Legendi[disk]: Total disk space
Legendo[disk]: Used disk space
Legend1[disk]: Total disk space
Legend2[ Disk]: Used disk Space
Ylegend[disk]: Megabytes
Shortlegend[disk]: &
Options[disk]: Growright,gauge, Nopercent
Pagetop[disk]: (5) Magnetic tray i/o:io.sh
#!/bin/bash
# This script would Monitor the kbread/sec &kbwriten/sec of Disk.
# CREATER:CCC IT Loren ext:2288 2005/8/3
# as SDA, Sdb,sdc,sdd,hda.
# DISK=SDA
Hd=sda
disk=/dev/$hd
kbread_sec= ' iostat-x $disk |grep $hd |awk ' {print $8} '
kbwrite_sec= ' Iostat-x $disk |grep $hd |awk ' {print $9} '
Echo ' $KBread _sec '
Echo ' $KBwrite _sec '
hostname
Edit MRTG configuration file: If you need to detect more partitions, modify the io.sh
# Disk I/O
Target[diskio]: '/root/mrtg/sh/io.sh '
Title[diskio]: Disk HDA I/O
Unscaled[diskio]: Dwym
Maxbytes[diskio]: 100
Kmg[diskio]: KB,MB,GB
Legendi[diskio]: Disk I/O kbread/sec
Legendo[diskio]: Disk I/O kbwrite/sec
Legend1[diskio]: Disk I/O kbread/sec
Legend2[diskio]: Disk I/O kbwrite/sec
Ylegend[diskio]: Megabytes
Shortlegend[diskio]: &
Options[diskio]: growright,gauge,nopercent
Pagetop[diskio]:
Installation details for MRTG under Linux (CentOS)