搭建cacti监控

首先搭建LAMP环境

#yum -yinstall gcc gcc-c++ autoconf libjpeg libjpeg-devel libpnglibpng-devel freetype freetype-devel libxml2 libxml2-devel zlibzlib-devel glibc glibc-devel glib2 gd gd-devel glib2-devel bzip2bzip2-devel ncurses ncurses-devel curl curl-devel opensslopenssl-devel libmcrypt-devel libtoollibtool-devel


安装mysql

#yum installbison

#tar -zxfcmake-2.8.4.tar.gz

#./configure

#gmake

#makeinstall




#tar -zxfmysql-5.5.14.tar.gz

#cmake./

#make

#makeinstall



#cpmy-medium.cnf /etc/my.cnf

#cpmysql.server /etc/init.d/mysqld

# chmod 770/etc/init.d/mysqld



#chmod +w/usr/local/mysql

#chown -Rmysql:mysql /usr/local/mysql

#mkdir -p/data/mysql/data/

#chown -Rmysql:mysql /data/mysql/


#vim/etc/my.cnf

加入以下内容

user =mysql

basedir =/usr/local/mysql

datadir =/data/mysql/data

log-error =/data/mysql/mysql_error.log

pid-file =/data/mysql/mysql.pid



#./scripts/mysql_install_db --user=mysql--datadir=/data/mysql/data--basedir=/usr/local/mysql

#ln -s/usr/local/mysql/bin/mysql /bin/

#/etc/init.d/mysqld start

#/usr/local/mysql/bin/mysqladmin -u root password123456




安装httpd

# useradd www-s /sbin/nologin

#tar -jxvfhttpd-2.2.24.tar.bz2

#./configure--prefix=/usr/local/apache --enable-module=so--enable-deflate=shared --enable-expires=shared--enable-rewrite=shared --enable-cache --enable-file-cahe--enable-mem-cache --enable-disk-cache --enable-static-support--enable-ssl --enable-so

#make&& make install

#ln -s/usr/local/apache/bin/apachectl /etc/init.d/httpd

#/etc/init.d/httpd start



安装PHP


# tar -zxvfphp-5.3.6.tar.gz

#./configure--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache/bin/apxs--with-mysql=/usr/local/mysql/--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--enable-safe-mode --enable-mbstring --with-gd--enable-gd-native-ttf --with-openssl --enable-zip--enable-sockets

# make&& make install

# cpphp.ini-development /usr/local/php/etc/php.ini

查看是否生成PHP模块

# ls/usr/local/apache/modules/ |grep php

libphp5.so


#vim/usr/local/apache/conf/httpd.conf

找到AddType模块处添加

AddTypeapplication/x-httpd-php-source .phps

AddTypeapplication/x-httpd-php .php .phtml

index.html前添加index.php



更改用户

www

更改主目录路径

/data/www/htdocs

更改日志路径

/data/www/logs/access_log

/data/www/logs/error_log




# chownwww:www /data/www/ -R

#/etc/init.d/httpd -k restart


测试

http://IP/index.php

 

出现PHP测试页说明LAMP环境搭建完成


部署CACTI


安装rrdtool

# yum installcairo-devel libxml2-devel pango-devel pango libpng-devel freetypefreetype-devel libart_lgpl-devel pear pear-devel


#tar -zxvfrrdtool-1.4.7.tar.gz

#./configure--prefix=/usr/local/rrdtool/

#make&& make install


安装snmp

# yum installnet-snmp net-snmp-devel net-snmp-libsnet-snmp-utils

# chkconfig--level 3 snmpd on

#/etc/init.d/snmpd start

# vim/etc/snmp/snmpd.conf

修改如下

# sec.namesource community

40 # sec.namesource community

41 com2secnotConfigUser 127.0.0.1 public



61 # groupcontext sec.model sec.level prefix read writenotif

62 accessnotConfigGroup "" any noauth exact all nonenone



84 ##incl/excl subtree mask

85 view allincluded .1 80


#/etc/init.d/snmpd restart

# $ snmpwalk-v 2c -c public 127.0.0.1 if //测试





安装cacti

解压cacti,移动到/data/www/

#tar -zxvfcacti-0.8.7g.tar.gz

#mvcacti-0.8.7g /data/www/cacti

#chown www:www/data/www/cacti/ -R


cacti添加别名

# vim/usr/local/apache/conf/httpd.conf

在最下增加如下

Alias /cacti/"/data/www/cacti/"

 

AllowOverrideNone

OptionsNone

Orderallow,deny

Allow fromall

 

或者添加虚拟主机


mysql中创建cacti数据库,并授权给用户


mysql> create databasecacti;

mysql> grant all on cacti.* tocactiuser@localhost identified by 'cactipwd';

mysql> flush privileges;




导入数据库

# mysql-ucactiuser -pcactipwd cacti < cacti.sql                

如有报错,执行以下即可

#vimcacti.sql                                                        

:%s/TYPE=MyISAM/ENGINE=MyISAM/g

修改cacti配置脚本

# viminclude/config.php

主要修改与mysql的连接


安装

先做软连接

