一、概述
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),它能夠存儲的數據筆數
在創建時就已經定義。
二、Cacti的架構及工作流程
1. Cacti 的架構
2. Cacti 的工作流程
安裝需求:(cacti相關包下載地址:http://www.cacti.net/downloads/)
· RRDTool 1.2.x 或者更高
· MySQL 4.1.x or 5.x 或者更高
· PH
· Web服務 例如:Apache 或者 IIS
· net-snmp
php編譯配置時需要添加下列模塊:(可用php –m查看這些模塊是否安裝)
· mysql
· snmp
· xml
· session
· sockets
· gd (安裝一些插件時需要)
· LDAP (當用LDAP認證時需要,非必須)
安裝過程步驟:
1.安裝必需組件
yum install –y fontconfig* autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel libart_lgpl* pango* libtool* ncurses ncurses-devel curl curl-devel openssl openssl-devel perl* net-snmp*
2. 安裝mysql
查看系統中是否已經安裝了MySQL,如果是卸載所有以mysql 開頭的包。
yum remove –y mysql*
tar -zxvf mysql-
useradd mysql
cd /usr/local/src/mysql-
./configure --prefix=/usr/local/cacti/mysql --enable-local-infile --with-charset=gbk
--with-low-memory --with-mysqld-user=mysql --enable-thread-safe-client
make && make install
cp /usr/local/src/mysql-
chown -R mysql:mysql /usr/local/cacti/mysql/
/usr/local/cacti/mysql/bin/mysql_install_db --user=mysql
/usr/local/cacti/mysql/bin/mysqld_safe --user=mysql &
echo "/usr/local/cacti/mysql/lib/mysql" >> /etc/ld.so.conf
cp /usr/local/src/mysql-
ln -s /usr/local/cacti/mysql/bin/mysql /usr/local/bin/mysql
ldconfig -v | grep mysql
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
3.安裝Apache
tar -zxvf httpd-
cd /usr/local/src/httpd-
./configure --prefix=/usr/local/cacti/apache --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/bin/openssl --with-zlib --enable-mods-shared=all --enable-track-vars --with-mysql=/usr/local/cacti/mysql
make && make install
/usr/local/cacti/apache/bin/apachectl start
ln -s /usr/local/cacti/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd //添加如下兩行
#description:http server
#chkconfig: 2345 83 17
chkconfig --add httpd
chkconfig httpd on
添加php支持
vi /usr/local/cacti/apache/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
4.安裝php
tar -zxvf php-
cd /usr/local/src/php-
./configure --prefix=/usr/local/cacti/php --with-config-file-path=/usr/local/cacti/php
--with-apxs2=/usr/local/cacti/apache/bin/apxs --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/cacti/mysql --with-mysqli=/usr/local/cacti/mysql/bin/mysql_config --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir --enable-sockets --with-snmp
make && make install
cp php.ini-dist /usr/local/cacti/php/php.ini
ln -s /usr/local/cacti/php/bin/php /usr/bin
vim /usr/local/cacti/apache/htdocs/index.php
<?
phpinfo();
?>
5.安裝rrdtool
yum install –y intltool //先更新intltool
tar -zxvf rrdtool-
cd rrdtool-
./configure --prefix=/usr/local/cacti/rrdtool
make && make install
6.安裝spine
tar -zxvf cacti-spine-
cd cacti-spine-
./configure --prefix=/usr/local/cacti/spine --with-mysql=/usr/local/cacti/mysql
make && make install
cat /usr/local/cacti/spine/etc/spine.conf
DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass cactiuser
DB_Port 3306
7.安裝cacti並創建cacti數據庫
tar -zxvf cacti-
mv cacti-
chown –R root:root /usr/local/cacti/apache/htdocs/cacti
cat /usr/local/cacti/apache/htdocs/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
cat /usr/local/cacti/apache/htdocs/cacti/include/global.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
useradd cactiuser
/usr/local/bin/mysql
mysql> create database cacti;
mysql> grant all privileges on cacti.* to cactiuser@localhost identified by "cactiuser";
mysql>flush privileges;
mysql cacti < /usr/local/cacti/apache/htdocs/cacti/cacti.sql //導入數據庫
8.定時執行
crontab -e
*/5 * * * * php /usr/local/cacti/apache/htdocs/cacti/poller.php > /dev/null 2>&1
9.在瀏覽器中輸入http://serverIP/cacti 安裝配置cacti
設置完後用http://serverIP/cacti/登錄,默認用戶名和密碼都是admin,第一次登錄要求強制修改密碼
安裝後的Settings設置,需要注意net-snmp,roodtool的版本號.spine路徑,poller type,如下:
以下是一些插件的安裝,用於擴展功能
10.安裝Plugin Architecture
unzip cacti-plugin-
/usr/local/bin/mysql cacti < pa.sql
cp cacti-plugin-
cd /usr/local/cacti/apache/htdocs/cacti/
patch -p1 -N < cacti-plugin-
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$config['url_path']='/';改成
$config['url_path']='/cacti/';
User Management-->admin-->選中Plugin Management 保存
刷新頁面,左側configuratin的Settings下面會顯示Plugin Managemnet
11.settings插件的安裝
tar -zxvf settings-0.5.tgz
mv settings-0.5 /usr/local/cacti/apache/htdocs/cacti/plugins/settings
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[] = 'settings';
$plugins[] = 'weathermap';
$plugins[] = 'monitor';
$plugins[] = 'thold';
$plugins[] = 'ntop';
$plugins[] = 'syslog';
$plugins[] = 'discovery';
點擊左側--->Plugin Management-->在新打開的窗口中會顯示剛安裝的settings插件,如圖:
必須Install再Enable才能使用
13.weathermap插件的安裝
unzip php-weathermap-0.97.zip
mv weathermap/ /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='weathermap';
cd /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap
chown cactiuser output
cp editor-config.php-dist editor-config.php
ps -aux | grep httpd
chown daemon configs/
chmod u+w configs/
vi editor-config.php
$cacti_base = "/usr/local/cacti/apache/htdocs/cacti";
$cacti_url = "http://192.168.0.161/cacti/";
$mapdir= $cacti_base.'/plugins/weathermap/configs';
$ignore_cacti = FALSE;
將editor.php中的ENABLED=false改爲true,否則weathermap點擊Editor時會報錯
vim /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap/editor.php
//$ENABLED=false; 將false改爲true
$ENABLED=true;
14.monitor的安裝
tar -zxvf monitor-latest.tgz
mv monitor-0.9/ /usr/local/cacti/apache/htdocs/cacti/plugins/monitor
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='monitor';添加
15.thold的安裝
tar -zxvf thold-latest.tgz
mv thold-0.41/ /usr/local/cacti/apache/htdocs/cacti/plugins/thold
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='thold';添加
在Plugin Managment中,將剛安裝的monitor,thold Install-->Enable 就可以看到monitor thold的標籤了
16. notp的安裝
安裝ntop之前要安裝libpcap和rrdttool
tar -zxvf libpcap-
cd libpcap-
./configure
make && make install
tar -zxvf ntop-3.3.tar.gz
cd ntop-3.3
./autogen.sh --with-rrd-home=/usr/local/cacti/rrdtool --disable-snmp
./configure --prefix=/usr/local/ntop --with-rrd-home=/usr/local/cacti/rrdtool --disable-snmp
make && make install
cp packages/RedHat/ntop.conf.sample /etc/ntop.conf
配置ntop
groupadd ntop
useradd ntop -g ntop
mkdir /var/log/ntop
chown -R ntop.ntop /usr/local/share/ntop
chown -R ntop.ntop /var/log/ntop
mkdir /usr/local/var/ntop/rrd
chmod -R 777 /usr/local/var/ntop/rrd/
ln -s /usr/lib64/libpcap.so.
ldconfig
/usr/local/ntop/bin/ntop -A
###########################################################################################
/usr/local/ntop/bin/ntop: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory
ldd /usr/local/ntop/bin/ntop
libpcap.so.1 => not found
libpcap.so.1 => not found
find / -name libpcap.so*
# find / -name libpcap.so*
/usr/local/lib/libpcap.so.
/usr/local/lib/libpcap.so.1
/usr/local/lib/libpcap.so
/usr/local/libpcap/lib/libpcap.so.
/usr/local/libpcap/lib/libpcap.so.1
/usr/local/libpcap/lib/libpcap.so
/usr/lib64/libpcap.so.
/usr/lib64/libpcap.so.0
/usr/lib64/libpcap.so.0.9
ln -s /usr/lib64/libpcap.so.
ldconfig
###########################################################################################
/usr/local/ntop/bin/ntop -P /var/log/ntop -u nobody & //啓動服務(測試不成功)
/usr/local/ntop/bin/ntop -p /var/log/ntop //這樣是成功的
設置開機自動啓動:
echo "/usr/local/ntop/bin/ntop -p /var/log/ntop & 2>1 1> /dev/null" >> /etc/rc.local
配置完成.
IP輸入: http://192.168.0.200:3000 就OK 了.
tar -zxvf ntop-0.1.tar.gz
mv ntop /usr/local/cacti/apache/htdocs/cacti/plugins/ntop
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='ntop';添加
User Management-->admin-->View NTop
17.syslog安裝,可以做爲日誌服務器
tar -zxvf syslog-
mv syslog /usr/local/cacti/ap
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='syslog';添加
vim /usr/local/cacti/apache/htdocs/cacti/plugins/syslog/config.php
$syslogdb_type = 'mysql';
$syslogdb_default = 'syslog';
$syslogdb_hostname = 'localhost
$syslogdb_username = 'cactiuser';
$syslogdb_password = 'cactiuser';
//建立syslog數據庫及用syslog.sql建表等
/usr/local/bin/mysql
mysql> create database syslog;
mysql> quit;
/usr/local/bin/
mysql> grant all privileges on syslog.* to cactiuser@localhost identified by "cactiuser";
mysql> flush privileges;
mysql> exit;
service syslog stop
安裝rpm -ivh syslog
vi /etc/syslog-ng/syslog-ng.conf
# 在文件末尾添加如下內容
source net {
udp();
};
destionation d_mysql{
pipe("/tmp/mysql.pipe”)
template("INSERT INTO
'$FACILITY', '$PRIORITY', '$YEAR-$MONTH-$DAY', '$HOUR:$MIN:$SEC', '$MSG' );\n") template-escape(yes)
);
};
log { source(net); destination(d_mysql); }
log { source(s_sys); destination(d_mysql); }
shell配置
vim /sbin/syslog
#!/bin/bash
if [ ! -e /tmp/mysql.pipe];then
mkfifo /tmp/mysql.pipe
fi
while[-e /tmp/mysql.pipe]
do
mysql –u cactiuser –password=cactiuser syslog </tmp/mysql.pipe
done
chmod 755 /sbin/syslog
echo "/sbin/syslog
/sbin/syslog
service syslog-ng restart
service mysqld restart
chkconfig syslog off
chkconfig --
chkconfig syslon-ng on
chkconfig --add syslog-n
點擊syslog標籤會有php的警告信息,經查找,是syslog.php中timespan_settings.php的路徑不對,懷疑是版本問題導致
vim /usr/local/cacti/apache/htdocs/cacti/plugins/syslog/syslog.php
include($syslog_config["graphtime"] ? "./lib/timespan_settings.php
"plugins/syslog/html/syslog_timespan_settings.php"); //改爲上面的路/*include($syslog_config["graphtime"] ? "./include/html/inc_timespan_settings.
"plugins/syslog/html/syslog_timespan_settings.php");*/
18.discovery的安裝
tar -zxvf discovery-
mv discovery /usr/local/cacti/apache/htdocs/cacti/plugins/discovery
vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
$plugins=array();找到這一項,添加
$plugins[]='discovery';添加
全部安裝完後效果圖: