cacti文檔
簡介:
cacti是用php語言實作的一個軟體,它的主要功能是用snmp服務擷取資料,然後用rrdtool(Round Robin Database,環形資料庫),儲存和更新資料,當使用者需要檢視資料的時候用rrdtool生成圖表呈現給使用者。
Mysql配合PHP程式存儲一些變量資料并對變量資料進行調用,如:主機名、主機ip、snmp團體名、端口号、模闆資訊等變量。 snmp抓到資料不是存儲在mysql中,而是存在rrdtool生成的rrd檔案中(在cacti根目錄的rra檔案夾下)。rrdtool對資料的更新和存儲就是對rrd檔案的處理,rrd檔案是大小固定的檔案檔案(Round Robin Archive),它能夠存儲的資料筆數在建立時就已經定義。
cacti架構(cacti的英文意思是仙人掌)
Cacti是一個c/s架構的,他主要監網絡接口流量,監控CPU的負載,記憶體使用,磁盤空間等,還監控伺服器中的WEB、mail、ftp、資料庫等,當然還能監控網絡裝置性能,配置檔案,路由數,以及機房溫度,電壓,濕度,風扇,電源,等運作狀态。
安裝步驟:
一.需要安裝的包:
yum install net-snmp net-snmp-utils net-snmp-devel net-snmp-libs php-mysql mysql-devel rrdtool-php php-snmp lib-tool autoconf automake make libxml2-devel php-gd php-xml net-snmp-utils httpd (呵呵,有點多啊,但是這總比在安裝時遇到蛋疼的依賴和報各種錯好得多)
二.配置snmp
參考文檔位址:http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/
/etc/init.d/snmpd start
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
#若沒有snmpwalk指令,則yum install net-snmp-utils
Timeout: No Response from localhost #若輸出結果為此則對snmp進行配置
vim /etc/snmp/snmpd.conf
Find line:
com2sec notConfigUser default public替代為:
com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public
Find lines:
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
Replace with:
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 system
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
/etc/init.d/snmpd reload
會得到如下結果:
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.46 = INTEGER: 6
三.安裝cacti
tar -zxf cacti-0.8.7h.tar.gz -C /var/www/html/cacti
1.配置mysql
/etc/init.d/mysqld start
shell>mysqladmin create cacti
cd /var/www/html/cacti
shell>mysql cacti < cacti.sql #導入資料庫
2.建立使用者cactiuser
shell>mysql -uroot -ppassword
mysql>grant all on cacti.* to cactiuser@localhost identified by "cacti";
mysql>flush privileges;
3.編輯include/config.php指定資料庫類型、名字、主機、使用者、和密碼
cd /var/www/html/cacti/include
vim config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;
4.設定權限
chown -R cactiuser.cactiuser rra/ log/
5.在/etc/crontab中添加一行
*/5 * * * * cactiuser php /var/www/html/cacti/poller.php
6.用browser浏覽
http://ip/cacti/
登入,預設使用者名和密碼均為admin
四.spine的安裝
Spine is a very fast poller engine, written in C. It is an optional replacement for cmd.php. If you decide to use it, you will have to install it explicitely. It does not come with cacti itself.
The easiest way is to install Spine using rpm or ports. You will find packages for Spine at the main cacti site or from your distribution.To compile Spine, please download it to any location of your liking. Then, please issue from the downloaded directory following commands
spine 是一個由C語言編寫的非常快的輪詢引擎。它是cmd.php的可選替代。使用需要安裝,cacti本身不附帶。cmd.php采集資料存在很大的延遲,執行效率很低。從添加裝置到是被up,spine隻需不到一分鐘,而cmd等的時間較長,超過10分鐘。當裝置down後2分鐘之内spine可以發出alert,而cmd可能需要10分鐘以上。
shell>aclocal
shell>libtoolize --force
(glibtoolize --force on Max OS)
shell>autoheader
shell>autoconf
shell>automake
shell>./configure
shell>make
shell>make install
cd /usr/local/spine/etc
cp -p spine.conf.dist spine.conf.dist
vim spine.conf #根據實際情況配置spine
DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass cacti
DB_Port 3306
DB_PreG 0
在浏覽器中cacti界面
console--Settings--Paths
在Spine Poller File Path後填上“/usr/local/spine/bin/spine”,點選儲存
點選上面的Poller選項
Poller Type後選擇spine
五.安裝插件管理更新檔
0.8.8a版本及其以上不用安裝此更新檔,解壓安裝包後已有plugins目錄
tar -zxf cacti-plugin-0.8.7h-PA-v3.0.tar.gz -C /var/www/html/cacti
cd /var/www/html/cacti
patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff
會産生一個plugin目錄
mysql cacti < pa.sql #導入資料庫檔案
在浏覽器中操作
在左邊欄選擇User Management,勾選最下方的Plugin Management,點選save
左邊欄的Plugin Management就能使用了
六.插件的安裝
#安裝settings
tar -zxf settings-v0.71-1.tgz -C /var/www/html/cacti/plugins #安裝插件均解壓到這個目錄裡
浏覽器console界面,點選Plugin Management,然後一次點選安裝、激活插件
安裝monitor,thold過程和上面相同。
七.添加監控裝置
虛拟機中的cacti監控主控端ip為:192.168.0.46
配置46的snmp,配置檔案cacti伺服器一樣,可以拷貝一份
然後開啟snmpd服務,
在cacti伺服器上檢測能否取到資料,
snmpwalk -v 1 -c public 192.168.0.46 IP-MIB::ipAdEntIfIndexIP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
若為如上結果,則能取到資料。
浏覽器管理界面—console—Devices,點選右上角Add
填入Description,Hostname;Host Template選擇ucd/net SNMP Host,其餘預設
點選create
上部出現 SNMP information則建立成功,點選右邊的
Create Graphs for this Host
然後勾選所需要監控的系統資訊及網卡,點create。這樣就完成了所指定裝置統計圖的建立。
點選左邊欄的Graph Management即可浏覽剛才所建立的圖表。
勾選需要顯示graphs的條目,在右下方chose an action:選擇
place on a tree(physical host)這樣就就能把該圖表類似快捷方式的樣子粘貼到Graphs,physical(被監控主機的描述)欄目中。