cacti 配置

 

Cacit 運行環境需要 Apache+ PHP + Mysql + rrdtool 以及 snmp 工具的支持。
下邊是本次配置需要用到的軟件。
1安裝mysql數據庫
mysql-5.1.40]# ./configure --prefix=/usr/local/mysql
--enable-thread-safe-client
--enable-local-infile
--with-charset=gbk
--with-extra-charsets=all
--with-low-memory
--with-named-curses-libs=/usr/lib/libncursesw.so.5
出現以下情況/bin/rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands刪除configure文件裏的$RM "$cfgfile"這一行,從新編輯就不會在現實。
make make install
如果想安裝選項文件,使用當前存在的‘support-files’文件夾下的作爲模板,執行指令:
[root@localhost mysql-5.1.40]#cp support-files/my-medium.cnf /etc/my.cnf
如果需要在此讓mysqld每次開機時自動啓動,需要執行以下指令:
[root@localhost mysql-5.1.40]#cp -r support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.1.40]#chmod 755 /etc/init.d/mysqld
[root@localhost mysql-5.1.40]#chkconfig --del mysqld
[root@localhost mysql-5.1.40]#chkconfig --add mysqld
如果在之前沒有安裝過MySQL,必須創建一個MySQL准許的表。
[root@localhost mysql-5.1.40]#bin/mysql_install_db --user=mysql
進行目錄授權:
[root@localhost mysql-5.1.40]#chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.1.40]#chown -R mysql /usr/local/mysql/var
所有的配置完成後,執行以下命令測試並運行MySQL
[root@localhost mysql-5.1.40]#/usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@localhost mysql-5.1.40]service mysqld start
正常啓動後需要更改管理員的密碼。可以運行mysqladmin,執行命令
[root@localhost mysql-5.1.40]/usr/local/mysql/bin/mysqladmin -u root -p password '123456'
Enter password: (這裏不需要再輸入密碼直接按回車鍵即可)
測試登陸mysql數據庫
[root@localhost ]mysql -u root -p
-bash: mysql: command not found 出現這一行需要安裝MySQL-client軟件包,安裝完後從新登陸mysql數據庫
[root@localhost ~]mysql -u root –p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.40-log Source distribution
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>
出現以上情況說明登陸成功。
2安裝Aapche軟件包
[root@localhost httpd-2.2.17]#./configure --prefix=/usr/local/apache2
 -with-mysql=/usr/local/mysql
--enable-so --enable-track-vars
--enable-rewrite --with-zlib
--enable-mods-shared=all
--enable-suexec
--with-suexec-caller=daemon
--enable-modules=most
make make install
3安裝PHP軟件包
需要安裝的軟件包有freetype-devel libpng-devel libjpeg-devel libxml2-devel
[root@localhost php-5.2.6]#./configure  --prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql
--with-libxml-dir
-with-png-dir
--with-jpeg-dir
--with-zlib
--with-freetype-dir
--with-gd
--enable-mbstring=all
--enable-sockets
make make install
[root@localhost php-5.2.6] # cp -fr php.ini-dist /usr/local/php/php.ini
編輯apache配置文件httpd.conf
查找
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在其下加入
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
修改DirectoryIndex 行,添加index.php
修改爲
DirectoryIndex index.php index.html index.html.var
測試新建vim /usr/local/apache2/htdocs/index.php添加以下內容
<?php
phpinfo();
?>
保存退出。訪問http://ip地址.index.php
出現以下如說明安裝正確
5安裝net-snmp net-snmp-devel net-snmp-libs  net-snmp-utils軟件包
可以用yum install net-snmp net-snmp-devel net-snmp-libs net-snmp-utils進行安裝。
修改 /etc/snmp/snmpd.conf文件
更改 1、com2sec notConfigUser  default       public
改爲:com2sec notConfigUser   127.0.0.1       public
2、access  notConfigGroup “”      any       noauth    exact  systemview  none none
改爲:access  notConfigGroup “”      any       noauth    exact  all  none  none
3、#view all    included  .1         80
將前面的 # 註釋 去掉。
保存退出 :wq 重啓service snmpd restart
6安裝rrdtool
# ./configure --prefix=/usr/local/rrdtool
make make install
如果 ./configure 時出現下面這個錯誤

