1、设置mysql,创建Cacti数据库和账号
1
2
3
4
5
|
[root@nagios ~]# mysql -u root -p123456
mysql> create database cactidb;
mysql> GRANT ALL ON cactidb.* TO cactier@localhost IDENTIFIED BY ‘123456’;
mysql> flush privileges;
mysql> quit
|
2、安装rrdtool
1
|
[root@nagios ~]# yum -y install rrdtool rrdtool-devel rrdtool-php
|
3、安装配置snmp
1
2
3
4
5
|
[root@nagios ~]# yum install -y net-snmp net-snmp-utils net-snmp-libs
[root@nagios ~]# vi /etc/snmp/snmpd.conf
可修改community默认密码public
[root@nagios ~]# service snmpd restart
[root@nagios ~]# chkconfig snmpd on
|
4、下载安装Cacti
1
2
3
4
5
6
7
|
[root@nagios ~]# mkdir /home/nagios
[root@nagios ~]# cd /home/nagios
[root@nagios nagios]# wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
[root@nagios nagios]# tar xzf cacti-0.8.8b.tar.gz
[root@nagios nagios]# mv cacti-0.8.8b /var/www/html/cacti
[root@nagios cacti]# cd /var/www/html/cacti
[root@nagios cacti]# mysql -uroot -p cactidb < cacti.sql
|
5、配置参数
1
2
3
4
5
6
7
8
|
[root@nagios cacti]# vi /var/www/html/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cactier”;
$database_password = “123456”;
$database_port = “3306”;
#$url_path = “/cacti/”;
|
6、添加用户、修改权限和属主
1
2
3
4
5
6
|
[root@nagios cacti]# useradd cactier
[root@nagios cacti]# passwd cactier
#输入密码123456
[root@nagios cacti]# usermod -G cactier apache
[root@nagios cacti]# chown -R root:root /var/www/html/cacti/
[root@nagios cacti]# chown -R cactier:cactier rra/ log/
|
7、Apache设置
1
2
3
4
5
6
7
8
9
10
|
[root@nagios cacti]# vi /etc/httpd/conf/httpd.conf
<Directory “/var/www/html/cacti “>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
[root@nagios cacti]# vi /etc/php.ini
date.timezone=Asia/Shanghai
[root@nagios cacti]# service httpd restart
|
8、添加计划
每5分钟更新RRD图形,poller是单线程程序,可以改用支持多线程和分布式的工具spine
1
2
3
4
|
[root@nagios cacti]# crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php &> /dev/null
[root@nagios cacti]# service crond restart
[root@nagios cacti]# ntpdate 65.55.56.206
|
切换用户,手动执行后在rra目录下生成rrd图形文件
1
2
|
[root@nagios cacti]# su – cactier
[cactier@nagios cacti]# php /var/www/html/cacti/poller.php
|
也可以不执行手动操作,等待5分钟,观察rra目录下是否自动生成rrd文件
9、WEB页面初始化
http://localhost/cacti
用户名admin 密码admin
10、测试采集数据
(1)查看RRD文件中数据
1
2
3
|
[cactier@nagios cacti]# cd /var/www/html/cacti/rra
[cactier@nagios rra]# rrdtool fetch -r 300 localhost_mem_buffers_3.rrd AVERAGE
date +%s
|
– nan表示没有数据,每隔300秒获取一次数据。
(2)查看mysql中的更新时间
1
2
3
4
|
[cactier@nagios rra]# mysql -uroot -p123456
mysql>use cactidb;
mysql>select * from poller_time;
mysql>quit
|
正常的话是每五分钟更新
(3)采集不到数据怎么办
在网页上清除缓存system utilities –>Rebuild poller cache
修改RRA权限#chmod 777 -R /srv/www/htdocs/cacti/rra
同步系统时间#ntpdate 65.55.56.206
(4)测试snmp抓取数据
1
|
[root@nagios ~]# snmpwalk -v 2c -c public <目标机器IP> system
|
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/56319.html