Devops>监控系统>正文 cacti监控系统的配置过程

1、安装mysql 

tar zxvf mysql-5.0.41-linux-i686-icc-glibc23.tar.gz

groupadd mysql 
useradd -g mysql mysql 
cd /usr/local
chown -R mysql:mysql mysql
cd mysql 
scripts/mysql_install_db --user=mysql 
chown -R root . 
chown -R mysql data 
chgrp -R mysql . 
cp a ./mysql-5.0.41-linux-i686-icc-glibc23 /usr/local/mysql
cp support-files/my-medium.cnf  /etc/my.cnf
 
vi /etc/my.cnf
[mysqld]部分下添加:
datadir = /var/lib/mysql
 
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 3 mysql on
service mysql start
 
/usr/local/mysql/bin/mysqladmin u root password 123456

2
apache 

tar –zxvf  httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/usr/local/apache2 --enable-module=so --enable-rewrite
make && make install
 
cp support/apachectl  /etc/init.d/httpd
 
vi /etc/init.d/httpd
加入:
 
# Startup script for the Apache Web Server
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd         
# pidfile: /usr/local/apache2/log/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
 
chmod 755 /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 3 httpd on
mkdir –p /var/log/httpd/access_log
service httpd start
 

3
php
cd php-5.2.4
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf \
--with-zlib-dir=/usr/lib --with-png-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 --with-ttf \
    --enable-sockets --enable-ftp --enable-mbstring
make && make install
#httpd
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
 
cp php.ini-dist /usr/local/php/php.ini 
vi  /usr/local/apache2/conf/httpd.conf 
加入: 
###############for php and cacti################### 
AddType application/x-tar .tgz 
AddType application/x-httpd-php .php 
AddType image/x-icon .ico 
DirectoryIndex index.php index.html index.html.var 
#######################over######################## 

service httpd start

4
mysql
 /usr/local/mysql/bin/mysql -u root –p123456

create database cactidb; 

grant all on cactidb.* to root; 


grant all on cactidb.* to root@localhost; 

grant all on cactidb.* to cactiuser; 

grant all on cactidb.* to cactiuser@localhost; 

set password for cactiuser@localhost=password('cactipw'); 
exit

5
rrdtool
./configure
make && make install 
即可
mrtg相比,rrdtool自带了gd,所以不用先安装gd.(不过由于rrdtool自带的gd库不支持中文,所以rrdtool画出来的图也不能有中文,否则会出现乱码).

注意:rrdtool1.2的版本由于已经不再自带外部的lib库(如cgilibzlib等),所以需要从http: //people.ee.ethz.ch/~oetiker/webtools/rrdtool/pub/libs/下载这些库来安装。建议还是使用 1.0的版本,比较方便。

6
、安装net-snmp
几乎所有的网络设备和操作系统默认都安装了snmp服务。
unix
系统安装的都是net-snmpucd-snmp(其实两个都是同一组人写的)
如果没有安装snmp,可以到net-snmp.sourceforge.org上下载源码编译安装。
我这里说的安装SNMP服务并不是要求安装SNMPD,其实是Cacti需要用到net-snmp中的两个命令――snmpwalksnmpget进行数据的采集。

我们可以直接在系统中运行snmpwalksnmpget看是否有该命令,如果有则不用安装了。

7
、安装cacti 

cp cacti-0.8.6c.tar.gz /usr/local/apache2/htdocs/
tar xzvf cacti-0.8.6c.tar.gz 
mv cacti-0.8.6c cacti 
cd cacti
/usr/local/mysql/bin/mysql –u root –prootroot cactidb < cacti.sql 
chown –R cactiuser rra/ log/

设置配置文件:
vi /usr/local/apache2/htdocs/cacti/include/config.php 

$database_type = “mysql”;    
$database_default = “cactidb”;                  //(cacti
数据库名)
$database_hostname = “localhost”; 
$database_username = “cactiuser”;              //
cacti数据库用户)
$database_password = “cactipw”;               //cacti数据库密码)