configure: error: Please fix the library issues listed above and try again.
 
表明系統有功能缺失,需安裝 libart_lgpl-devel.rpm 這個包
如果還是提示聽樣的錯誤,有可能是找不到 FreeType
/usr/local/freetype2/lib/pkgconfig 下的 .pc 文件拷貝到 /usr/lib/pkgconfig 下即可
如果 make install 時出現 [tclrrd.o] 錯誤
就安裝 tcl-8.4.7-2.i386.rpm 以及 tcl-devel-8.4.7-2.i386.rpm 這 2 個包
 
解壓cacti軟件包
把解壓的cacti軟件包複製到apache WEB目錄
cp -fr cacti-0.8.7g/ /usr/local/apache2/htdocs/cacti
進入mysql數據庫創建cacti數據庫
mysql –u root –p
create database cacti;
查看數據庫是否創建
mysql> show databases;      
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cacti              |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)顯示出cacti數據庫說明創建好,接下來還原cacti.sql數據庫
[root@localhost ] # mysql -u root -p cacti < /usr/local/apache2/htdocs/cacti/cacti.sql(小於號後面是cacti.sql數據庫的存放路徑)
# vi /data/web_server/admin/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "數據庫用戶";
$database_password = "用戶密碼";
 
更改後保存退出。
# crontab – e (加入自動執行規則,每 5 分鐘執行。)
*/5 * * * * /usr/local/php/bin/php /usr/local/apache2/htdocs/cacti/poller.php > /dev/null 2>&1
打開瀏覽器 http://IP/cacti 進入cacti的初始設置頁面
第一次默認登陸賬號:admin 密碼 admin
登陸後在新改個密碼就OK
說一下 cacti 設置頁中各項“零件”的路徑。
當修改好新密碼進入,第一個顯示出的頁面就是讓你設置 rrdtool,snmp 等工具的路徑。這是個很重要的環節,必須無誤,要不然 cacti 將無法生成出統計圖。

snmpwalk Binary Path : /usr/bin/snmpwalk
 snmpget Binary Path: /usr/bin/snmpget
 RRDTool Binary Path: /usr/local/rrdtool/bin/rrdtool
 PHP Binary Path: /usr/local/php/bin/php
 Cacti Log File Path: /data/web_server/admin/cacti/log/cacti.log
 Cactid Poller File Path: /data/web_server/admin/cacti/poller.php
 

默認的配置中會出現許多“ NotFound ”
按照上邊的路徑把“ NotFound ”的項都重新填上。
手動運行一次
/usr/local/php/bin/php /data/web_server/admin/cacti/poller.php > /dev/null 2>&1
你就能在頂上 graphs 中 localhost 裏頭看到本機的內存,CPU,登陸用戶等的統計圖 .
但默認 Cacti 是沒有創建網卡流量的監控圖的。要我們自己來加。
回到 console 菜單
選擇 Devices 監控設備。
然後點擊右上角的 Add 進行添加
Description 設備名稱 ( 可隨意輸入 )
Hostname 設備地址 ( 如果是本機就填 127.0.0.1 )
Host Template 設備的類型 ( 選擇 ucd/net SNMP Host )
然後其他按照默認即可,如下圖
create 創建。
如果剛纔填寫的地址無誤,創建成功後,會在該頁面左上方出現所新建設備的 SNMP Information
然後點擊隔壁醒目的 * Create Graphs for this Host 即開始創建監控圖表
如圖 6,溝選你所要監控的網卡以及 IP,點 create 。
這樣就完成了你所指定設備統計圖的創建。

 
 /usr/local/php/bin/php /data/web_server/admin/cacti/poller.php > /dev/null 2>&
 
