(lamp平台)
系统环境: rhel6 x86_64 iptables and selinux disabled
主机: 192.168.122.119 server19.example.com
192.168.122.7 server7.example.com (注:时间需同步)
相关网址: rpm.pbone.net http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/ cacti.net nagios.org https://trac.assembla.com/npc
所需的包:cacti-0.8.8b.tar.gz cacti-spine-0.8.8b.tar.gz settings-v0.71-1.tgz monitor-v1.3-1.tgz thold-v0.4.9-3.tgz nagios-cn-3.2.3.tar.bz2 nagios-plugins-1.4.16.tar.gz gd-devel-2.0.35-10.el6.x86_64.rpm fetion linuxso_20101113.tar.gz nrpe-2.14.tar.gz ganglia-3.6.0.tar.gz ganglia-web-3.5.10.tar.gz libconfuse-2.6-3.el6.x86_64.rpm libconfuse-devel-2.6-3.el6.x86_64.rpm rrdtool-devel-1.3.8-6.el6.x86_64.rpm npc-2.0.4.tar.gz ndoutils-1.5.2.tar.gz
1.安装与配置cacti
[root@server19 kernel]# yum install httpd mysql-server php rrdtool -y
[root@server19 kernel]# yum install php-mysql php-xml mysql net-snmp net-snmp-utils.x86_64 -y
[root@server19 kernel]# rpm -ivh php-snmp-5.3.3-22.el6.x86_64.rpm
注:因为在红帽企业7中用mariadb替代了mysql,所以需要将mysql和mysql-server换成mariadb和mariadb-server.并且php-snmp的版本必须与企业7中php的版本一致,可以通过rpm -q php查看php的版本.
[root@server19 kernel]# vim /etc/php.ini
safe_mode = Off
date.timezone = Asia/Shanghai
file_uploads = On
[root@server19 kernel]# mysql_secure_installation (给数据库设置密码)
[root@server19 kernel]# vim /etc/snmp/snmpd.conf
(注:以下配置可在http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/上查看)
#com2sec notConfigUser default public
com2sec local localhost public
com2sec mynetwork 192.168.122.0/24 public
#group notConfigGroup v1 notConfigUser
#group notConfigGroup v2c notConfigUser
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view systemview included .1.3.6.1.2.1
view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
#access notConfigGroup "" any noauth exact systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation rhel6.4 (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
[root@server19 kernel]# /etc/init.d/snmpd start
[root@server19 kernel]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex (此命令可在http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/上查看)
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.122.119 = INTEGER: 2
(出现类似上面的输出为正常)
[root@server19 kernel]# tar zxf cacti-0.8.8b.tar.gz -C /var/www/html/
[root@server19 kernel]# mysqladmin -uroot -pwestos create cacti
[root@server19 kernel]# cd /var/www/html/
[root@server19 html]# ln -s cacti-0.8.8b/ cacti
[root@server19 html]# cd cacti
[root@server19 cacti]# mysql -uroot -pwestos cacti < cacti.sql
[root@server19 cacti]# mysql -uroot -pwestos
mysql> grant all on cacti.* to cacti@localhost identified by 'cacti';
mysql> flush privileges;
mysql> quit
[root@server19 cacti]# cd /var/www/html/cacti/include/
[root@server19 include]# vim config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;
$url_path = "/cacti/";
$cacti_session_name = "Cacti";
[root@server19 include]# useradd cacti
[root@server19 include]# chown cacti /var/www/html/cacti-0.8.8b/ -R
[root@server19 include]# su - cacti
[cacti@server19 ~]$ crontab -e
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
[root@server19 include]# /etc/init.d/httpd start
访问server19.example.com/cacti出现如下页面:
注:net-snmp和rrdtool的版本设置需要与本机的版本匹配,可以通过rpm -q net-snmp和rpm -q rrdtool查看版本.
注:第一次登录会强制要求更改密码(初始用户名:admin,密码:admin)
出现类似上面图形说明可以正常采集到数据.
#安装并配置spine
[root@server19 kernel]# yum install net-snmp-devel mysql-devel openssl-devel dos2unix autoconf automake binutils libtool gcc cpp glibc-headers kernel-headers glibc-devel -y
注:因为在红帽企业7中用mariadb替代了mysql,所以需要将mysql-devel换成mariadb-devel.
[root@server19 kernel]# tar zxf cacti-spine-0.8.8b.tar.gz
[root@server19 kernel]# cd cacti-spine-0.8.8b
[root@server19 cacti-spine-0.8.8b]# ./bootstrap
[root@server19 cacti-spine-0.8.8b]# ./configure
[root@server19 cacti-spine-0.8.8b]# make && make install
[root@server19 cacti-spine-0.8.8b]# cd /usr/local/spine/etc/
[root@server19 etc]# cp spine.conf.dist spine.conf
[root@server19 etc]# vim spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
DB_PreG 1
(注:如果你用的是cacti087g,将DB_PreG配置为0,否则将 DB_PreG配置为1.)
[root@server19 etc]# cp spine.conf /etc/
[root@server19 etc]# /usr/local/spine/bin/spine
PINE: Using spine config file [spine.conf]
INE: Version 0.8.8b starting
INE: Time: 0.1288 s, Threads: 5, Hosts: 2
出现类似以上输出为正确.
选择Settings选项.
选择Paths选项.
如图填写并保存,然后选择Poller选项.
如图选择并保存.
注:观察图像,如果没有出现中断说明spine配置成功.
#安装插件
[root@server19 kernel]# tar zxf settings-v0.71-1.tgz -C /var/www/html/cacti/plugins
[root@server19 kernel]# tar zxf monitor-v1.3-1.tgz -C /var/www/html/cacti/plugins
[root@server19 kernel]# tar zxf thold-v0.4.9-3.tgz -C /var/www/html/cacti/plugins
在Configuration中就会出现Plugin Management这个选项,启动插件.
注:在新版的cacti中已经集成了Plugin Management这个功能,只需将要安装的插件包加压到cacti目录下的plugins目录中,然后在Plugin Management中安装激活即可使用
#配置thold插件进行报警并发送邮件到QQ邮箱
(注:QQ邮箱必须打开POP3/SMTP服务)
选择Setting
选择Mail|DNS
仿照上图进行配置并保存
选择Thresholds
仿照上图进行配置并保存
选择Threshold Templates
仿照上图配置并保存
选择Graph Managerment