Crontab –u cactiuser –e 
cactiuser用户加入 
*/5 * * * *  /usr/local/php/bin/php /usr/local/apache2/htdocs/cacti/poller.php >; /dev/null 2>;&1

(不要使用root用户运行上面的命令,否则要再运行一次chown –R cactiuser rra/ log/

8
、页面设置: 

在浏览器上输入: 
http://IP/cacti 
进入cacti的初始设置页面: 
在这里我们要输入一些原始的信息: 

/usr/bin/snmpwalk
/usr/bin/snmpget
/usr/bin/snmpgetnext
/usr/local/rrdtool-1.0.50/bin/rrdtool
/usr/bin/snmpbulkwalk
/usr/local/php/bin/php
/usr/local/apache2/htdocs/cacti/log/cacti.log
 
 

输入一些信息,如rrdtoolphpsnmpwalksnmpget的位置,使用ucd-snmp还是net-snmp等 -》 
输入原始的用户和密码:admin/admin -》 
更改admin用户的密码 -》 
点击 Save 

打开默认的/etc/snmp/snmpd.conf文件,更改如下配置:


1
、查找以下字段:
#       sec.name  source          community
com2sec notConfigUser  default       public

"comunity"字段改为你要设置的共同体名.比如"public".
                                                
“default”改为你想哪台机器可以看到你的snmp信息,10.10.10.10

2
、查找以下字段:
# Finally, grant the group read-only access to the systemview view.


#       group          context sec.model sec.level prefix read   write  notif
 
 
#access  notConfigGroup ""      any       noauth    exact  systemview none none
改成:

access  notConfigGroup ""      any       noauth    exact  all none none

"read"字段改为all.

3
、查找以下字段:
##           incl/excl subtree                          mask
#view all    included  .1                               80

将该行前面的"#"去掉.


保存关闭.


4
、运行/etc/init.d/snmpd start命令运行snmpd.

最后运行netstat -ln查看161端口是否打开了.



rrdtool fetch yourRRDfile.rrd AVERAGE
 
 
 
1,  首先要下载Plugin Architecture,这个使得cacti可以使用插件,目前的版本是2.1下载地址是http://cactiusers.org/downloads/cacti-plugin-arch.tar.gz

注意:要下与自己监控系统的版本相同的插件,否则patch不成功
安装:
cd cacti-plugin-arch
mv  cacti-plugin-0.8.7b-PA-v2.1.diff/usr/local/apache2/htdocs/cacti
cd /usr/local/apache2/htdocs/cacti
patch -p1 -N < cacti-plugin-0.8.7b-PA-v2.1.diff //
进行patch

配置
vi /usr/local/apache2/htdocs/cacti/include/global.php
找到$config['url_path'] = "/";这行
如果你的cacti安装路径是
http://servername/projects/cacti/testing/
那就需要把这个参数改成
$config['url_path'] = "/projects/cacti/testing/";
如果你的cacti安装路径是
http://servername/cacti/
那这个参数就应该是
$config['url_path'] = "/cacti/";
 
2,接下来下载Monitor这个插件,目前最新版本0.8.2,地址:http://cactiusers.org/downloads/monitor.tar.gz
tar zxvf monitor.tar.gz -C /usr/local/apache2/htdocs/cacti/plugins
解压完毕后进入到/usr/local/apache2/htdocs/cacti/plugins/monitor目录
执行mysql -u root -p cactdbi <monitor.sql   //cactidb是数据库名
然后编辑cacti目录下的include/global.php文件
$plugins = array(); 
找到这行,然后在他的下面添加
$plugins[] = 'monitor';
保存退出后就重启apache就可以看到monitor了。

本文转自wiliiwin 51CTO博客,原文链接:
http://blog.51cto.com/wiliiwin/199204
上一篇:解密阿里云大规模深度学习性能优化实践


下一篇:《工业控制网络安全技术与实践》一2.6.3 电力行业的工业控制网络