MRTG安装笔记

网络结构:
子节点:121.191.131.111[外网地址]172.16.141.21[内网地址]  
子节点:121.191.131.112
子节点:121.191.131.113
子节点:121.191.131.114
子节点:121.191.131.115
子节点:121.191.131.116
中心节点:121.191.131.117[外网地址] 172.16.141.27[内网地址]
 
一 在客户端装snmp
进入某子节点后 su - root
1.which snmpd 看看原来装过没有
2. rsync 211.11.11.101::download/software/snmp/net-snmp-5.4.1.tar.gz  
./configure
make
make install
3. cp /usr/sbin/snmp* /usr/local/sbin/
4.rsync 211.11.11.101::download/tmp/snmpd.conf /etc/snmpd/
这里下载了一个以前用过的配置,事实上这样的做法导致错误,这个后面会解决.
5.
/usr/local/sbin/snmpd -c /etc/snmpd/snmpd.conf
6.  
echo "/usr/local/sbin/snmpd -c /etc/snmpd/snmpd.conf" >>/etc/rc.local


二 安装MRTG软件包:
中心机 121.191.131.117  

apache 和 mrtg 装在一台机器上 apache 启8000端口
rsync 211.11.11.101::download/software/mrtg/mrtg-2.10.15-1.i386.rpm /data0/jevons
rpm -ivh mrtg-2.10.15-1.i386.rpm
告诉我没有gd
【rsync 211.11.11.101::download/software/gd/gd-2.0.28-4.rpm】
rpm -ivh gd-2.0.28-4.rpm


下载安装apache
rsync 211.11.11.101::download/tmp/apache.tar /data1/
进这个目录下:
/data1/apache/htdocs/mrtg

