一切盡在掌控--構建Cacti服務器管理監測系統

       Cacti(願意仙人掌,也是次軟件的名稱)實在大型網絡常見的性能監測軟件,可提供對CPU負載、內存佔用、運行進程數、磁盤空間、網卡流量等各種數據進行監測。

Cacti本身只是基於PHP語言編寫的一套管理套件,需要使用Net-SNMP工具採集監測數據,並結合RRDtool(輪詢數據庫工具)記錄數據及繪製圖片,並通過web頁面的形式展現給管理員用戶。

原理圖;

clip_image003

軟件獲取:

clip_image001 Cacti下載

p 官方站點:http://www.cacti.net

clip_image001[1] RRDTool

p Round Robin Database Tool,輪詢數據庫工具

p 官方站點:http://oss.oetiker.ch/rrdtool

需求:

Redhat 5.4或者CentOS5.5系統,採用文本安裝模式最小化安裝,構建YUM。

實現步驟:

一.配置被監測端(snmpd)

在被檢測的linux主機中,安裝好net-snmp軟件包,並配置啓動snmpd服務,以便允許Cacti系統採集數據。

1. 安裝net-snmp軟件包

net-snmp軟件需要用到lm_sensors提供的硬件監測模塊,安裝時直接使用系統光盤中的rpm包文件,依次安裝lm_sensors、net-snmp。(被監測的服務器需要安裝snmpd服務,在監測服務器上還需要安裝net-snmp-utils-5.3.2.2-7.el5.i386.rpm)

[root@www ~]# mount /dev/cdrom /media/mnt/

[root@www ~]# cd /media/mnt/Server/

[root@www Server]# rpm -ivh lm_sensors-2.10.7-4.el5.i386.rpm

[root@www Server]# rpm -ivh net-snmp-5.3.2.2-7.el5.i386.rpm

[root@www Server]# rpm -ivh net-snmp-utils-5.3.2.2-7.el5.i386.rpm

2. 配置及啓動snmpd服務

修改/etc/snmp/snmpd.conf文件

修改內容:

把com2sec notConfigUser default public

access notConfigGroup "" any noauth exact systemview none none

#view all included .1 80

修改爲

com2sec notConfigUser 192.168.1.111 public

access notConfigGroup "" any noauth exact all none none

view all included .1 80

3. 啓動snmpd服務並設置開機啓動

[root@www ~]# service snmpd start

[root@www ~]# chkconfig --level 35 snmpd on

二.配置監測服務端(Cacti)

Cacti監測服務端需要有Apache、Mysql、PHP網站平臺的支持,且需要預先安裝有gd、zlib等軟件包。

1. 安裝LAMP平臺、啓動服務並設置開機啓動

[root@www ~]# yum install httpd* -y

[root@www ~]# yum install mysql* -y

[root@www ~]# yum install php* -y

[root@www ~]# service httpd start

[root@www ~]# service mysqld start

[root@www ~]# chkconfig --level 35 httpd on

[root@www ~]# chkconfig --level 35 mysqld on

2. 安裝rrdtool軟件包

rrdtool需要的軟件包

libart_lgpl-2.3.17-4.i386

libpng-1.2.10-7.1.el5_3.2.i386

freetype-2.2.1-21.el5_3.i386 需預先安裝

[root@www ~]# tar zxf rrdtool-1.2.27.tar.gz

[root@www ~]# cd rrdtool-1.2.27

[root@www rrdtool-1.2.27]# ./configure --prefix=/usr/local

[root@www rrdtool-1.2.27]# make

[root@www rrdtool-1.2.27]# make install

3. 安裝配置Cacti服務器套件

安裝Cacti文件包,解壓至WEB服務器的網頁目錄,並添加用於讀寫監測數據的用戶

[root@www ~]# cd /var/www/html/

[root@www html]# tar zxf cacti-0.8.7b-cn-utf8.tar.gz

[root@www html]# mv cacti-0.8.7b-cn-utf8 cacti

[root@www html]# useradd cactiuser

[root@www html]# chown -R cactiuser:cactiuser cacti/rra/ cacti/log/

設置監測數據庫。

建立保存監測數據的數據庫、表,設置好授權訪問數據庫的用戶和密碼

[root@www html]# service mysqld start

[root@www html]# mysql -u root -p

mysql> create database cactidb default character set utf8;

mysql> grant all on cactidb.* to cactiuser@localhost identified by '123';

mysql> exit

[root@www html]# mysql -u cactiuser -p cactidb < cacti/cacti.sql //導入數據表

4. 安裝PA、Thold、Monitor插件擴展

[root@www ~]# cd /var/www/html/cacti

[root@www cacti]# tar zxf cacti-plugin-arch.tar.gz

[root@www cacti]# mysql -u cactiuser -p cactidb &lt; cacti-plugin-arch/pa.sql

[root@www cacti]# gunzip -c cacti-plugin-0.8.7b-PA-v2.1-cn-utf8.diff.gz > PA-utf.diff

[root@www cacti]# patch -p1 -N < PA-utf.diff

[root@www cacti]# cd plugins

[root@www plugins]# tar zxf settings-0.5.tar.gz

[root@www plugins]# tar zxf monitor-0.8.2.tar.gz

[root@www plugins]# tar zxf thold-0.3.9.tar.gz

[root@www plugins]# mysql -u cactiuser -p cactidb &lt; thold/thold.sql

[root@www plugins]# mysql -u cactiuser -p cactidb &lt; monitor/monitor.sql

5.調整Cacti配置文件

[root@www cacti]# vi include/config.php

&lt;?php

$database_type = "mysql";

$database_default = "cactidb";

$database_hostname = "localhost";

$database_username = "cactiuser";

$database_password = "123";

$database_port = "3306";

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

$plugins = array ();

$plugins[] = "settings";

$plugins[] = "thold";

$plugins[] = "monitor";

/* Default session name - Session name must contain alpha characters */

#$cacti_session_name = "Cacti";

?>

6. 調整httpd設置

[root@www ~]# vi /etc/httpd/conf/httpd.conf

修改http.conf文件,以便支持自動查找索引頁index.php,並將utf-8作爲默認的中文頁面字符集。

Listen 192.168.1.111:80

DocumentRoot "/var/www/html/cacti"

<Directory "/var/www/html/cacti">

Options None

AllowOverride None

Order allow,deny

Allow from all

</Directory>

DirectoryIndex index.php

AddDefaultCharset UTF-8

7. 重啓httpd服務,並查看其端口

[root@www ~]# service httpd restart

[root@www ~]# service mysqld restart

[root@www ~]# netstat -anpt | grep :80

8. 添加任務計劃

[cactiuser@www ~]$ php /var/www/html/cacti/poller.php

[cactiuser@www ~]$ crontab –e

內容如下;

*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &&gt;/dev/null

[cactiuser@www ~]$ exit

[root@www ~]# service crond start

[root@www ~]# chkconfig --level 2345 crond on

clip_image005

9. 通過web頁面初始化安裝cacti

使用web瀏覽器訪問Cacti服務器,第一次訪問Cacti界面時,會自動跳轉到Cacti的初始化安裝嚮導界面。如圖,點擊下一步即可

clip_image007

clip_image008

clip_image010

clip_image012

clip_image014

clip_image016

爲了在監測圖像中正常現實中文,還需要設置RRDtool所使用的中文字體路徑,此版本的路徑應爲“/usr/share/fonts/zh_TW/TrueType/bsmi00lp.ttf”,點擊右下方的保存即可。

clip_image018

clip_image020

clip_image022

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章