Cacti0.8.8a安裝與優化
系統:centos 6.3 x86_64
一,先将時間修改好
vim /etc/sysconfig/clock 重新開機生效
Asia/Chongqing
# cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime 馬上生效
# date 如果跟目前系統時間還是不一緻。則需手動調整
Thu Dec 13 12:49:54 CST 2012
#date 1213124912 [MMDDhhmm[YY]
# hwclock -w 将系統時間寫入硬體時間
# hwclock --show 檢視硬體時間
二,安裝LAMP環境,當然,如果你有興趣可以采用編譯,我線上Mysql是編譯的,其餘是yum安裝的。在這次實驗采用yum安裝。
關閉iptables與selinux,如果有需要,後面再開啟。
#/etc/init.d/iptables stop
#Setenforce 0
#yum -y install httpd http-devel httpd-manual mysql mysql-devel mysql-server php php-devel php-mysql php-common php-pdo php-gd lm_sensors net-snmp php-snmp net-snmp-utils
# chkconfig mysqld on
# chkconfig httpd on
# chkconfig snmpd on
# service mysqld start
# service httpd start
# service snmpd start
在浏覽器中輸入http://192.168.1.17,檢視測試頁有沒有出現。
1)、修改snmp
#vim /etc/snmp/snmd.conf
<a target="_blank" href="http://blog.51cto.com/attachment/201306/155754796.jpg"></a>
#/etc/init.d/snmpd restart
驗證snmp配置是否正确,
# snmpwalk -v 2c -c public 127.0.0.1 if 表示正确
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: lo
如果提示Timeout: No Response from 127.0.0.1則配置不對。
2)、建立資料庫存儲cacti的資料。
# mysqladmin -u root password 'bingo'
# mysql -u root -p
:輸入密碼
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cactiuser@localhost identified by 'cactiuser';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Tip:建立 cacti資料庫與cactiuser,可以省略在cacti配置檔案中修改。當然也可以建立别的名字,隻是在cacti的配置檔案需要多做兩步。
三、安裝cacti
1、安裝rrdtool需要的軟體包
# yum -y install cairo-devel libxml2-devel pango pango-devel
2、安裝rrdtool
1 # tar xf rrdtool-1.4.7.tar.gz
2 # cd rrdtool-1.4.7
3 # ./configure --prefix=/usr/local/rrdtool && make && make install
4 提示錯誤:
#Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
解決:安裝yum -y install perl-CPAN 即可
5 #make clean
6 #./configure --prefix=/usr/local/rrdtool && make &&make install
3、安裝cacti-0.8.8a
7 # tar xf cacti-0.8.8a.tar.gz -C /var/www/html/
8 # cd /var/www/html/
9 # mv cacti-0.8.8a cacti
10 # chown -R apache:apache /var/www/html/cacti/
11 Tip:當我們打開浏覽後,是apache使用者來通路cacti,如果是編譯的http,則不是apache使用者,在http.conf有定義
12 #useradd cactiuser
13 #chown -R cactiuser:cactiuser cacti/{rra,log}
4、導入資料庫
14 # mysql -ucactiuser -p cacti < cacti/cacti.sql
15 Enter password:
5、修改配置檔案,如下:
16 # vim cacti/include/global.php
vim include/config.php修改下面的資料庫連接配接資訊,基于不用修改。
17 $database_type = "mysql";
18 $database_default = "cacti";
19 $database_hostname = "localhost";
20 $database_username = "cactiuser";
21 $database_password = "cactiuser";
22 $database_port = "3306";
23 $database_ssl = false;
6、添加計劃任務
#echo "*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &>/dev/null" >/var/spool/cron/cactiuser
#/etc/init.d/crond restart
Tip:以cactiuser的身份定時執行這個腳本。
10、浏覽器輸入http://192.168.1.17/cacti/install初始化cacti,
<a target="_blank" href="http://blog.51cto.com/attachment/201306/155821471.jpg"></a>
11、将/usr/local/bin/rrdtool修改成正确的路徑/usr/local/rrdtool/bin/rrdtool,點完成輸入使用者和密碼都 是admin,輸入之後會要求強制修改密碼。
12、打開http://192.168.1.17/cacti 打開Console-->setting-->Genernal--->修改下面兩項
RRDTool Utility Version選擇RRDTOOL 1.4.x,SNMP Version選擇version 2
13、手動執行一次php /var/www/html/cacti/poller.php會提示下警告
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /var/www/html/cacti/lib/functions.php on line 486
14、#vim /etc/php.ini 啟用下面并修改。
date.timezone = Asia/Chongqing
15、/etc/init.d/httpd restart,再執行行php /var/www/html/cacti/poller.php沒警告了,這下應該正常了。等幾鐘應該會出圖
最後得到的結果如下所示。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/155845995.jpg"></a>
Tip:1,初始化出現這種FATAL: Cannot connect to MySQL server on ‘localhost’. Please make sure you have specified a valid MySQL database name in ‘include/config.php’,則用cactiuser連接配接資料庫,是否有權限完全控制cacti庫。
2,如果不是cactiuser導緻的,但是mysql是編譯的,由于/var/www/html/cacti/poller.php使用的/var/lib/mysql/mysql.sock,因為編譯的mysql的sock檔案在tmp下,是以做一個軟體連結
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
3,初始化時,點選finished後又彈回初始化界面,則檢查資料庫配置檔案是否有read-only=1,有則删除,并重新開機Mysql
4,cacti圖檔顯示的字型是方框,則需要安裝字型,yum -y install dejavu-*,安裝完後,重新整理cacti界面就行。
5,在Console--->Devices中顯示localhost的狀态為unknow,在rrd目錄中沒有生成檔案,檢視rra,log目錄的權限是否正确,并手動執行php /var/www/html/cacti/poller.php。注意調整時間,系統有兩個時間,一個硬體時間和系統時間。在虛拟機中往往要注意。
四,安裝spine
#tar xf cacti-spine-0.8.8a.tar.gz
# cd cacti-spine-0.8.8a
#./configure --prefix=/usr/local/cacti-spine
configure: error: Cannot find SNMP headers. Use --with-snmp= to specify non-default path.
#yum -y net-snmp-devel
#Make && make install
#cd /usr/local/cacti-spine/etc/
#cp spine.conf.dist spine.conf
#vim spine.conf
DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass cactiuser
DB_Port 3306
DB_PreG 0
#/usr/local/cacti-spine/bin/spine --conf=/usr/local/cacti-spine/etc/spine.conf 測試spine安裝是否正确,輸出下面資訊表示安裝成功
SPINE: Using spine config file [/usr/local/cacti-spine/etc/spine.conf]
SPINE: Version 0.8.8a starting
SPINE: Time: 0.1251 s, Threads: 5, Hosts: 2
打開catcti網頁。
Console——》setting——》poller 将cmd.php修改成spine,并儲存。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/155907852.jpg"></a>
Console——》settings--->paths,添加spine指令的路徑并儲存。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/155924780.jpg"></a>
五,安裝setting,thold,monitor
在安裝thold插件,必須先安裝settings插件,後安裝thold插件。因為settings插件提供email的相關設定,thold插件的報警功能是根據settings裡的設定來決定發送郵件的。
# tar xf settings-v0.71-1.tgz -C /var/www/html/cacti/plugins
# tar xf thold-v0.4.9-3.tgz -C /var/www/html/cacti/plugins
#tar xf monitor-v1.3-1.tgz -C /var/www/html/cacti/plugins
# vim /var/www/html/cacti/include/config.php
//$url_path = "/cacti/"; 在這一行下面添加一行
$plugins[] = 'settings';
$plugins[] = 'thold';
$plugins[] = 'monitor';
儲存後,打開cacti網頁,啟用插件console-->plugin management-->将插件安裝與啟用,如下圖表示已經正确啟用。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160033598.jpg"></a>
六、設定郵件報警通知
在Console---->setting------>mail/DNS中填寫好
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160058323.jpg"></a>
如果點了send a test Email出現下圖的錯誤
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160117185.jpg"></a>
解決辦法
# cat /var/log/httpd/error.log中提示沒權限
sendmail: fatal: chdir /var/spool/postfix: Permission denied
#setenforce 0再測試就ok了
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160137683.jpg"></a>
如果成功後,登入郵箱會收到一封郵件。
七、設定主機當機通知:
<a href="mailto:%E5%9C%A8Console----%3Esetting------%3Ethresholds,%E4%B8%8B%E5%9B%BE%E8%A1%A8%E7%A4%BA%EF%BC%8C%E7%94%[email protected]">在Console---->setting------>thresholds</a>
下圖表示,當有伺服器當機時,用[email protected]向[email protected]發送通知。
[email protected]表示全局的郵箱設定,與後面建立新的裝置時,選擇新的郵箱位址有關系。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160430861.jpg"></a>
八、設定插件moniter顯示模式:
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160500801.png"></a>
點moniter
九、監控linux主機
#yum -y install net-snmp
#vim /etc/snmp/snmpd.conf修改下面三處
<a target="_blank" href="http://blog.51cto.com/attachment/201306/110246473.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/160550643.jpg"></a>
編輯iptable
#vim /etc/sysconfig/iptables開放161端口
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m multiport --destination-port 22,80 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m multiport --destination-port 161 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#/etc/init.d/iptables restart
至此被監控端設定完成
十、在監控端添加被監控機,打開cacti監控界面。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161201136.png"></a>
點add後,如下圖
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161223296.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161303361.jpg"></a>
添加snmp - get mounted partions時為後面監控報警可以使用。 ucd/net - Get Monitored Partitions 可以删除,因為snmp - get mounted partions 也會擷取磁盤的使用。
這裡完了之後,需要點下面的Create後,如下圖所示
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161446233.jpg"></a>
選擇哪些資源畫成圖形,再選擇下面的Create。
可以自己選擇圖形的顔色,這裡選擇預設的。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161509467.jpg"></a>
下圖表示建立成功
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161537919.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/161539589.jpg"></a>
完成後點Create,在device中可以看到剛添加的裝置。過幾分鐘狀态應該會變成up。
如果建立時無法建立網卡圖檔或其他圖檔時:點選verbose query,排查錯誤
<a target="_blank" href="http://blog.51cto.com/attachment/201306/162935621.png"></a>
下面就是debug資訊
<a target="_blank" href="http://blog.51cto.com/attachment/201306/162951239.png"></a>
如果網卡圖像無法建立,編輯 vim /etc/snmp/snmpd.conf
view systemview included .1.3.6.1.2.1.1 将這行修改
view systemview included .1.3.6.1.2.1 改成這樣
重新開機snmpd,再重新編輯主機,建立圖像。
被監控機監控磁盤容量要在snmpd.conf中添加磁盤分區格式如下
disk /
disk /home
disk /boot
disk /data
或者執行此指令
mount |egrep '^/' |awk '{print "disk " $3}' >> /etc/snmp/snmpd.conf && service snmpd restart
十二,監控window2008主機與網卡流量
安裝snmp,在2008後,snmp被做成一個功能的形式,而不是元件。按下面步驟安裝snmp
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163218607.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163218496.png"></a>
安裝完後,需要重新開機,window系統基本都是這樣。重新開機後,在管理-----》配置---》服務中找到snmp service點屬性,做下面修改。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163252669.png"></a>
到些,window主機設定完畢。
十三、在cacti添加window,監控主機與網卡流量也與上面一樣。隻是選擇模闆的時候需要注意。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163329457.png"></a>
将兩台被監控的主機添加到預設樹中顯示,這樣話,在檢視圖檔時,可以檢視到更詳細的資訊。
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163358722.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163359768.png"></a>
Tree item type中選擇root,host選擇對應的主機
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163421842.png"></a>
Cacti不出圖總結:
system utilities –>Rebuild poller cache
2.系統時間不準确,重新設定時間
5.資料庫表有損壞,修複#mysqlcheck -ao cacti –auto-repair -uroot -p
6.重新開機snmpd服務#service snmpd restart
十四、監控磁盤使用并報警
1,建立發送給管理者的清單
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163701862.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163702931.jpg"></a>
2,建立報警模闆
Console -----> threshold templates
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163800680.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163802236.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163802475.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163807904.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/163917710.jpg"></a>
點儲存後,已經建立完了。
3,批量設定磁盤報警
<a target="_blank" href="http://blog.51cto.com/attachment/201306/164238110.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/164315147.jpg"></a>
4,也可以在graphs對每台伺服器設定
<a target="_blank" href="http://blog.51cto.com/attachment/201306/164001493.jpg"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201306/164401551.jpg"></a>
建立完在thresholds中可以查到
<a target="_blank" href="http://blog.51cto.com/attachment/201306/164402235.jpg"></a>
十五,監控ubantu
root@summba-dev3:~# apt-get install snmp snmpd
root@summba-dev3:~# vim /etc/default/snmpd
<a target="_blank" href="http://blog.51cto.com/attachment/201308/094420853.png"></a>
root@summba-dev3:~# vim /etc/snmp/snmpd.conf
<a target="_blank" href="http://blog.51cto.com/attachment/201308/094422391.png"></a>
root@summba-dev3:~# service snmpd restart
本文轉自 deng304749970 51CTO部落格,原文連結:http://blog.51cto.com/damondeng/1226857,如需轉載請自行聯系原作者