红联Linux门户
Linux帮助

CentOS 6.4搭建Cacti中遇到的问题及解决

发布时间:2015-04-02 22:24:46来源:linux网站作者:zyx1990zm

我在CentOS 6.4下搭建一个Cacti,本来感觉很容易,可是后来感觉都快赶上红军长征了,下面我来介绍一下我在搭建cacti的过程中,出现的的问题及解决方法。

1.安装snmp软件不成功,总是说缺一些插件,都有什么没有安装,最后被我攻克了

yum -y install lm_sensors net-snmp net-snmp-utils

2.安装rrdtool报错

首先要把rrdtool所需要的依赖包安装好,否则,总是报错

yum -y install cairo-devel glib2-devel pango-devel intltoolwget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz

./configure --prefix=/usr/local

make &&  make install

然后就是下载cacti的安装包了

wget http://www.cacti.net/downloads/cacti-0.8.7i.tar.gz

tar -zxvf cacti-0.8.7i.tar.gz

cp -r cacti-0.8.7i /usr/local/nginx/html/cacti  # 复制到html目录

useradd cactiuser -M -s /sbin/nologin          # 创建cacti用户

chown -R cactiuser.cactiuser /usr/local/nginx/html/cacti/rra/ # 改变属主和属组

chown -R cactiuser.cactiuser /usr/local/nginx/html/cacti/log/

然后创建数据库:

create database cactidb default character set utf8;  #创建数据库

grant all on cactidb.* to cactiuser@localhost identified by '123456'; # 创建一个mysql用户

use cactidb  # 使用刚才创建的数据库

source /usr/local/nginx/html/cacti/cacti.sql # 导入cacti数据

接下来我们编辑cacti配置文件/usr/local/nginx/html/cacti/include/config.php

cd /usr/local/nginx/html/cacti/

vi include/config.php

编辑下面内容:

$database_type="mysql";            # 数据库类型

$database_default="cactidb";      # 数据库名字

$database_hostname="localhost";    # 数据库主机

$database_username="cactiuser";    # 数据库用户

$database_password="123456";      # 数据库密码

$database_port="3306";            # 数据库端口

$database_ssl=false;然后修改nginx配置文件像下面:

vi /usr/local/nginx/config/nginx.conf

location / {
root  html;
index  index.php;
}
location ~ \.php$ {
fastcgi_pass        127.0.0.1:9000;
fastcgi_index      index.php;
include fastcgi.conf;
fastcgi_buffers 8 8k;
fastcgi_buffer_size 8k;
}

后两条一定要加上,否则会报请求的页面过大之类的,不过,这样设置之后这个网站只能用来查看cacti了。

重启nginx

service nginx restart

然后设置php时区,

cd /usr/local/nginx/html/cacti/vi include/global_constants.php

如果不写时区的话,会在访问cacti的页面上出现日志

It is not safe to rely on the system's timezone settings

在写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 'UTC' for '8.0/no DST' instead in D:\PHPWEB\news\file.php on line 17 。

这是因为PHP所取的时间是格林威治标准时间,所以和你当地的时间会有出入格林威治标准时间和北京时间大概差8个小时左右,我们可以按照下面的方法解决:

1、在页头使用date_default_timezone_set()设置我的默认时区为北京时间,即<?phpdate_default_timezone_set("PRC");?>就可以了。

2、在php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时取消这一行代码的注释,即去掉前面的分号就可以了。

或在第二行添加

date_default_timezone_set("Asia/Chongqing");

接下来配置snmp,编辑/etc/snmp/snmpd.conf

vi /etc/snmp/snmpd.conf

然后找到41行将public改成一个较为复杂的名字:

com2sec notConfigUser  default      public

然后找到62行

access  notConfigGroup ""      any      noauth    exact  systemview none none

将systemview改成all:

access  notConfigGroup ""      any      noauth    exact  all none none

然后去掉85行的注释:

view all    included  .1                              80

保存配置文件后启动snmp

service snmpd start

时区的问题解决了,可是出现了令一个bug:

Error

The following PHP extensions are missing:

* sockets

Please install those PHP extensions and retry

到网上一搜索,原因是在编译php时没有配置socket支持

解决方法一:重新编译php

解决方法二:单独编译socket模块,之后手动为php添加此模块。

编译php时需要加上参数./configure --enable-sockets

可以通过#php -m查看可以有sockets支持,如果支持的话php -m后会输出sockets

如果编译时没有添加,也不需要LAMP环境都重新配置。

方法:

1、进入php源文件下ext/sockets目录

[root@68Q ~]# cd /aa/php-5.3.6/ext/sockets/

2、执行命令

[root@68Q ~]# /usr/local/php5/bin/phpize

3、编译安装

[root@68Q sockets]# ./configure --enable-sockets --with-php-config=/usr/local/php5/bin/php-config

make

make install

4、配置php.ini

[root@68Q ~]# ll /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/

总用量 96

-rwxr-xr-x 1 root root 97482 9月  11 17:32 sockets.so

[root@68Q ~]#

[root@68Q ~]# vi /usr/local/php5/php.ini

搜索extension,并添加扩展模块引用

extension_dir =  "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/"

extension = sockets.so

5、检查php.ini配置文件正确性

/usr/local/php5/bin/php -v

6、检查已安装模块

/usr/local/php5/bin/php -m

7、重启php-fpm

killall php-fpm

/usr/local/sbin/php-fpm

cacti生成不了图像,这样处理;根据自己的路径来设置一下。

[root@68Q sockets]# /usr/local/php5/bin/php -q /usr/local/nginx/html/cacti/poller.php --force -d

还有客户端的SNMP服务器是否有问题

至此,这样就能访问了。