简介

cacti号称一款完全采用rrdtool和snmp实现的监控软件,与同为自由软件的nagios相比,它能够呈现大量直观的监控图表,功能主要体现在了数据的量化上。该软件最初完全采用php写成,采用crontab调用poller.php脚本进行数据的定时收集,如今已经有c语言写成的改良版spine收集器进行数据的收集可供选择。

接下来开始安装,一开始还是一样先把可能妨碍安装成功的iptables和selinux关闭掉 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 </pre></td><td class=’code’><pre>service iptables stop chkconfig iptables off vim /etc/selinux/config </pre></td></tr></table></div>
</div> 然后SELINUX=enforcing改成SELINUX=disabled 重启机器getenforce 为disable 正式开篇 <div class=’bogus-wrapper’>
<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 </pre></td><td class=’code’><pre>yum -y install mysql mysql-server mysql-devel yum -y install httpd yum -y install php php-mysql </pre></td></tr></table></div>
</div>

启动服务并加入到启动列表 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 4 </pre></td><td class=’code’><pre>service httpd start service mysqld start chkconfig httpd on chkconfig mysqld on </pre></td></tr></table></div>
</div>

安装需要的库文件 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 4 5 6 7 </pre></td><td class=’code’><pre>yum -y install zlib yum -y install freetype yum -y install libjpeg yum -y install fontconfig yum -y install gd yum -y install libxml2 yum -y install php-gd </pre></td></tr></table></div>
</div>

安装rrdtool <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 </pre></td><td class=’code’><pre>yum -y install rrdtool </pre></td></tr></table></div>
</div>

安装snmp支持工具 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 </pre></td><td class=’code’><pre>yum -y install net-snmp yum -y install net-snmp-utils </pre></td></tr></table></div>
</div>

启动snmpd服务 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 </pre></td><td class=’code’><pre>service snmpd start chkconfig snmpd on </pre></td></tr></table></div>
</div>

安装cacti 下载wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz

1
2
3
4
tar xzf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /var/www/html/cacti
cd /var/www/html
vim cacti/include/config.php

编辑为下面的配置 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 4 5 6 </pre></td><td class=’code’><pre>$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "cacti"; $database_port = "3306"; </pre></td></tr></table></div>
</div>

添加cacti用户 useradd cacti

添加计划任务 编辑/etc/crontab <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 </pre></td><td class=’code’><pre>* * * * * cacti /usr/bin/php /var/www/html/cacti/poller.php >> /dev/null 2>&1 </pre></td></tr></table></div>
</div>

更改属组 将web目录的所属组改为cacti <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 4 </pre></td><td class=’code’><pre>#chgrp -R cacti /var/www/html/cacti #chown -R cacti /var/www/html/cacti/rra #chown -R cacti /var/www/html/cacti/log #chown -R cacti /var/www/html/cacti/poller.php </pre></td></tr></table></div>
</div>

创建cacti数据库 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 </pre></td><td class=’code’><pre>mysql mysql> create database cacti; </pre></td></tr></table></div>
</div> 导入cacti.sql <div class=’bogus-wrapper’>
<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 4 5 </pre></td><td class=’code’><pre>mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql mysql> use cacti mysql> grant all on cacti.* to cacti@localhost identified by 'cacti'; mysql> flush privileges; mysql> exit </pre></td></tr></table></div>
</div>

浏览器登录cacti http://ip/cacti new install后一路回车,安装完成。 默认登录密码为admin/admin

疑难杂症之cacti不出图

首先检查log文件权限 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 3 </pre></td><td class=’code’><pre>cd /var/www/html/cacti/log ll -rw-r--r-- 1 cacti cacti 438 Dec 3 02:14 cacti.log </pre></td></tr></table></div>
</div>

校正时间 <div class=’bogus-wrapper’>

<figcaption></figcaption><div class=”highlight”><table><tr><td class=”gutter”><pre class=”line-numbers”>1 2 </pre></td><td class=’code’><pre>#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #reboot </pre></td></tr></table></div>
</div>

确保/var/www/html/cacti/rra目录下有可写权限。 重启点击graph菜单观察发现已经出现图表了。

发表评论