Cacti简单安装详细步骤

服务器监控 (1.7万) 2017-01-09 14:28:47

一、cacti概述

1. cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。

2. Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。

3. snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。

二、安装rrdtool

CentOS-5:
32位:rpm -ivh http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
64位:rpm -ivh http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
     yum install rrdtool -y

CentOS-6:
32位:rpm -ivh http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
64位:rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
     yum install rrdtool -y

三、安装配置net-snmp

1、安装net-snmp
[root@tiejiang ~]# yum -y install net-snmp net-snmp-libs net-snmp-utils

2、配置net-snmp,在/etc/snmp/snmpd.conf中修改:
[root@tiejiang ~]# vim /etc/snmp/snmpd.conf
     view    systemview    included   .1.3.6.1.2.1.1
   改为
     view    systemview    included   .1.3.6.1.2.1

3、测试net-snmp
[root@tiejiang ~]# service snmpd start
[root@tiejiang ~]# snmpwalk -v 1 -c public localhost .1.3.6.1.2.1.1.1.0
     SNMPv2-MIB::sysDescr.0 = STRING: Linux tiejiang.org 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64

四、安装LAMP

[root@tiejiang ~]# yum install httpd php php-mysql php-snmp php-xml php-gd mysql mysql-server
[root@tiejiang ~]# service httpd start
[root@tiejiang ~]# service mysqld start
[root@tiejiang ~]# mysqladmin -uroot password yuanfei123

五、安装cacti

1、下载cacti

[root@tiejiang ~]# cd /tmp/
[root@tiejiang tmp]# wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
[root@tiejiang tmp]# tar zxvf cacti-0.8.8b.tar.gz
[root@tiejiang tmp]# mv cacti-0.8.8b /var/www/html/cacti
[root@tiejiang tmp]# cd /var/www/html/cacti/

2、创建数据库

[root@tiejiang cacti]# mysqladmin --user=root -p create cacti

3、导入数据库

[root@tiejiang cacti]# mysql -uroot -p cacti < cacti.sql

4、创建数据库用户

[root@tiejiang cacti]# mysql -uroot -p mysql
    mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
        Query OK, 0 rows affected (0.00 sec)

    mysql> flush privileges;
        Query OK, 0 rows affected (0.00 sec)

5、配置include/config.php

[root@tiejiang cacti]# vim include/config.php 
     $database_type = "mysql";
     $database_default = "cacti";
     $database_hostname = "localhost";
     $database_username = "cactiuser";
     $database_password = "cactipassword";
 
     /* load up old style plugins here */
     $plugins = array();
     //$plugins[] = 'thold';
 
     /*
        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";
[root@tiejiang cacti]# useradd cactiuser
[root@tiejiang cacti]# chown -R cactiuser rra/ log/
[root@tiejiang cacti]# echo "*/5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1">>/etc/crontab
[root@tiejiang cacti]# service crond restart
[root@tiejiang cacti]# service httpd restart

6、设置目录权限

[root@tiejiang cacti]# useradd cactiuser
[root@tiejiang cacti]# chown -R cactiuser rra/ log/

7、配置计划任务

[root@tiejiang cacti]# echo "*/5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1">>/etc/crontab
[root@tiejiang cacti]# service crond restart
[root@tiejiang cacti]# service httpd restart

8、完成cacti的安装

1) 在浏览器中输入:http://youip/cacti/
       默认用户名:admin 密码:admin
2) 更改密码
3)设置cacti用到的命令路径

Cacti简单安装详细步骤 (https://www.tiejiang.org/) 服务器监控 第1张

至此,cacti的安装已经完成,服务器流量监控设置可以参考!

THE END

发表评论

上一篇

已是最后文章