分类: LINUX
2011-10-10 10:11:31
root@alex:~# apt-get install snmpd mrtg
root@alex:~# vim /etc/snmp/snmpd.conf \\或者shell界面输入snmpconf按照提示进行配置文件修改
com2sec notConfigUser 192.168.108.102 public
com2sec notConfigUser localhost public
com2sec notConfigUser 127.0.0.1 public
\\做一个映射,把notConfigUser与public做好一个映射,在调用snmp的时候,声明notConfigUser 就可以获得相应的权限
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
把notConfigUser放到notConfigGroup组里, 用的协议是v1和v2c
view all included .1 80
赋予所有这个用户view能够查看.1下面所有节点
access notConfigGroup "" any noauth exact all none none
基本语法access NAME CONTEXT MODEL LEVEL PREFX READ WRITE NOTIFY
v2c版本,所以context为空,any理解成v2c level也就是noauth ,all none none就是所有权限
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root
\\定义联系信息
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat \\定义MIB组件
root@alex:~# /etc/init.d/snmpd restart
root@alex:~# snmpwalk -v 2c -c public localhost
root@alex:~# snmpwalk -v 2c -c public 192.168.108.102
能够出现很多数据,也就说明snmp调试成功
配置mrtg
root@alex:~# mkdir /var/www/mrtg
root@alex:~# mkdir /etc/mrtg
root@alex:~# vim /etc/mrtg/cpu.pl \\定义监控cpu ,网上找的 用perl语言编写
#!/usr/bin/perl
system ("/usr/bin/sar -u 1 3|grep Average >cpu_info_file");
open (CPUINFO,"cpu_info_file");
@cpuinfo=
close (CPUINFO);
foreach $line(@cpuinfo) {
@cpustatus=split(/ +/,$line);
}
$cpuused=$cpustatus[2]+$cpustatus[4];
$cpuidle=$cpustatus[5];
print "$cpuused\n";
print "$cpuidle";
system ("uptime");
system ("uname -n");
root@alex:~# vim /etc/mrtg/mem.pl \\定义监控内存
#!/usr/bin/perl
system ("/usr/bin/free -m | grep Mem >mem_info_file");
open (MEMINFO,"mem_info_file");
@meminfo=
close (MEMINFO);
foreach $line(@meminfo) {
@memstatus=split(/ +/,$line);
}
$memused=$memstatus[2];
$memtotal=$memstatus[1];
print "$memused\n";
print "$memtotal\n";
system ("uptime");
system ("uname -n");
root@alex:~# vim /etc/mrtg.cfg \\在mrtg配置文件里添加监控信息
#---------CPU-------------------------------------
Target[192.168.108.102_cpu]: `/etc/mrtg/cpu.pl`
Xsize[192.168.108.102_cpu]: 500
Ysize[192.168.108.102_cpu]: 300
Ytics[192.168.108.102_cpu]: 30
MaxBytes[192.168.108.102_cpu]:100
Title[192.168.108.102_cpu]:CPU State
PageTop[192.168.108.102_cpu]:CPU State of
TestServer
ShortLegend[192.168.108.102_cpu]: %
YLegend[192.168.108.102_cpu]: CPU (%)
Legend1[192.168.108.102_cpu]: Used
Legend2[192.168.108.102_cpu]: Total
LegendI[192.168.108.102_cpu]: CPU Used
LegendO[192.168.108.102_cpu]: CPU IDEL
Options[192.168.108.102_cpu]: growright,gauge,nopercent
#---------mem-----------------------------------
Target[192.168.108.102_mem]: `/etc/mrtg/mem.pl`
Xsize[192.168.108.102_mem]:500
Ysize[192.168.108.102_mem]:300
Ytics[192.168.108.102_mem]:30
MaxBytes[192.168.108.102_mem]: 2002
Title[192.168.108.102_mem]:Memory State of TestServer
PageTop[192.168.108.102_mem]:Memory State of
TestServer
ShortLegend[192.168.108.102_mem]: B
kmg[192.168.108.102_mem]: M
YLegend[192.168.108.102_mem]: Memory Usage
Legend1[192.168.108.102_mem]: Used
Legend2[192.168.108.102_mem]: Total
LegendI[192.168.108.102_mem]: Used
LegendO[192.168.108.102_mem]: Total
Options[192.168.108.102_mem]: growright,gauge,nopercent
root@alex:~# cfgmaker --global "WorkDir: /var/www/mrtg" --global "Options[_]: growright,bits" --ifref=ip public @127.0.0.1 > mrtg.cfg \\ cfgmaker生成文档
root@alex:~# mrtg /etc/mrtg.cfg 执行三次 没有错误 bug 生成html和图片
root@alex:~# indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html \\生成mrtg主页
在网页输入 即可显示监控图像信息
注:如需增加监控信息 需要增加相应配置 在/etc/mrtg.cfg中添加信息 并且重新生成index.html,执行mrtg /etc/mrtg.cfg