lnmp环境下cacti搭建
实验过程中关闭防火墙和selinux1
2
service iptables stop
setenforce 0
官网下载cacti相关软件
1
root@localhost file]# wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.5.tar.gz
安装rrdtool采集工具
安装rrdtool之前需要安装相应的lib库,如下安装:
1
yum install cairo-devel libxml2-devel pango pango-devel perl-devel -y
1
2
3
tar xzf rrdtool-1.4.5.tar.gz;cd rrdtool-1.4.5;
./configure --prefix=/data/local/rrdtool/;make&&make install
ln -s /data/local/rrdtool/bin/* /usr/local/bin/
安装SNMP服务
1
yum install net-snmpnet-snmp-utils-y
安装cacti主程序
1
tar xzf cacti-0.8.8a.tar.gz && mvcacti-0.8.8a /usr/local/nginx/html/
创建cacti数据库
1
service mysqld restart
mysql 进入创建数据库:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql -u root -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.60 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
创建数据库
1
2
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
创建用户并授权
1
2
mysql> grant all on cacti.* to cacti@'localhost' identified by "123456";
Query OK, 0 rows affected (0.00 sec)
刷新权限
1
flush privileges;
把数据导入到数据库:
1
2
3
mysql -u cacti -p cacti < cacti
/cacti
.sql
配置php的数据库连接部分,改用户名和密码
1
# vim /usr/local/nginx/html/cacti-0.8.8a/include/config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2012 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See|
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
/*
Edit this to point to the default URL of your Cacti install
ex: if your cacti install as at http://serverip/cacti/ this
would be set to /cacti/
*/
//$url_path = "/cacti/";
/* Default session name - Session name must contain alpha characters */
//$cacti_session_name = "Cacti";
?>
1
2
# chmod -R 777 /usr/local/nginx/html/cacti/rra/
# chmod -R 777 /usr/local/nginx/html/cacti/log/
重启网站服务 service nginxd restart
添加Rrdtool抓图任务计划
1
crontab -e
1
*/1* * * * /usr/bin/php /usr/local/nginx/html/cacti/poller.php >>/tmp/cacti_rrdtool.log 2 >&1
启动smmp
1
2
3
4
5
6
# /etc/init.d/snmpd restart
停止 snmpd: [失败]
正在启动 snmpd: [确定]
# /etc/init.d/snmptrapd restart
停止 snmptrapd: [失败]
正在启动 snmptrapd: [确定]
浏览器里面查看安装
http://192.168.72.250/cacti/install/
有界面提示进行全新安装 安装后添加devices graph trees,再查看devices里面的status状态是否为up,up才算成功,
如果一直是unkown,那么可以
测试snmp返回数据的是否正确:
snmpwalk -v2c -c public localhost
手动抓图后再观察status是否为up:
1
/usr/bin/php /usr/local/nginx/html/cacti/poller.php
添加一个远程主机
在远程主机上安装snmpd服务
yum install net-snmpnet-snmp-utils-y
修改配置文件vi /etc/snmp/snmpd.conf
vi/etc/snmp/snmpd.conf,我们只需要更改:62行把他改为:
access notConfigGroup "" any noauth exactallnonenone
第二:我们需要更改42行为:
com2sec notConfigUser 192.168.1.16 public #注意:如果是服务器端这里的IP要改成你要监控的远程客户端的IP
(其中192.168.1.16 ip 表示你允许那台服务器可以监控你。public 表示团体名)
第三:我们还要更改:86行:把#号去掉:变成如下即可
view all included.1 80
最后重启snmpd服务ok :
service snmpd restart
如果发现监控的主机不出图,状态始终为unkown.那就同步下时间。
yum install -y ntpdate
ntpdate us.pool.ntp.org
然后清空掉 /usr/local/nginx/html/cacti/rra下抓取的数据
手动抓取下 /usr/bin/php/usr/local/nginx/html/cacti/poller.php
再看下/usr/local/nginx/html/cacti/rra下 是否有远程主机的IP开头的文件
比如 192_168_1_17_hdd_free_100.rrd
localhost_traffic_in_35.rrd
此时应该有图了
排错:有图无数据
vi/usr/local/php/php.ini
将php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时取消这一行代码的注释,即去掉前面的分号就可以了。
tail -f /var/log/cron
tail -f /var/spool/mail/root 即可查看最近的crontab执行情况 这里的值有数据 Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:26 RRDsProcessed:
代表抓取成功了
注意RRA目录下面的文件都是每隔1分钟产的数据才算成功。
页:
[1]