Cacti on Windows Server 2003 安裝記錄

PS. 轉載請註明出處並連結!

Cacti Demo 圖表

以前要偵測系統流量大多是使用 MRTG,不過功能太少、管理不易,推薦使用 Cacti 與擁有強大圖形化功能的 RRDTool 搭配,可以創造出極漂亮的監測圖表,讓管理者一目了然並輕鬆掌握眾多設備狀況,官網也有很多熱心網友提供已作好的 templates 下載,只要上傳套用即可擁有美觀詳細的圖表。

曾經在 FreeBSD 上裝過 Cacti,這次嘗試裝在 Windows,為了避免忘記還是將步驟記錄下來。

◎軟體基本需求
1. Windows Internet Information Server(當然也可以用 Apache
2. Cacti 目前最新 stable 版本 0.8.6j,released 01/17/07
Cacti 下載後解壓至網頁目錄裡 “cacti” 資料夾裡(自訂)
3. RRDTool 目前最新版本 1.2.19
RRDTool 網站下載或從這裡下載 Win32 版本,並解壓縮到 c:\rrdtool 資料夾。
4. PHP 4.3.6+ or 5.x – 請安裝在 c:\php 資料夾(Do not install into a path containing spaces (i.e. C:\Program Files\))
5. MySQL 4.x or MySQL 5.x – 請安裝在預設的資料夾。MySQL 5 is completely supported in Cacti 0.8.6i +
6. Net-SNMP:用於偵測設備狀態

◎ 設定PHP
(假如使用 PHP 4 建議將安裝目錄選在 c:\php 下面)
1. 增加系統變數 PATH = c:\php(系統變數的設定在 控制台 → 系統 → 進階 → 環境變數 → 系統變數)
2. 新增一個新的系統變數 PHPRC = c:\php
3. 新增一個新的系統變數 MIBDIRS,使用 PHP4 設定為 c:\php\mibs,PHP5 則設定為 c:\php\extras\mibs
4. 將您的 php.ini 移到 c:\php 下面
5. 使用 PHP 4 請將 php.ini 下列選項 uncomment:
[php]
extension_dir = c:\php\extensions
extension = php_snmp.dll
extension = php_sockets.dll
cgi.force_redirect = 0
[/php]

PHP 5 uncomment 下列選項:
[php]
extension_dir = c:\php\ext
extension = php_mysql.dll
extension = php_snmp.dll
extension = php_sockets.dll
cgi.force_redirect = 0
[/php]
6. 若使用 PHP 4.3.5 或者更舊版本,請建立一資料夾 c:\tmp,並修改 php.ini 如下:
uncomment session.save_path = c:\tmp
4.3.6+ 則將此選項 comment 起來。
7. 假如您想上傳檔案(ie. templates…)請將 php.ini 下列選項 uncomment:
file_uploads = On

◎Configure the Webserver – IIS
1. Under the Default Web Site, right click on Cacti and select Properties.
2. Under the Directory tab, click the Write checkbox..
3. Give the COMPUTERNAME\IUSR_XXXX and COMPUTERNAME\IIS_WPG users READ & EXECUTE permissions to the file C:\Windows\system32\cmd.exe.
Both users will also need READ permissions on c:\inetpub\wwwroot\cacti\ and its subfolders.
4. IIS6: Give the IIS_WPG user modify permissions to the folders /cacti/log and /cacti/rra.
IIS5: Give the IUSR_XXXX user modify permissions to the folders /cacti/log and /cacti/rra.
5. Completely stop and start the IIS service using the following commands:
[bash]
net stop iisadmin
net start w3svc
[/bash]

◎ MySQL 設定
1. 停止 MySQL 服務
2. 修改 MySQL 安裝目錄\my.ini,將 [bash]sql-mode = “STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”[/bash] comment 起來。
3. If you’re running MySQL 4.1 or 5, then you will need to apply the old password trick for user authentication to work with Cacti.
Add the following to my.ini the [mysqld] sub-section:
[bash]
#Use old password encryption method (needed for 4.0 and older clients).
old-passwords[/bash]
4. START MySQL service
5. 新增一個 cacti 資料庫:[bash]shell> mysqladmin –user=root –password create cacti[/bash]
6. 然後匯入 web_root/cacti/cacti.sql 這一個檔案:
[bash]mysql –user=root –password cacti < c:\inetpub\wwwroot\cacti\cacti.sql[/bash] 7. Create a MySQL username and password for Cacti.(本例是 username: cactiuser, password: cactipw) [bash] shell> mysql –user=root –password mysql
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘cactipw’;
mysql> flush privileges;
[/bash]
8. You will also need to update the cactiuser account with the old password style:
[bash]
shell> mysql –user=root –password mysql
shell> UPDATE mysql.user SET Password = OLD_PASSWORD(‘cactipw’) WHERE Host = ‘localhost’ AND User = ‘cactiuser’;
mysql> FLUSH PRIVILEGES;
[/bash]
9. You should see the following after issuing the UPDATE command:
[bash]
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0[/bash]

◎ 安裝 Net-Snmp
1. 原始 Cacti 在 Windows 下只能監測 LOGGING USER & PROCESS,要偵測網路流量、CPU 資訊及 HD、RAM 用量就要用到 Net-Snmp。從官網下載最新版本的 Win32檔案:net-snmp-5.4.0-1.win32.exe。
2. 將它安裝在 c:\net-snmp 下面,按照預設值下一步安裝。裝完就好,不要將它 REGISTER 成服務,因為要用 Windows 內建的SNMP。(You do NOT need to install/use the Net-SNMP SNMP agent. The Microsoft SNMP agent is recommended.)
3. 修改系統變數 MIBDIRS 加入 C:\Net-SNMP\share\snmp\mibs
4. 測試是否安裝成功,在CMD執行 [bash]snmptranslate -IR -Td IF-MIB::linkDown[/bash],檢查有無出現以下訊息:
[bash]
IF-MIB::linkDown
linkDown NOTIFICATION-TYPE
— FROM IF-MIB
OBJECTS { ifIndex, ifAdminStatus, ifOperStatus }
DESCRIPTION “A linkDown trap signifies that the SNMP entity, acting in
an agent role, has detected that the ifOperStatus object for
one of its communication links is about to enter the down
state from some other state (but not from the notPresent
state). This other state is indicated by the included value
of ifOperStatus.”
::= { iso(1) org(3) dod(6) internet(1) snmpV2(6) snmpModules(3) snmpMIB(1)
snmpMIBObjects(1) snmpTraps(5) 3 }
[/bash]
若出現 IP-MIB: Module not found 類似訊息,檢查第 3 點的 MIBDIRS 設定,若已設定好,登出再重新登入測試。

◎ 啟動本機 SNMP
1. 要偵測本機的 snmp 狀態請啟用它
開啟控制台 → 新增移除程式 → 新增移除Windows元件 → Management and Monitoring Tools → Simple Network Management Protocol
將它打勾後點選確定並啟動它。

2. 到服務設定 SNMP Service -> Agent代理程式下面的服務全打勾,才可以偵測 HD 和 RAM
snmp 設定
->Traps 設陷,群體名稱 public,加入清單
snmp 設定
->Security 安全性,新增接受的群體名稱 public,唯讀
snmp 設定
然後重新啟動服務。

3. 以命令提示字元(cmd.exe)執行以下兩道指令:
●指令 1:[bash]snmpwalk -v 1 -c public localhost 1.3.6.1.2.1.1.3[/bash]

有無出現類似訊息
[bash]DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (6185177) 17:10:51.77[/bash]
●再執行指令 2:[bash]snmpwalk -v 1 -c public localhost .1.3.6.1.2.1.2.2.1.1[/bash]
檢查有無出現
[bash]IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.65539 = INTEGER: 65539[/bash]

若無類似以上二者訊息,檢查防火牆是否阻擋 snmp 以及 SNMP service 設定。

◎ 設定 Cacti
1. 編輯 c:\inetpub\wwwroot\cacti\include\config.php 符合您的 MySQL 資訊。
[php]
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “cactipw”;
[/php]
2. 如果 using php 5.2.1, a bug with cacti’s cmd.php file. Code:
“PHP cmd.php”: I get “CMDPHP: Poller[0] ERROR: The PHP Script: CMD.PHP Must be started using the full path to the file and in lower case. This is a PHP Bug!!!”
For an unofficial patch, find the following line near the top of \cacti\cmd.php and change it to:
–> 將原本的 “<" 改為 ">=”
[php]
//略…
if (version_compare(“5.2.0”, PHP_VERSION, “>=”)) {
//略…
}
//略…
[/php]
3. 連上 http://your_server/cacti/ 會要求登入,先以 admin/admin,進入後會立即要求更改密碼
進入後會問是新安裝還是升級,選 new install
接著有路徑設定,若前面都設定好,cacti 會偵測出各所需元件的路徑,記得每個都要檢查過是否無誤(cactid不用)
RRDTool Default Font Path:
c:/windows/fonts/arial.ttf -> 可改成 c:/rrdtool/VeraMono.ttf,顯示在圖形上才會對齊

RRDTool Version:
Select the appropriate version 1.2

SNMPGET, SNMPWALK, SNMPBULKWALK, SNMPGETNEXT Paths:
c:/net-snmp/bin/snmpget.exe
c:/net-snmp/bin/snmpwalk.exe
c:/net-snmp/bin/snmpbulkwalk.exe
c:/net-snmp/bin/snmpgetnext.exe

Cacti Logfile Path:
c:/inetpub/wwwroot/cacti/log/cacti.log

然後按 finish。
註:若在首頁出現 “Warning: system() [function.system]: Unable to fork …”,檢查 cmd.exe 權限設定是否完成。
4. 左方的 Devices,Delete Localhost,因為原始設定是給 Linux 用的,
In the upper right corner, click on Add. Fill in the following information and then click Add.
Description: localhost(自訂)
Hostname: localhost
Host Template: Windows 2000/XP

5. 進入後,檢查上方有無 SNMP Information,若是 SNMP ERROR,在中間 SNMP Community -> public,
另外 SNMP Version 設 version 1 數值才正常
檢查下方Data Queries 有無 3 個 SNMP MOUNTED PARTITIONS, PROCESSOR INFORMATION, INTERFACE STATISTICS
和右邊 STATUS 是不是 SUCCESS 並偵測到 [xx Items, x Rows]
6. Device 完成後按右上角 Creat Graphs for this host,選擇要監測的設備,不用作任何設定 create 即可
7. 接著以cmd執行 php.exe c:\inetpub\wwwroot\cacti\poller.php
測試有無類似訊息
OK u:0.00 s:0.06 r:1.32
OK u:0.00 s:0.06 r:1.32
OK u:0.00 s:0.16 r:2.59
OK u:0.00 s:0.17 r:2.62
10/28/2005 04:57:12 PM – SYSTEM STATS: Time:4.7272 Method:cmd.php Processes:1 Threads:N/A Hosts:1 HostsPerProcess:2 DataSources:4 RRDsProcessed:2
有就是快成功啦,到 cacti/log 和 cacti/rra 下面檢查是否有cacti.log,*.rrd 那些都是產生圖表必備檔案

◎ 定時執行命令
1. 點選開始 → 設定 → 控制台 → 排定的工作
2. 點新增排定工作 → 下一步 → 點選瀏覽 → 並選擇 C:\PHP\php.exe(If using PHP 5 with Cacti 0.8.6f or earlier, use php-win.exe instead.)
3. 輸入排程名稱 選擇每日執行 → 下一步
4. 這邊不要變更 → 下一步
5. 輸入執行者的名稱及密碼 → 下一步,此帳號需有 /log 和 /rra 的修改權限
6. 完成 → 勾起按下[完成]後開啟這項工作的進階內容
7. 選擇上方選項裡的 → 工作 將執行裡的指令改成(請注意您的 poller.php 檔案的位置)
c:\php\php.exe c:\inetpub\wwwroot\cacti\poller.php
8. 選擇上方選項裡的 → 排程 點選進階
9. 勾選 重覆執行 → 每隔改成 5 分鐘 → 直到:改成期間 24 小時 0 分鐘,勾選 如果工作還在執行就停止它

大功告成!