screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/05bf69bccccc4035aa0291b7ffb1abf6.gif');}"onmousewheel="return imgzoom(this);" alt="" />
Cacti的架构 ( 图一 )
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/56830ac83311448a8065c609acb998cd.png');}"onmousewheel="return imgzoom(this);" alt="" />
c) 配置Cacti连接数据库
#vi /home/wwwroot/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cacti”;
$database_password = “password”;
d) 导入数据表
/usr/local/mysql/bin/mysql -u root –p cactidb cacti.sql
chown -R cactiuser rra/ log/
e) 定时crontab运行cacti的收集数据程序
crontab -u cactiuser –e
*/5 * * * * /usr/local/bin/php /home/wwwroot/cacti/poller.php > /dev/null 2>&1
注意: 不要使用root用户运行上面的命令,否则要再运行一次chown –R cactiuser rra/ log/
f) 配置Cacti
在浏览器上输入:
http://IP/cacti
进入cacti的初始设置页面:
在这里我们要输入一些原始的信息:
NEXT -》
输入一些信息,如rrdtool、php、snmpwalk、snmpget的位置,使用ucd-snmp还是net-snmp等-》
输入原始的用户和密码:admin/admin -》
更改admin用户的密码-》
点击 Save
安装完成!!!
现在可以在浏览器中进入Cacti的世界了! 5.测试
1) 添加监控站点
点
Devices
中的Add进入添加服务器如图3、4、5
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/1ee0aff263a346679f78d82ab1351b2d.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图3)
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/f3276b2b01ae493f9def004340c075d9.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图4)
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/c82c34d146ca49edbe762d8cf4658cde.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图5)
如果能连接得上,则添加后会在头部显示 61.129.102.51 (61.129.102.51) SNMP Information System:00:LINUX:MAIL.BIZCN.COM:2.4.20-30.9SMP:#1:SMP:WED:FEB:04:20:36:46:EST:2004:I686 Uptime:156994868 Hostname:mail.bizcn.com
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/3fe5fa229e2248b2b23624fa47253558.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图6)
2) 配置添加的服务器的监控服务(这里一般使用UCD/NET 模板)
点
New Graphs
选择监控点名,勾选相应的creat
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/f96d1812d525496dbbe75f2acd5a2df4.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图6)
3)、添加目录树(增加后将在监控的位置出现)
点
Graph Trees 中的Add(如图)
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/8f30d8b5ce04417d92b97fcb08eab5c0.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图7)
选择host,并在下拉列表中选择你刚添加的
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/714b6a51ccb44b9e84e692dba0d7255d.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
添加监控服务器(图8)
4)、监控
点击总菜单中的Graphs 显示监控图,可在左边选择相应的监控端查看(一般添加5分钟后就有图出来)
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/3764bc5428c84ef891920318b92be05b.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
监控服务器(图9)
以下是关于流量负载内存等的截图
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/d3fdab4604a140f1a20665546480940c.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
screen.width*0.7){this.resized=true; this.width=screen.width*0.7; this.alt='Click hereto open new window/nCTRL Mouse wheel to zoom in/out';}"onmouseover="if(this.width>screen.width*0.7) {this.resized=true;this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Clickhere to open new window/nCTRL Mouse wheel to zoom in/out';}"onclick="if(!this.resized) {return true;} else{window.open('http://p.blog.iyunv.com/images/p_blog_csdn_net/superpan/7aa4c81c75ea4e7c97facc8bab74c2e8.jpg');}"onmousewheel="return imgzoom(this);" alt="" />
四、被监控端配置
大部分情况下,我们监控的是服务器,以RedHat Linux为例,看看如何打开SNMP服务。
只有开启了SNMP服务,监控端才可以收集数据。
打开默认的/etc/snmp/snmp.conf文件,更改如下配置:
1、查找以下字段:
代码:
# sec.name source community
com2sec notConfigUser default public
将"comunity"字段改为你要设置的密码.比如"bizcnpublic".
将“default”改为你想哪台机器可以看到你的snmp信息,如10.10.10.10。授权服务器IP
2、查找以下字段:代码:
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact systemview none none
将"read"字段改为all.
代码:
#access notConfigGroup "" any noauth exact all none none
3、查找以下字段:代码:
## incl/excl subtree mask
#view all included .1 80
将该行前面的"#"去掉.
4、查找以下字段:代码#
#name incl/excl subtree mask(optional)
添加一行view all included .1
变成
#name incl/excl subtree mask(optional)
view all included .1
4、查找一下字段:代码
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
将该行前面的"#"去掉.
保存关闭.
4、运行/etc/init.d/snmpd start命令运行snmpd.
5、如果有防火墙,打开UDP 161端口。
最后运行netstat -ln查看161端口是否打开了.
使用ntsysv,让snmp服务,每次开机自动运行。
如果没有安装snmp服务,请在RH的安装光盘上找到net-snmp.rpm,再安装。
五、测试
打开本机的SNMP服务,
打开http://IP/cacti
默认Cacti有LocalHost的四项参数,直接可以查看了。
六、排错
1. 首先检查一下rra/下面,有没有数据,如果没有检查rra/ log/的拥有者是不是cactiuser
2. snmpwalk -v 2c -c public ServerIP if 用来测试被控对象(serverIP)是否开启了SNMP服务
3. snmpwalk -v 2c ServerIP -c public .1.3.6.1.4.1.2021.10.1.3 查看被控端是否有CPU负载的数据返回
4. /usr/local/bin/php /home/wwwroot/cacti/poller.php 用来测试PHP是否可以采集到数据。如果上面的都正确,但这步出错,很有可能是PHP配置的问题,或开启了SuLinux。
5. 如果按第2步snmpwalk能采集到数据,但第3步无法采集,可能是PHP设置的问题,修改PHP.ini,很有可能是PHP权限问题。如果第4步正常而无法显示图,则可能是rra/ log/ 的Owner不对