设为首页 收藏本站
查看: 1746|回复: 0

[经验分享] lnmp环境下cacti搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-25 09:59:47 | 显示全部楼层 |阅读模式
实验过程中关闭防火墙和selinux

1
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-snmp  net-snmp-utils  -y



安装cacti主程序
1
tar xzf cacti-0.8.8a.tar.gz && mv  cacti-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
[iyunv@localhost ~]# 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
[iyunv@localhost ~]# chmod -R 777 /usr/local/nginx/html/cacti/rra/
[iyunv@localhost ~]# 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
[iyunv@localhost ~]# /etc/init.d/snmpd restart
停止 snmpd:                                               [失败]
正在启动 snmpd:                                           [确定]
[iyunv@localhost ~]# /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-snmp  net-snmp-utils  -y  
修改配置文件vi /etc/snmp/snmpd.conf
vi  /etc/snmp/snmpd.conf,我们只需要更改:62行把他改为:
access   notConfigGroup   ""    any   noauth    exact  all  none  none
第二:我们需要更改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分钟产的数据才算成功。
QQ截图20160725095934.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-249030-1-1.html 上篇帖子: cacti安装配置及邮件告警 下篇帖子: 找不到已经有的模板
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表