#ln -s/usr/local/rrdtool/bin/rrdtool /usr/local/bin/

#ln -s/usr/local/php/bin/php /usr/bin/

添加timezone

更改php时区

编辑php.ini,将timezone改成PRC

http://IP/cacti/install

这里基本不会报错了,如果有文件没找到,最软链接即可解决


点击finish,出现登陆界面,默认账号口令都是admin

#crontab–e

*/5 * * * */usr/bin/php /data/www/cacti/poller.php2>&1


注:此lamp环境加cacti-0.8.7g,问题很多,而且目前为止,就算全解决,还有一个最重要的,就是不装spine不出图,所以下面要装spine

安装spine

#tar -zxvfcacti-spine-0.8.7g.tar.gz

#aclocal

#libtoolize--force

#autoconf

#autoheader

#automake

#./configure--prefix=/usr/local/spine--with-mysql=/usr/local/mysql

#make&& make install

#cd/usr/local/spine/etc/

#cpspine.conf.dist spine.conf

#vimspine.conf

#ln -s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/

#./spine

SPINE: Usingspine config file [../etc/spine.conf]

SPINE: Version0.8.7g starting

SPINE: Time:0.1604 s, Threads: 1, Hosts: 2

/usr/local/spine/bin/spine


测试命令:

# /usr/bin/php-q /data/www/cacti/poller.php --force --debug                 //测试生成rra文件情况


# snmpwalk -v2c -c public 127.0.0.1 if                                            //测试snmp


#/usr/local/rrdtool/bin/rrdtool fetch localhost_hdd_free_10.rrdAVERAGE    //打开rra文件,看里面数据



Cacti插件安装

1.cacti-plugin

#tar -zxvfcacti-plugin-0.8.7g-PA-v2.8.tar.gz

# cpcacti-plugin-0.8.7g-PA-v2.8.diff /data/www/cacti/

# cp pa.sql/data/www/cacti/

#patch -p1 -N< cacti-plugin-0.8.7g-PA-v2.8.diff//打补丁

#vim pa.sql//%s/TYPE=MyISAM/ENGINE=MyISAM/g

#mysql-ucactiuser -pcactipwd cacti <pa.sql

#vim/data/www/cacti/include/global.php //$config['url_path'] ='/cacti/';



2.安装setting

#tar -zxvfsettings-v0.71-1.tgz

#mv settings/data/www/cacti/plugins/


3.安装monitor

# tar -zxvfmonitor-v1.3-1.tgz

# mv monitor/data/www/cacti/plugins/

# mysql-ucactiuser -pcactipwd cacti <monitor.sql

# vim/data/www/cacti/include/config.php

$plugins =array();

$plugins[] ='settings'; //添加setting插件

$plugins []='monitor'; //添加monitor插件

 

继续点击启动,方法同setting




报错解决方法(部分有效):


1.导入cacti.sql时提示:TYPE=MyISAM不对

cacti.sql里面所有的TYPE=MyISAM 替换成 ENGINE=MyISAM

mysql5.5取消了type 只能用engine!!否则会出现以下错误:

ERROR 1064(42000) at line 5: You have an error in your SQL syntax; check themanual that corresponds to your MySQL server version for the rightsyntax to use near 'TYPE=MyISAM' at line 6

命令为:

vi/var/www/html/cacti/cacti.sql

然后输入:

:1,%s/TYPE=MyISAM/ENGINE=MyISAM/g

或者 :1,%s/TYPE=MyISAM/ENGINE=MyISAM/gc多了个提示对话框

最后重启:/usr/local/apache2/bin/apachectl restart



2.session_start(): Failed to initialize storagemodule


解决方法1

#vimphp.ini

将如下0修改成1

session.auto_start = 1



解决方法2

在报错的文件里的sessionstart();之前加入如下代码:ini_set(‘session.save_handler’, ‘files’);


解决方法3

php.ini文件里,显式指定sessionsave_path(比如 /temp)然后重启web服务。



解决方法4

session_start前面增加上面的内容

if(!is_dir(’./tmp/’))mkdir (’./tmp/’,0700);

session_save_path(’./tmp/’);

session_start();



解决方法5

/tmp目录所属组修改www




3.进入ip/cacti时区错误


解决方法1

date_default_timezone_set('Asia/shanghai');

就加在

$database_type= "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cactiuser";

$database_password = "cactiuser";

$database_port= "3306";

date_default_timezone_set('Asia/shanghai');//手动添加

重启生效apache/usr/local/apache2/bin/apachectl restar


解决方法2

修改/etc/php.ini

找到date.timezone,去掉前面的注释并

 

改为

 

date.timezone = PRC

 

 

date.timezone= Asia/Shanghai


4.打补丁之后,图片无法正常显示

# vim/data/www/cacti/include/global.php


if (!isset($url_path)) {

$url_path ="";

}

$config['url_path'] ='/cacti/';

define('URL_PATH', $url_path);





5.安装插件后,日志中提示数据库错误

修复 //修复时会提示缺少libmysqlclient.so.15,如果没有可以cp过来

# mysqlcheck--repair cacti -u root –p //修复索引



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值