安装配置cacti前,需要安装:httpd、php、mysqld、php-mysql、net-snmp、rrdtool
httpd、php、mysqld、php-mysql,可以直接rpm或yum安装,其它使用的软件包为:
net-snmp-5.4.2.1.tar.gz
rrdtool-1.4.7.tar.gz
cacti-0.8.8a.tar.gz
相关软件包全部上传至:/usr/local目录下;
net-snmp安装:
cd /usr/local
tar xzvf net-snmp-5.4.2.1.tar.gz
cd net-snmp-5.4.2.1
./configure
(小括号中为configure时的信息:
************** Configuration Section **************
You are about to be prompted with a series of questions. Answer
them carefully, as they determine how the SNMP agent and related
applications are to function.
After the configure script finishes, you can browse the newly
created net-snmp-config.h file for further - less important - parameters to
modify. Be careful if you re-run configure though, since net-snmp-config.h
will be overwritten.
-Press return to continue-
//这里按回车
……
*** Default SNMP Version:
Starting with Net-SNMP 5.0, you can choose the default version of
the SNMP protocol to use when no version is given explicitly on the
command line, or via an 'snmp.conf' file. In the past this was set to
SNMPv1, but you can use this to switch to SNMPv3 if desired. SNMPv3
will provide a more secure management environment (and thus you're
encouraged to switch to SNMPv3), but may break existing scripts that
rely on the old behaviour. (Though such scripts will probably need to
be changed to use the '-c' community flag anyway, as the SNMPv1
command line usage has changed as well.).
At this prompt you can select "1", "2" (for SNMPv2c), or "3" as
the default version for the command tools (snmpget, ...) to use. This
can always be overridden at runtime using the -v flag to the tools, or
by using the "defVersion" token in your snmp.conf file.
Providing the --with-default-snmp-version="x" parameter to ./configure
will avoid this prompt.
Default version of SNMP to use (3):
//这里输入2,默认为3,我们使用的是2版本
//后面几处都输入回车即可)
make
make install
安装成功后,会生成可执行文件:/usr/local/sbin/snmpd
[root@luly net-snmp-5.4.2.1]# which snmpd
/usr/local/sbin/snmpd
直接执行/usr/local/sbin/snmpd,就可启动snmp
使用net-snmp-5.4.2.1.tar.gz安装成功后,会发现找不到snmpd.conf文件
cd /usr/local/net-snmp-5.4.2.1
mkdir /usr/local/etc/snmp
cp EXAMPLE.conf /usr/local/etc/snmp/snmpd.conf
修改配置文件:
原文件内容:
# sec.name source community
com2sec local localhost COMMUNITY
com2sec mynetwork NETWORK/24 COMMUNITY
修改后内容:
# sec.name source community
com2sec local 192.168.146.228 public //被监控服务器的IP
com2sec mynetwork 192.168.146.0/24 public //监控客户端所在的网段
com2sec mynetwork 192.168.133.0/24 public //如果需要,可以增加多个监控网段
原文件内容:
# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
修改后内容:
# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all all none
access MyRWGroup "" any noauth exact all all none
保存修改,退出,重启snmpd:
[root@luly net-snmp-5.4.2.1]# ps -e | grep snmpd //查看进程
6126 ? 00:00:00 snmpd
[root@luly net-snmp-5.4.2.1]# kill 6126 //杀死PID为6126的进程
[root@luly net-snmp-5.4.2.1]# /usr/local/sbin/snmpd //启动snmpd
[root@luly net-snmp-5.4.2.1]# ps -e | grep snmpd //确认是否启动成功
6143 ? 00:00:00 snmpd //(PID有变,说明有重启过)
rrdtool安装:
安装rrdtool之前,需要先安装一些相关依赖包(这里使用光盘镜像安装,也可以直接使用yum安装):
mount -t nfs 192.168.146.75:/centos54_i386 /mnt
cd /mnt/CentOS
rpm -ivh libXau-devel-1.0.1-3.1.i386.rpm libX11-devel-1.0.3-11.el5.i386.rpm xorg-x11-proto-devel-7.1-13.el5.i386.rpm libXdmcp-devel-1.0.1-2.1.i386.rpm mesa-libGL-devel-6.5.1-7.7.el5.i386.rpm cairo-devel-1.2.4-5.el5.i386.rpm pango-devel-1.14.9-6.el5.centos.i386.rpm libXrender-devel-0.9.1-3.1.i386.rpm fontconfig-devel-2.4.1-7.el5.i386.rpm libXext-devel-1.0.1-2.1.i386.rpm libXft-devel-2.1.10-1.1.i386.rpm libart_lgpl-2.3.17-4.i386.rpm libart_lgpl-devel-2.3.17-4.i386.rpm
yum install -y libxml2-devel
cd /usr/local/
tar xzvf rrdtool-1.4.7.tar.gz
cd rrdtool-1.4.7
./configure -prefix=/usr/local/rrdtool
make
make install
whereis rrdtool
/usr/local/rrdtool/bin/rrdtool -v
cacti安装:
tar xzvf cacti-0.8.8a.tar.gz
mv cacti-0.8.8a /var/www/html/cacti
cd /var/www/html/cacti/
创建cactidb库,并导入相关表:
mysql> create database cactidb;
mysql -u root -p cactidb<cacti.sql
vi /var/www/html/cacti/include/config.php
修改数据库配置:
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "postfix";
$database_password = "postfix";
$database_port = "3306";
$database_ssl = false;
访问:http://IP/cacti进行首次安装配置:
配置:RRDTool Binary Path为:/usr/local/rrdtool/bin/rrdtool
第一次默认登陆账号:admin 密码 admin
登陆后它就会让你立即修改新密码
登录cacti后,也可以在Configuration-Settings-Paths中进行配置;
另修改:
Configuration-Settings-General-RRDTool Utility Version为:RRDTool 1.4.x
SNMP Version为:Version 2
手动执行:php -f /var/www/html/cacti/poller.php
执行如果成功,把*/5 * * * * root php -f /var/www/html/cacti/poller.php >/dev/null 2>&1增加到/etc/crontab中,每5分钟进行一次数据采样;
被监控端安装配置
安装net-snmp即可;
具体步骤见“监控端安装配置”;