CentOS6.8搭建mrtg与详细配置

版权声明:转载请标明出处! https://blog.csdn.net/weixin_38642130/article/details/84646939

什么是MRTG?

MRTG是一个监控网络链路流量负载的工具软件,通过snmp协议得到设备的流量信息,并将流量负载以包含PNG格式的图形的HTML 文档方式显示给用户,以非常直观的形式显示流量负载。
SNMP(imple Network Management Protocol,简单网络管理协议)的前身是简单网关监控协议(SGMP),用来对通信线路进行管理。随后,人们对SGMP进行了很大的修改,特别是加入了符合Internet定义的SMI和MIB:体系结构,改进后的协议就是著名的SNMP。

版本信息

centos6.8
freetype-2.4.12
jpeg-9c
libgd-2.2.5
libpng-1.5.30
mrtg-2.17.7
zlib-1.2.11
net-snmp-5.8

安装环境

$ yum -y install make gcc gcc-c++ openssl openssl-devel

上传源码包到/usr/local/software目录下

获取源码包方法,文章结尾有说明!

安装依赖

安装snmp
$ yum install -y net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils
$ vi /etc/snmp/snmpd.conf

将62行:
access notConfigGroup "" any noauth exact systemview none none
改为
access notConfigGroup "" any noauth exact mib2 none none
把第89行前面的注释符号#去掉,变成
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

$ /etc/init.d/snmpd start	#启动snmp
安装web服务

mrtg需要web服务器作为载体,然后以网页的形式把监控的内容呈现出来。这里就采用apache,快速用yum进行安装。

$ yum install -y httpd
$ vi /etc/httpd/conf/httpd.conf

#查找ServerName,填写主机ip,我的目前主机ip是192.168.0.68
ServerName 192.168.0.68:80
#最配置文件最下面加上网站目录
<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

$ service httpd start	#启动apache
安装zlib库
$ tar -zxvf zlib-1.2.11.tar.gz 
$ cd zlib-1.2.11
$ ./configure --prefix=/usr/local/zlib && make && make install && echo "say ok"
$ cd ..
安装libpng库
$ tar -zxvf libpng-1.5.30.tar.gz 
$ cd libpng-1.5.30
$ ./configure --prefix=/usr/local/libpng && make && make install && echo "say ok"
$ cd ..

可能发生错误:--configure: error: ZLib not installed
解决方法:执行以下两条命令

$ export LDFLAGS="-L/usr/local/zlib/lib"
$ export CPPFLAGS="-I/usr/local/zlib/include"
安装JPEG库
jpeg默认不会自建目录,因此需手动建立目录:
$ tar -zxvf jpegsrc.v9c.tar.gz 
$ cd jpeg-9c/
$ ./configure --prefix=/usr/local/jpeg --enable-static --enable-shared && make && make install && echo "say ok"
$ cd ..
安装freetype
$ tar -zxvf freetype-2.4.12.tar.gz 
$ cd freetype-2.4.12
$ ./configure --prefix=/usr/local/freetype && make && make install && echo "say ok"
$ cd ..
安装gd库
$ tar -zxvf libgd-2.2.5.tar.gz 
$ cd libgd-2.2.5
$ ./configure --prefix=/usr/local/libgd --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
$ make && make install && echo "say ok"
$ cd ..

搭建MRTG

安装mrtg
$ tar -zxvf mrtg-2.17.7.tar.gz
$ cd mrtg-2.17.7
$ ./configure --with-gd=/usr/local/libgd --with-gd-lib=/usr/local/libgd/lib/ --with-gd-inc=/usr/local/libgd/include/ --with-z=/usr/local/zlib/ --with-z-lib=/usr/local/zlib/lib/ --with-z-inc=/usr/local/zlib/include/ --with-png=/usr/local/libpng/ --with-png-lib=/usr/local/libpng/lib/ --with-png-inc=/usr/local/libpng/include/ --prefix=/usr/local/mrtg
$ make && make install && echo "say ok"
配置mrtg
  1. 由于mrtg是通过snmp协议与网络设备进行通信的,所以在客户端也需要安装且开启snmp,客户端采用yum进行快速的安装。
$ yum install -y net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils
$ /etc/init.d/snmpd start	#启动snmp
  1. 在web网站目录下建立mrtg/switch100目录,以交换机为划分管理一批主机,方便日后管理。
$ mkdir -p /var/www/html/mrtg/switch100
$ cp ./images/* /var/www/html/mrtg/switch100/
  1. 配置好关于获取监控主机的cfg,并生成页面:
$ /usr/local/mrtg/bin/cfgmaker --snmp-options=:::::2 [email protected] --output=/var/www/html/mrtg/switch100/192.168.0.60.cfg
$ vi /var/www/html/mrtg/switch100/192.168.0.60.cfg	#添加如下内容
	WorkDir: /var/www/html/mrtg/switch100/
	Options[_]: growright, bits
	Language:chinese
  1. 测试配置文件:
$ env LANG=C /usr/local/mrtg/bin/mrtg /var/www/html/mrtg/switch100/192.168.0.60.cfg
执行过程可能会报错,多执行几次,没有提示报错就表示成功了。
执行完上面命令,会在目录/var/www/html/mrtg/switch100下生成一些html和png文件。
  1. 现在来生成主页文件:
$ /usr/local/mrtg/bin/indexmaker --title="switch100" --output=/var/www/html/mrtg/switch100/index.html /var/www/html/mrtg/switch100/192.168.0.68.cfg

参考链接
1、史上最详细的mrtg设置说明
http://www.cnblogs.com/see7di/archive/2013/01/04/2843750.html
2、MRTG安装教程
https://blog.csdn.net/u013298318/article/details/71600594
3、MRTG Configuration
https://blog.csdn.net/snowman_sp/article/details/522790
4、mrtg监控网络流量简单配置
http://blog.itpub.net/20575781/viewspace-709869/

猜你喜欢

转载自blog.csdn.net/weixin_38642130/article/details/84646939