原理簡單來說,Cacti就是rrdtool的一個forefront,它内置了快速的獲資料取工具、優秀的繪圖模闆以及許多設計精良的資料擷取腳本,進而可以通過結合rrdtool強大的資料抓取、資料存儲和繪圖功能,輕松實作主機負載、網絡流量等資訊的走勢圖的繪制。
<a href="http://blog.51cto.com/attachment/201208/100545389.png" target="_blank"></a>
Cacti的安裝:
Cacti是建立在lamp環境下的,先建立lamp環境和編譯環境。
Yum install pango pango-devel freetype freetype-devel libpng libpng-devel gettext gettext-devel libjpeg libjpeg-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart*
<a href="http://blog.51cto.com/attachment/201208/100722989.png" target="_blank"></a>
<b>1.</b><b>安裝</b><b>rrdtool</b><b>源碼包</b>
Tar zxvf rrdtool-1.4.5.tar.gz
Cd rrdtool-1.4.5
./configure –prefix=/usr/local
Make && make install
<a href="http://blog.51cto.com/attachment/201208/100735408.png" target="_blank"></a>
<b>2.</b><b>安裝</b><b>snmp</b><b>協定</b>
監控協定:SNMP(simple network manager protocol)
Yum intall net-snmp*
<a href="http://blog.51cto.com/attachment/201208/100750346.png" target="_blank"></a>
Vi /etc/snmp/snmpd.conf
<a href="http://blog.51cto.com/attachment/201208/100806415.png" target="_blank"></a>
Service snmpd restart
<a href="http://blog.51cto.com/attachment/201208/100817658.png" target="_blank"></a>
<b>3.</b><b>安裝</b><b>cacti</b><b>源碼包</b>
Tar zxvf cacti-0.8.7h-beta3.tar.gz
Mv cact-0.8.7h-beta3/ /usr/local/apache2/htdocs/cacti/
Vi /usr/local./apache2/conf/httpd.conf
設定網站程式使用者,然後重新開機apache,程序生效
<a href="http://blog.51cto.com/attachment/201208/100829487.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/100844275.png" target="_blank"></a>
Setfacl –m u:apache:rwx –R htdocs/
Setfacl –m d:u:apache:rwx –R htdocs/ //修改檔案屬性值
Getfacl htdocs/ //檢視htdocs屬性
<a href="http://blog.51cto.com/attachment/201208/100903849.png" target="_blank"></a>
<b>4.</b><b>建立測試資料庫</b>
Mysql>create database cacti;
Shell#mysql cacti < /usr/local/apache2/htdocs/cacti/caci.sql
Mysql>use cacti;
Mysql>show tables;
<a href="http://blog.51cto.com/attachment/201208/100916304.png" target="_blank"></a>
<b>5.</b><b>編輯</b><b>cacti</b><b>配置檔案</b>
Vi /usr/local/apache2/htdocs/cacti/include/config.php
輸入資料庫名,資料庫使用者名和密碼,指定url
<a href="http://blog.51cto.com/attachment/201208/100943692.png" target="_blank"></a>
<b>2.</b><b>測試:</b>
http://192.168.211.128/cacti
<a href="http://blog.51cto.com/attachment/201208/100959744.png" target="_blank"></a>
選擇new install全新安裝
<a href="http://blog.51cto.com/attachment/201208/101012147.png" target="_blank"></a>
進入環境檢查頁
<a href="http://blog.51cto.com/attachment/201208/101024112.png" target="_blank"></a>
檢查通過,單擊finsh,然後輸入賬戶登入,首次登入使用者名admin密碼admin,首次需要修改密碼,我們修改為5991460、
<a href="http://blog.51cto.com/attachment/201208/101036430.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/101046224.png" target="_blank"></a>
如果出現時區錯誤,解決方法
1:首先改 /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
date.timezone ='Asia/Shanghai'
2:在程式代碼中寫入
第一行寫入:date_default_timezone_set ('Asia/Shanghai');
登陸之後,我們首先添加主機,然後給該主機配置設定服務;接着我們添加圖集,給圖集添加元素,我們将我們剛設定的主機添加入圖集,于是就可以通過graphs 進行通路圖像了。
服務添加過後,圖像不會馬上顯示,需要一定時間,我們可以建立一個計劃任務來完成該監控。也可以強制執行php
/usr/local/apache2/htdocs/cacti/poller.php &>/dev/null
<a href="http://blog.51cto.com/attachment/201208/101115496.png" target="_blank"></a>
稍等會看到圖集
<a href="http://blog.51cto.com/attachment/201208/101138278.png" target="_blank"></a>
<b>8.</b><b>開啟</b><b>apache-status</b><b>功能</b>
Apache-status是apache的擴充功能,在/usr/local/apache2/conf/extra裡面,我們通過指令grep –I“server-status”*查找到該擴充在httpd-info.conf配置檔案中,我們然後提取此段代碼,然後粘貼到/usr/local/apache2/conf/httpd.conf 末尾,然後重新開機apache服務,使配置生效,然後加載給子產品使apache-status子產品生效。
<a href="http://blog.51cto.com/attachment/201208/101153370.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/101206632.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/101218458.png" target="_blank"></a>
/usr/loacl/apache/bin/apachectl -h
該指令檢視到幫助,然後知道-t –D DUMP_MOUDULES可以檢視所有的靜态子產品,可以看到有status_module子產品,不需要再加載了
<a href="http://blog.51cto.com/attachment/201208/101230465.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/101247700.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/101258890.png" target="_blank"></a>
顯示通路次數和流量和cpu負載和通路的網站
Apache程序有99個空閑的,我們可以通過
Pstree –p|grep httpd 檢視http程序
<a href="http://blog.51cto.com/attachment/201208/101310621.png" target="_blank"></a>
<b>3.</b><b>Cact</b><b>監控</b><b>apache</b><b>狀态</b>
首先下載下傳apache圖形子產品
然後,我們将ss_aoacge_stats.php腳本檔案放在cacti/scripts下面,我們将cacti_host_template_webserver_-_apache.xml檔案通過web界面導入到cacti。
導入的辦法是:console->import templates->浏覽->upload
<a href="http://blog.51cto.com/attachment/201208/102918803.png" target="_blank"></a>
這是我們選擇“device”進入主機,這時選擇圖集便可以看到apahce子產品了。
<a href="http://blog.51cto.com/attachment/201208/102950696.png" target="_blank"></a>
我們建立過圖集後,單擊“create graphs for this host“->打鈎進行啟用服務。
<a href="http://blog.51cto.com/attachment/201208/103008368.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103035465.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103054179.png" target="_blank"></a>
這時定位到graphs面闆檢視圖像
<a href="http://blog.51cto.com/attachment/201208/103157235.png" target="_blank"></a>
<b>7.3cacti插件的安裝</b>
cactii的功能是通過插件進行完善的,對于0.8.8以上版本不需要安裝plungin了。然後直接部署插件就行了。
還是介紹一下plugins的安裝:
Tar zxvf cacti-0.8.7i-PIA-3.1.tar.gz
Cp cacti-plugin-0.8.7h-PA-v3.0.diff /usr/local/apache2/htdocs/cacti //打更新檔
Mysql cacti <pa.sql //導入資料庫
Vi /usr/local/apache2/htdocs/cacti/includes/global.php
<a href="http://blog.51cto.com/attachment/201208/103246343.png" target="_blank"></a>
對于monitor,settings和thold插件的安裝,解壓後拷貝到/usr/local/apache2/htdocs/cacti/plugins然後執行setfacl –m u:apache:rwx –R htdocs/和setfacl –m d:u:apache:rwx –R htdocs/配置設定權限即可。
<a href="http://blog.51cto.com/attachment/201208/103304385.png" target="_blank"></a>
Vi /usr/local/apache2/htdocs/cacti/include/config.php //定義插件
<a href="http://blog.51cto.com/attachment/201208/103323271.png" target="_blank"></a>
這時打開圖形界面,通過plugin management可以看到定義的插件,然後單擊左邊的箭頭,啟動即可,啟動後顔色為紅色。
<a href="http://blog.51cto.com/attachment/201208/103339195.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103353852.png" target="_blank"></a>
這是定位到setting按鈕可以看到多了幾個misc,mail/dns和template按鈕,我們可以設定郵件進行測試,我們使用postfix郵件,定義接收郵箱和端口以及發送郵箱。
<a href="http://blog.51cto.com/attachment/201208/103407341.png" target="_blank"></a>
我們配置完畢後單擊右上角的“send test mail ”測試
<a href="http://blog.51cto.com/attachment/201208/103425732.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103442518.png" target="_blank"></a>
使用outlook進行檢視郵件,可以看到收到測試郵件
<a href="http://blog.51cto.com/attachment/201208/103455653.png" target="_blank"></a>
<b>測試:</b>
Console->threahold templates->定義新的模版
<a href="http://blog.51cto.com/attachment/201208/103507687.png" target="_blank"></a>
我們定義一個空間報警的模版,選擇“hara drive space”圖集,然後空間量選擇60,時間每五分鐘,比例選擇percenter,占total的百分比,輸入接收郵箱。
<a href="http://blog.51cto.com/attachment/201208/103526923.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103542838.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103602996.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103625591.png" target="_blank"></a>
模版可以導出xml檔案,然後備用。通過device選擇主機->create graph->auto-create thresholds進行調用模版即可。
<a href="http://blog.51cto.com/attachment/201208/103642909.png" target="_blank"></a>
<b>7.4壓力測試</b>
<b>7.4.1apache壓力測試</b>
Apache2.2之後的版本有ab壓力測試工具可以直接使用
表示10個使用者發送1000次請求
我們可以在htdocs中建立内容相同的index.html和index.php頁面
測試:/usr/local/apache2/bin/ab –c 10 –n 1000 http://192.168.211.128/index.html
<a href="http://blog.51cto.com/attachment/201208/103658596.png" target="_blank"></a>
/usr/local/apache2/bin/ab –c 10 –n 1000 http://192.168.211.128/index.php
<a href="http://blog.51cto.com/attachment/201208/103711333.png" target="_blank"></a>
可以看到html的速度要快于php頁面,靜态頁面還是快一些的。
<b>7.4.2mysqlslap壓力測試</b>
Mysql5.1以上版本的資料擁有這個測試工具。
<a href="http://blog.51cto.com/attachment/201208/103734996.png" target="_blank"></a>
50,100個使用者,請求3000次,重複5次操作,分别對myisam和innodb引擎進行測試
<a href="http://blog.51cto.com/attachment/201208/103747162.png" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201208/103808769.png" target="_blank"></a>
本文轉自zsaisai 51CTO部落格,原文連結:http://blog.51cto.com/3402313/970873