cacti
Cacti是通過snmpget來獲取數據,使用RRDtool繪畫圖形,而且你完全可以不需要了解RRDtool複雜的參數。它提供了非常強大的數據和用戶管理功能,可以指定每一個用戶能查看樹狀結構、host以及任何一張圖,還可以與LDAP結合進行用戶驗證,同時也能自己增加模板,功能非常強大完善。界面友好
Cacti架構
Cacti工作原理
一.安裝前準備
Cacti是一套基於PHP,MySQL,SNMP及RRDTool開發的網絡流量監測圖形分析工具,所有我們需要搭建lamp環境,這裏我們採用yum安裝
(1)本地yum
[root@localhost]#mount/dev/cdrom/mnt/cdrom/
mount:blockdevice/dev/cdromiswrite-protected,mountingread-only
[root@localhost]#vim/etc/yum.repos.d/rhel-debuginfo.repo
[rhel-server]
name=RedHatEnterpriseLinuxserver
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
二.lamp搭建
[root@localhost~]#yuminstallhttpdphpphp-mysqlphp-snmpmysql-serverper-DBD-MySQLphp-pdonet-snmpnet-snmp-libsnet-snmp-utilsnet-snmp-develrubyruby-devel
(1)設置lamp能夠開機啓動
[root@localhost~]#servicehttpdstart
[root@localhost~]#chkconfighttpdon
[root@localhost~]#servicemysqldstart
[root@localhost~]#chkconfigmysqldon
(2)爲mysql創建賬號並授權給cacati
[root@localhost~]#mysqladmin-uroot-ppassword'123'
[root@localhost~]#mysql-uroot-p
mysql>createdatabasecacti;
授權給cacati並賦予密碼爲cacti
mysql>grantallprivilegesoncacti.*tocacti@localhostidentifiedby'cacti';
mysql>grantallprivilegesoncacti.*[email protected]'cacti';
mysql>flushprivileges;
三.安裝rrdtool文件
[root@localhost~]#yumlocalinstallrrd*--nogpgcheck
/rrdtool-1.4.4-1.el5.wrl.i386
/rrdtool-perl-1.4.4-1.el5.wrl.i386
/rrdtool-ruby-1.4.4-1.el5.wrl.i386
(1)建立調度任務
[root@localhostcacti]#crontab-e
*/5****php/var/www/html/cacti/poller.php>/dev/null2>&1
(2)編輯cacti的控制腳本
[root@localhostcacti]#viminclude/config.php
26$database_type="mysql";
27$database_default="cacti";
28$database_hostname="localhost";
29$database_username="cacti";
30$database_password="cacti";
31$database_port="3306";
[root@localhostcacti]#servicehttpdrestart
(3)增加cacti賬號密碼
[root@localhostcacti]#useraddcacti
[root@localhostcacti]#passwdcacti
[root@localhostcacti]#chown-Rcactilogrra
(4)啓動snmp對本主機進行監控
[root@localhost~]#servicesnmpdstart
[root@localhost~]#chkconfigsnmpdon
(5)對本地apache配置
[root@localhostcacti]#vim/etc/httpd/conf/httpd.conf
查看是否有這樣的模塊
176LoadModulestatus_modulemodules/mod_status.so
216#
217ExtendedStatusOn
902#
903<Location/server-status>
904SetHandlerserver-status
905Orderdeny,allow
906Allowfromall
907</Location>
[root@localhostcacti]#servicehttpdrestart
四.進入cactig管理界面
(1)通過192.168.2.10/cactil/進入cacti
(2)指明目錄,如果是yum安裝這些目錄,會自動添加上去.
(3)輸入賬號admin,密碼admin
(4)全局配置,版本V2版本,採用snmp
1).Create創建
NewGraphs添加新圖形
(2).Management管理
GraphManagement圖形管理。可以在此刪除、複製圖像,Cacti會自動創建圖像。不過如果我們有特殊的需要,比如將幾張圖上的數據合併在一張圖像上的話也可以在此手工新建圖像;
GraphTrees圖形樹。在graphs界面裏,圖像或devices是樹狀結構顯示的,可以在此設置樹的結構;
DataSources數據源。記要用來管理rrd文件的,一般無需修改,Cacti會自己創建rrd文件;
Devices設備管理。這是我們最經常需要修改的地方,可以在此創建新的設備或修改其名稱等信息。
(3).CollectionMethods數據收集方法,一般我們無需對這兩項進行修改。(非常重要在下面的內容中進行詳解)
DataQueries數據查詢,
DataInputMethods數據輸入方法
(4).Templates模板,這些模板可以導出、導入也可以自己編寫,一般無需修改。
GraphTemplates圖形模板
HostTemplates主機模板
(5)對本地主機監控,
(6)創建圖形
(7)查看graphs查看本地監控
(8)對windows進行監控需要安裝snmp服務
(9)啓動該服務,並對該服務添加團體名,設置允許192.168.2.10對其監控
(10)cacti設置創建windows圖形樹
(11)創建表格,對windows進行監控端口161端口,版本version2
(12)添加windows監控服務
(13)把windows添加到圖形樹
樹裏面查看已有數據
查看rrd表,這時候發現增加幾個表
(14)監控junpier防火牆
允許192.168.2.10,掩碼255.255.255.255,掩碼必須是四個255指明單個主機否則無法獲得數據
cacti添加設備
創建圖形樹,由於沒有junpier的圖形樹模板,我們需要對其創建或者網上下載相應的模板,這裏我們可以利用現有的設備模板,複製更改,這裏一定要把被監控設備的OID設備指明,否則我們將無法獲得數據
(15)apache監控,首先我們需要導入apache的模板
ss_apache_stats.php需要導入到/var/www/html/cacti目錄
cacti_host_template_webserver_-_apache.xmlapache模板
(16)增加插件管理器
[root@localhost~]#tar-zxvfcacti-plugin-0.8.7g-PA-v2.8.tar.gz
[root@localhostcacti-plugin-arch]#cp-r*/var/www/html/cacti/
cp:是否覆蓋“/var/www/html/cacti/LICENSE”?y
cp:是否覆蓋“/var/www/html/cacti/README”?Y
導入數據庫
[root@localhostcacti]#mysql-uroot-pcacti<pa.sql
Enterpassword:
[root@localhostcacti]#patch-p1-N<cacti-plugin-0.8.7g-PA-v2.8.diff
[root@localhostcacti]#viminclude/config.php
42$url_path="/cacti/";
[root@localhostcacti]#servicehttpdrestart
拆解域值
[root@localhost~]#tar-zxvfthold-latest.tgz
[root@localhost~]#tar-zxvfmonitor-latest.tgz
[root@localhost~]#tar-zxvfsettings-latest.tgz
[root@localhost~]#mvmonitor-0.9//var/www/html/cacti/plugins/
[root@localhost~]#mvthold-0.41//var/www/html/cacti/plugins/
[root@localhost~]#mvsettings-0.6//var/www/html/cacti/plugins/
[root@localhostplugins]#mvmonitor-0.9/monitor
[root@localhostplugins]#mvsettings-0.6/settings
[root@localhostplugins]#mvthold-0.41/thold
增加插件
腳本(附件下載)
[root@localhost~]#mvsendmessage.sh/var/www/html/cacti/plugins/thold/
[root@localhost~]#mvsendsms.sh/var/www/html/cacti/plugins/thold/
[root@localhostthold]#chmoda+xsendmessage.sh
[root@localhostthold]#chmoda+xsendsms.sh
郵件於cacti的結合
[root@localhostthold]#vimthold_functions.php
559thold_mail($alert_emails,'',$subject,$msg,$file_array);
560exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");
561exec("sh/var/www/html/cacti/plugins/thold/sendmessage.sh");
對windows進行監控,設置域值
設置域值,這裏監控是進程數量
飛信控制
[root@localhost~]#tar-jxvffeition.tar.bz2
[root@localhost~]#cplinuxso_20101113/lib*/lib/標準路徑下
[root@localhostthold]#cd/var/www/html/cacti/plugins/thold/
[root@localhost~]#mkdir/var/www/html/sendsms
[root@localhost~]#mvlinuxso_20101113//var/www/html/sendsms/linuxso
[root@localhost~]#
[root@localhostthold]#vimthold_functions.php
559thold_mail($alert_emails,'',$subject,$msg,$file_array);
560exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");
561exec("sh/var/www/html/cacti/plugins/thold/sendmessage.sh");
562exec("echo$subject>>/var/www/html/cacti/plugins/thold/alert.log");
563exec("sh/var/www/html/cacti/plugins/thold/sendsms.sh");
cacti實現飛信報警,郵件報警腳本,以及apache模板查看附件下載