1. 程式人生 > 實用技巧 >RHEL5.4下cacti及相關外掛的編譯安裝

RHEL5.4下cacti及相關外掛的編譯安裝

一、概述

1. Cacti 是用php 語言實現的一個軟體,它的主要功能是用snmp 服務獲取資料,

然後用rrdtool 儲存和更新資料,當用戶需要檢視資料的時候用rrdtool 生成圖表

呈現給使用者。因此,snmp rrdtool cacti 的關鍵。snmp 關係著資料的收集,

rrdtool 關係著資料儲存和圖表的生成。

2. Mysql 配合PHP 程式儲存一些變數資料並對變數資料進行呼叫,如:主機名、主

ipsnmp 團體名、埠號、模板資訊等變數。

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 或者更高

· PHP 4.3.6或者更高(推薦5.3以下,否則會報很多錯誤) php-mysql

php-snmp

· 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-5.1.44.tar.gz -C /usr/local/src

useradd mysql

cd /usr/local/src/mysql-5.1.44

./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-5.1.44/support-files/my-medium.cnf /etc/my.cnf

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-5.1.44/support-files/mysql.server /etc/init.d/mysqld

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-2.2.15.tar.gz -C /usr/local/src

cd /usr/local/src/httpd-2.2.15

./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-5.2.8tar.gz -C /usr/local/src

cd /usr/local/src/php-5.2.8

./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-1.3.9.tar.gz

cd rrdtool-1.3.9

./configure --prefix=/usr/local/cacti/rrdtool

make && make install

6.安裝spine

tar -zxvf cacti-spine-0.8.7e.tar.gz

cd cacti-spine-0.8.7e

./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-0.8.7e.tar.gz

mv cacti-0.8.7e /usr/local/cacti/apache/htdocs/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 [email protected] 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-0.8.7e-PA-v2.5.zip

/usr/local/bin/mysql cacti < pa.sql

cp cacti-plugin-0.8.7e-PA-v2.5.diff /usr/local/cacti/apache/htdocs/cacti/

cd /usr/local/cacti/apache/htdocs/cacti/

patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.5.diff

vi /usr/local/cacti/apache/htdocs/cacti/include/global.php

$config['url_path']='/';改成

$config['url_path']='/cacti/';

User Management-->admin-->選中Plugin Management 儲存

重新整理頁面,左側configuratinSettings下面會顯示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外掛,如圖:

必須InstallEnable才能使用

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之前要安裝libpcaprrdttool

tar -zxvf libpcap-1.1.1.tar.gz

cd libpcap-1.1.1

./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.0.9.4 /lib64/libpcap.so.1

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.1.1.1

/usr/local/lib/libpcap.so.1

/usr/local/lib/libpcap.so

/usr/local/libpcap/lib/libpcap.so.1.1.1

/usr/local/libpcap/lib/libpcap.so.1

/usr/local/libpcap/lib/libpcap.so

/usr/lib64/libpcap.so.0.9.4

/usr/lib64/libpcap.so.0

/usr/lib64/libpcap.so.0.9

ln -s /usr/lib64/libpcap.so.0.9.4 /lib64/libpcap.so.1

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-0.5.2.tar.gz

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 [email protected] 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/syslogtomysql

#!/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/syslogtomysql

echo "/sbin/syslogtomysql &" >> /etc/rc.local

/sbin/syslogtomysql &

service syslog-ng restart

service mysqld restart

chkconfig syslog off

chkconfig --del syslog

chkconfig syslon-ng on

chkconfig --add syslog-n

點選syslog標籤會有php的警告資訊,經查詢,是syslog.phptimespan_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-0.8.5.tar.gz

mv discovery /usr/local/cacti/apache/htdocs/cacti/plugins/discovery

vi /usr/local/cacti/apache/htdocs/cacti/include/global.php

$plugins=array();找到這一項,新增

$plugins[]='discovery';新增

全部安裝完後效果圖:

轉載於:https://blog.51cto.com/lilinqing/383994