一、监控端安装
1)基础软件:安装配置cacti前,需要安装:httpd、php、mysqld、php-mysql、net-snmp、rrdtool
以上均可使用yum安装:
yum install -y httpd
yum install -y php
yum install -y mysql-server
yum install -y php-mysql
yum install -y net-snmp
yum install -y rrdtool
2)cacti安装
wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
tar xzvf cacti-0.8.8c.tar.gz
mv cacti-0.8.8c /var/www/html/cacti
cd /var/www/html/cacti/
创建cactidb库,并导入相关表:
mysql> create database cactidb;
mysql -u root -p cactidb<cacti.sql (cacti.sql在cacti安装包目录下)
创建数据库用户
shell> mysql -uroot -p mysql
mysql> GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
mysql> flush privileges;
vi /var/www/html/cacti/include/config.php
修改数据库配置:
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = " cactiuser "; //对应前面创建的mysql用户
$database_password = "cactipassword "; //对应前面创建mysql用户的密码
$database_port = "3306";
$database_ssl = false;
访问:http://IP/cacti进行首次安装配置:
配置:RRDTool Binary Path为:/usr/local/rrdtool/bin/rrdtool
第一次默认登陆账号:admin 密码 admin
登陆后它就会让你立即修改新密码
登录cacti后,也可以在Configuration-Settings-Paths中进行配置
手动执行:php -f /var/www/html/cacti/poller.php
执行如果成功,把*/5 * * * * root php -f /var/www/html/cacti/poller.php >/dev/null 2>&1增加到/etc/crontab中,每5分钟进行一次数据采样;
安装完成后启动对应服务
/etc/init.d/httpd start
/etc/init.d/mysqld start
/usr/sbin/snmpd
二、被监控端安装
1)yum install -y net-snmp
2)配置文件替换
3)启动服务:/usr/sbin/snmpd
三、使用
1)新建设备:Console -> Devices:
2)增加图像:Console->Create->New Graphs
3)图像树管理:Console->Management->Graph Trees->Default Tree->Add
4)添加监控项: Console->Management->Graph Trees->Default Tree-> Tree Items
四、定制需要
1)负载资源将累加区域型修改为线性的图表
----Graph Templates,选择ucd/net - Load Average,Item #1 >>Line1;Item #3 >>Line3;Item #3 >>Line3
四-1、安装mail插件
wget http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz
wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz
wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz
tar xf settings-v0.7-1.tar.gz -C /var/www/html/cacti/plugins/
tar xf thold-v0.5.0.tar.gz -C /var/www/html/cacti/plugins/
tar xf monitor-v1.2-1.tgz -C /var/www/html/cacti/plugins/
五、踩坑合集
1)ip/cacti的web页面无法打开
---系统会默认开启防火墙,关闭:/etc/init.d/iptables stop;可添加至/etc/rc.local系统重启的时候会直接关闭
---http服务未启动,service httpd restart
2)php -f /var/www/html/cacti/poller.php执行报时区错误,现象如下:
[root@localhost scripts]# php -f /var/www/html/cacti/poller.php
PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /var/www/html/cacti/include/global_constants.php on line 165
---解决方案:
vim /etc/php.ini
date.timezone = Asia/Shanghai
再重启http服务:service httpd restart
3)net-snmp 已经安装,为什么没有snmpwalk和snmpget?执行snmpwalk的时候报错
---确保安装这几个包
# rpm -qa |grep snmp
net-snmp-5.1.2-11.EL4.7
net-snmp-libs-5.1.2-11.EL4.7
net-snmp-devel-5.1.2-11.EL4.7
net-snmp-utils-5.1.2-11.EL4.7
net-snmp-perl-5.1.2-11.EL4.7
4)如何确认被监控端机器是否正确部署
---在监控端执行:snmpwalk -v 2c -c public 172.20.0.1 //172.20.0.1为被监控端的IP
有返回监控数据则表示可以正常进行监控
5)监控端和被监控端正确部署,但是graphs却无法显示对应的图表和数据
5.1)确认采集任务是否定时执行,/var/log/cron的日志中确定; 或者手动执行采集数据脚本后看看是否有图表和数据【php -f /var/www/html/cacti/poller.php】
5.2)采集任务有执行,确认是否可以正常采集数据:snmpwalk -v 2c -c public 127.0.0.1
5.3)/var/www/html/cacti/rra下执行:rrdtool fetch 3-172_20_0_20_traffic_in_42.rrd AVERAGE
结果都是nan。有snmpd进程,snmpwalk有数据,rrd也正常画,但fetch却全是nan,突然想到会不会因为poller没有办法拿到数据,所以获取到的数据全是nan,而rrd直接把nan给画了上去。所以造成了有数据,但却没有图的结果
不出图不出数据排查步骤总结:
a.图像没有生成,运行 # /usr/bin/php /usr/share/cacti/poller.php
b.权限问题,修改权限 #chmod 777 -R /var/www/html/rra /var/www/html/log/
c.snmp配置问题,检测是否有数据输出 #snmpwalk -v2c -c public 127.0.0.1
d.删除rra下所有文件,清除缓存 #system utilities –>Rebuild poller cache
e.系统时间不准确,重新设置时间
f.数据库表有损坏,修复 #mysqlcheck -ao cacti -auto-repair -uroot -p
g.尝试重启snmpd服务 #service snmpd restart
6)添加devices后,提示snmp error:
第一,确定cacti所有的主机能ping通被监控主机;如果不能ping通,请确认网络配置和被监控主机的ip设置是否正确。
第二,如果能ping通,那么确认被监控主机是否启用snmpd服务:
ps -ef | grep snmp
或者直接重启被监控主机的snmp服务:
rcsnmpd restart
若上面的命令不可用,则用这两个:
service snmpd reload
service snmpd restart
然后到cacti服务器上,用root用户:
snmpwalk -c public -v 2c 192.168.124.14 --> (这个ip为被监控主机的ip)
如果能够接收到被监控机器的数据信息,则表示被监控主机的snmp配置已经完成,没有错误。如果没有接收到被监控主机的数据信息,那么进行第三步操作。
第三,用root登录被监控主机,修改snmp的配置文件:
vi /etc/snmp/snmpd.conf
最后配置如下:
syslocation Server Room
syscontact Sysadmin (root@localhost)
rocommunity public 127.0.0.1
agentaddress 161
rocommunity public
rwcommunity private
trapsink 192.168.124.14 public 162 --> 这里的ip=192.168.124.14为被监控主机ip
然后,再执行第二步操作即可。
7)执行/usr/bin/php /var/www/html/cacti/poller.php,报错如下:
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /var/www/html/cacti/include/global_arrays.php on line 676
解决办法:vim /etc/php.ini
date.timezone =PRC
8)部署完成后,打开浏览器,页面提示:FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'
数据库信息配置错误,数据库名、数据库连接用户名、数据库连接密码检查一下
安装脚本:
#!/bin/sh echo "安装包与安装脚本放在同一个目录下" ###定义安装失败判断### function check_if_fail() { if [ $? = 0 ] ; then echo "$1成功!" else echo "Error!" echo "******$1出现ERROR,请尝试手动排查解决!******" exit 1 fi } ###网络检查是否可以ping通百度### ping -c 2 -w 2 www.baidu.com if [[ $? = 0 ]];then echo "^_^可以正常 ping通百度^_^" else echo "-_-Error!无法正常ping通百度,请手动排查解决后再重新执行脚本-_-" exit 1 fi ###定义安装### function do_install() { rpm -q --quiet $1 if [ $? == 0 ]; then echo "*发现已安装$1" else echo "未安装$1,进行安装..." yum install -y $1 fi } echo "##########install httpd、php、mysqld、php-mysql、net-snmp、rrdtool##########" do_install "httpd" do_install "php" do_install "mysql-server" do_install "php-mysql" do_install "net-snmp" do_install "rrdtool" do_install "net-snmp-libs" do_install "net-snmp-devel" do_install "net-snmp-utils" do_install "net-snmp-perl" echo "#####install cacti#####" #wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz tar xzvf cacti-0.8.8a.tar.gz mv cacti-0.8.8a /var/www/html/cacti echo "#####create cactidb,import tables#####" cd /var/www/html/cacti/ mysql -uroot -e "drop database if exists cactidb;" mysql -uroot -e "create database cactidb;" mysql -uroot -e "use cactidb;source /var/www/html/cacti/cacti.sql;" echo "#####create dbuser#####" mysql -uroot -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';" mysql -uroot -e "flush privileges;" echo "edit cacti config.php" sed -i 's/$database_password = "cactiuser";/$database_password = "cactipassword";/g' /var/www/html/cacti/include/config.php sed -i 's/$database_default = "cacti";/$database_default = "cactidb";/g' /var/www/html/cacti/include/config.php echo "#####start mysql/httpd/snmpd#####" /etc/init.d/mysqld restart /etc/init.d/httpd restart /usr/sbin/snmpd /etc/init.d/iptables stop echo "#####write to rc.local#####" echo "/usr/sbin/snmpd" >> /etc/rc.local echo "/etc/init.d/httpd start" >> /etc/rc.local echo "/etc/init.d/mysqld start" >> /etc/rc.local echo "/etc/init.d/iptables stop" >> /etc/rc.local echo "^_^cacti install success!!" echo "URL: http://IP/cacti"