三 设置MRTG
就以要统计的机器外网IP121.191.131.111  内网IP 172.16.141.21 为例
这里要注意,MRTG的机器和被统计的机器内网一定要互通,而且snmp进程需要启动
mkdir /data1/apache/htdocs/mrtg/121.191.131.111;/
cd 121.191.131.111;/
cp /var/www/mrtg/* /data1/apache/htdocs/mrtg/121.191.131.111;/
cfgmaker --output=/data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg [email protected]
######################################
【事实上以上配置在这里会出现一个问题,--snpo: Skipping ifName scanning because [email protected]: does not seem to support it,但之前很难注意到】
现在得到一个mrtg.cfg
######################################
 修改mrtg.cfg文件,主要修改以下内容,以符合你的实际情况
-----

#  for UNIX
WorkDir: /data1/apache/htdocs/mrtg/121.191.131.111  (这里换成实际目录)

#  or for NT
# WorkDir: c:/mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits    
Language:Chinese               

然后执行下面这行(需要执行三遍)
env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
 
在crontab -e  里添加
 

* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg > /dev/null &
* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.112/mrtg.cfg > /dev/null &
* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.113/mrtg.cfg > /dev/null &
* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.114/mrtg.cfg > /dev/null &
* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.115/mrtg.cfg > /dev/null &
* * * * * /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.116/mrtg.cfg > /dev/null &
#####################################
【crontab 里面像上面这样加也是有问题的,手动执行会看到错误
 /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start:
 
       env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
-----------------------------------------------------------------------
所以crontab里面应该是
* * * * * env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg > /dev/null &
* * * * * env LANG=C /usr/bin/mrtg  /data1/apache/htdocs/mrtg/121.191.131.112/mrtg.cfg > /dev/null &
* * * * * env LANG=C /usr/bin/mrtg  /data1/apache/htdocs/mrtg/121.191.131.113/mrtg.cfg > /dev/null &
* * * * * env LANG=C /usr/bin/mrtg  /data1/apache/htdocs/mrtg/121.191.131.114/mrtg.cfg > /dev/null &
* * * * * env LANG=C /usr/bin/mrtg  /data1/apache/htdocs/mrtg/121.191.131.115/mrtg.cfg > /dev/null &
* * * * * env LANG=C /usr/bin/mrtg  /data1/apache/htdocs/mrtg/121.191.131.116/mrtg.cfg > /dev/null &

######################################
增加mrtg管理员的账户密码
/data1/apache/bin/htpasswd -c /data1/apache/conf/.htpasswd myuser
mypassword

四 制作mrtg浏览页面


/data1/apache/htdocs/mrtg/index.html
可以用命令生成,也可以参照下面的手动制作

例如:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>  RTG监控系统 </TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="Gil">
<META NAME="Keywords" CONTENT="mrtg">
<META NAME="Description" CONTENT="mrtg monitor">
</HEAD>

<BODY bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000" alink="#000000">
<BR>
        <CENTER><H1><FONT COLOR="GREEN"> MRTG监控系统</FONT></H1></CENTER>
<BR>
<HR>


<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>
  <TR>
  <TD>
          <DIV><B>Traffic Analysis for bce0 - 121.191.131.111</B></DIV>
          <DIV><A HREF="121.191.131.111/172.16.141.21_2.html"><IMG BORDER=1 ALT="172.16.141.21_2 Traffic Graph" SRC="121.191.131.111/172.16.141.21_2-day.png"></A><BR>
          <SMALL><!--#flastmod file="172.16.141.21_2.html" --></SMALL></DIV>
  </TD>
  <TD><DIV><B>Traffic Analysis for bce1 - 172.16.141.21</B></DIV>
          <DIV><A HREF="121.191.131.111/172.16.141.21_3.html"><IMG BORDER=1 ALT="172.16.141.21_3 Traffic Graph" SRC="121.191.131.111/172.16.141.21_3-day.png"></A><BR>
          <SMALL><!--#flastmod file="172.16.141.21_3.html" --></SMALL></DIV>
  </TD>
  </TR>
  <TR>
  </TR>
</TABLE>

 <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>
  <TR>
  <TD>
          <DIV><B>Traffic Analysis for bce0 - 121.191.131.112</B></DIV>
          <DIV><A HREF="121.191.131.112/172.16.141.21_2.html"><IMG BORDER=1 ALT="172.16.141.21_2 Traffic Graph" SRC="121.191.131.112/172.16.141.21_2-day.png"></A><BR>
          <SMALL><!--#flastmod file="172.16.141.21_2.html" --></SMALL></DIV>
  </TD>
  <TD><DIV><B>Traffic Analysis for bce1 - 172.16.141.21</B></DIV>
          <DIV><A HREF="121.191.131.112/172.16.141.21_3.html"><IMG BORDER=1 ALT="172.16.141.21_3 Traffic Graph" SRC="121.191.131.112/172.16.141.21_3-day.png"></A><BR>
          <SMALL><!--#flastmod file="172.16.141.21_3.html" --></SMALL></DIV>
  </TD>
  </TR>
  <TR>
  </TR>
</TABLE>


 <BR><HR><BR>
  <TABLE WIDTH=500 BORDER=0 CELLPADDING=4 CELLSPACING=0>
   <TR><TD ALIGN=RIGHT><FONT SIZE=-1 COLOR="#00cc00">
      <B>GREEN ###</B></FONT></TD>
      <TD><FONT SIZE=-1>Incoming Traffic in Bits per Second</FONT></TD></TR>
   <TR><TD ALIGN=RIGHT><FONT SIZE=-1 COLOR="#0000ff">
      <B>BLUE ###</B></FONT></TD>
      <TD><FONT SIZE=-1>Outgoing Traffic in Bits per Second</FONT></TD></TR>
  </TABLE>
 <BR><HR><BR>

<BR>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
  <TR>
    <TD WIDTH=63><A
    HREF=""><IMG
    BORDER=0 SRC="images/mrtg-l.png" WIDTH=63 HEIGHT=25 ALT="MRTG"></A></TD>
    <TD WIDTH=25><A
    HREF="/"><IMG
    BORDER=0 SRC="images/mrtg-m.png" WIDTH=25 HEIGHT=25 ALT=""></A></TD>
    <TD WIDTH=388><A
    HREF="/"><IMG
    BORDER=0 SRC="images/mrtg-r.png" WIDTH=388 HEIGHT=25
    ALT="Multi Router Traffic Grapher"></A></TD>
  </TR>
</TABLE>

</BODY>
</HTML>

##########################现在来解决刚才说的问题########################################  
刚才遇到的问题1是
cfgmaker --output=/data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg [email protected]
 --snpo: Skipping ifName scanning because [email protected]: does not seem to support it
2是改好/data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg后,执行
env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
会看到
SNMP Error:
Received SNMP response with error code
  error status: noSuchName
解决方法
1)进入子节点121.191.131.111
2)su - root
3)
cp -a /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
echo "rocommunity public" > /etc/snmp/snmpd.conf
cp /etc/snmp/snmpd.conf /etc/snmpd/snmpd.conf
ps aux|grep snmpd|awk '{print $2}'|xargs kill -9
/usr/local/sbin/snmpd -c /etc/snmpd/snmpd.conf
#################################################################
现在到中心机,再次
cfgmaker  --output /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg  [email protected]
 --base: Get Device Info on [email protected]:
--base: Vendor Id:
--base: Populating confcache
--snpo: confcache [email protected]: Name lo --> 1
--snpo: confcache [email protected]: Name eth0 --> 2
--snpo: confcache [email protected]: Name eth1 --> 3
--snpo: confcache [email protected]: Name sit0 --> 4
--snpo: confcache [email protected]: Descr lo --> 1
--snpo: confcache [email protected]: Descr eth0 --> 2
--snpo: confcache [email protected]: Descr eth1 --> 3
--snpo: confcache [email protected]: Descr sit0 --> 4
--snpo: confcache [email protected]: Type 24 --> 1
--snpo: confcache [email protected]: Type 6 --> 2
--snpo: confcache [email protected]: Type 6 --> 3 (duplicate)
--snpo: confcache [email protected]: Type 131 --> 4
--snpo: confcache [email protected]: Ip 127.0.0.1 --> 1
--snpo: confcache [email protected]: Ip 172.16.141.21 --> 3
--snpo: confcache [email protected]: Ip 221.192.141.21 --> 2
--snpo: confcache [email protected]: Ip 221.192.147.121 --> 1
--snpo: confcache [email protected]: Ip 221.192.147.122 --> 1
--snpo: confcache [email protected]: Eth  --> 1
--snpo: confcache [email protected]: Eth 00-15-c5-ed-24-c9 --> 2
--snpo: confcache [email protected]: Eth 00-15-c5-ed-24-cb --> 3
--snpo: confcache [email protected]: Eth  --> 4 (duplicate)
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifSpeed
--base: Writing /data1/apache/htdocs/mrtg/221.192.141.21/mrtg.cfg
可以看到都正确了,对 /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg 做修改
#  for UNIX
WorkDir: /data1/apache/htdocs/mrtg/121.191.131.111  (这里换成实际目录)

#  or for NT
# WorkDir: c:/mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits    
Language:Chinese
###################################################################
现在执行
env LANG=C /usr/bin/mrtg /data1/apache/htdocs/mrtg/121.191.131.111/mrtg.cfg
显示正确

你可能感兴趣的:(MRTG安装笔记)