然後曲線表中就能出現第一個峯值,每 5 分鐘自動更新。 24 小時後,曲線圖就能完整地出現在你眼前。
Choose an action 框中選擇 Place on a Tree(default Tree)
就能把該圖表類似快捷方式的樣子張貼到本文圖 1 所示的 Graphs,Default tree 欄目中。然而你也能自己在菜單欄的 Graph Trees中新建定製欄目,然後用相同的方法把新建的統計圖往你所定製的欄目中放。
Cacti 的強大功能不單止可以通過 snmp 獲取裝有 Linux,Unix 操作系統服務器的運行狀態,還能監控 Windows 系統服務器。跟諸如 Cisco,Linksys, 路由器,交換機,無線 AP 。或者其他支持 snmp 管理協議的網絡設備。

下邊我們舉出實應用的例子。
設備結構:
  1. 網絡入口路由器 Linksys RV042
    Linksys 的一款路由器,主要負責,外網接入路由,防火牆,以及端口映射。
  2. server1 WEB 應用服務器
    操作系統: Linux RedHat As4
    Eth0,Eth1 雙網卡工作。前者接入路由器映射至外網。後者直連至 server2
    進行反向代理 ( proxy ) 以及數據備份以及同步等功能。
    IP 分別爲 192.168.3.2 以及 192.168.10.2
  3. server2儲存,FTP與WEB 應用服務器
    操作系統: Windows2003 r2
    與 server1 網絡環境相仿,雙網卡工作。
    IP 分別爲 192.168.3.3 以及 192.168.10.3
Cacti 已經配置完成,安裝在 server1 上。第一臺添加到監控表裏邊的是路由器 RV042 。打開路由器的 WEB 設置頁面,勾選並啓用 SNMP 功能。如圖 9
Send SNMP Trap to: 192.168.3.2( server1 的 IP )
然後其他輸入框按照默認留空即可,但需留意 Get Community Name: 所填寫的組名: public 。保存設置。
Description 設備名稱 ( 我們這裏自定爲 Linksys RV042)
Hostname 設備地址 ( 路由器的地址 192.168.3.1 )
Host Template 設備的類型 ( 選擇 ucd/net SNMP Host 或者是 Cisco Router )
然後其他按照默認即可。
創建成功後,也會在該頁面左上方出現所新建設備的 Linksys RV042 SNMP Information
點擊隔壁 *Create Graphs for this Host 創建監控圖表
路由器 RV042 的端口以及 IP 等數據都取出來了。
勾選好所要監控的端口,點擊 create 就能完成路由器監控圖表的建立。
Cacti 運行在 Server1 上,所以配置方式跟前邊所介紹是一樣的,這裏就掠過了。但順帶說一下,如果環境中還存在 Server3,而且跟 Server1 一樣都是 Linux 系統,需要添加到 cacti 裏頭。哪麼只需在該服務器上修改 snmp 配置,修改的內容也跟 server1 上幾乎一樣,不同的是。
編輯 /etc/snmp/snmpd.conf 的時候,原來填 127.0.0.1 ( 本機地址 ) 的地方換成 Cacti 所在運行的服務器 IP,即 server1: 192.168.3.2
  1. com2secnotConfigUser default public
    改爲:com2secnotConfigUser 192.168.3.2(server1 地址) public
  1. access  notConfigGroup ""  any   noauth    exact  systemview  none none
改爲:accessnotConfigGroup""anynoauthexact all none none
  1. #view all    included  .1         80
    將前面的 # 註釋 去掉。
  1. 保存退出 :wq
重新啓動 snmp 服務
# service snmpd restart
填寫 Server3 IP 地址,設備類型: ucd/net SNMP Host , 創建圖表 , 完成。
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章