Cacti的設置以及Spine輪詢器

Cacti的設置  php

    接着上一篇的cacti系列講解,在配置選項中有兩個子項目,Settings和Plugin Management。咱們點擊Settings後,出現如下界面。
mysql

wKiom1PoDdGwpcgIAAQaoHPu__g367.jpg

咱們看到上圖中,箭頭指向的地方,咱們能夠針對這些項目進行設置。sql

首先咱們看一下「General」,通用配置,配置的內容主要有如下幾項bash

  • 日誌服務器

  • SNMP相關的設置多線程

  • 其餘配置ide

其實這裏基本上不須要進行修改,保持默認的配置便可。若是須要修改,也就是「Required Tool Versions」和「SNMP Defaults」,修改後點擊「Save」。
工具


接下來看「Path」選項,很明顯,這是和路徑相關的。主要配置的內容有測試

  • 所需工具的路徑(snmp, rrdtool, php)優化

  • Cacti日誌文件的存放路徑

  • Spine輪詢優化器的路徑(在下面的內容中咱們立刻講解)

  • 結構化RRD路徑(勾選此選項,那麼每個主機的RRD文件會單獨存放在某個目錄下)

    咱們看到,這裏的配置路徑和剛開始安裝和初始化Cacti時的檢測的一致。全部的配置保持默認便可,基本不須要配置。

    惟一咱們下面須要更改的地方就是 【Alternate Poller Path】, 先記住,咱們下面再說。

wKiom1PoEbmBnyzZAAA98ULKqu4901.jpg


接下來看「Poller」選項,Cacti採集器的配置,主要配置內容有

  • 通用配置

  • 採集器參數設置

  • 主機高可用配置

  • 主機在線/宕機配置

    在Poller配置中咱們能夠選擇「Poller Type」(採集器類型),cmd.php及poller.php採集器,此採集器是用php編寫的,功能比較簡單。另外一種是spine採集器,是多線程的,效率比較高,適合大規模的監控。等一下咱們就會詳細介紹spine的安裝使用,這裏先別動。

wKiom1PoG52T2w64AAEjjE4JCxk324.jpg


接下來是「Graphs Export」選項,能夠將咱們生成的圖片導出到什麼地方。能夠導出到本地,或是遠程FTP服務器上,主要的配置選項有:

  • 通用配置

  • 圖形樹配置

  • 縮略圖配置

  • 路徑配置

  • 導出時間配置FTP選項等

咱們通常不須要導出圖形。


下面是「Visual」選項,主要設置Cacti頁面是如何顯示的,主要配置有

  • 圖形管理配置

  • 數據查詢配置

  • 圖形建立配置

  • 數據源顯示配置

  • 主機顯示配置

  • 日誌管理配置

  • 默認的RRDTool工具配置

保持默認的配置便可。


最後,咱們講解「Authentication」選項,主要有四種認證方式,分別爲:

  • 無             無認證方式,全部的用戶都將擁有所有訪問權限(危險)

  • 內建驗證       Cacti控制用戶認證,這將容許你創建用戶並設置它們訪問Cacti的權限。

  • WEB基本認證    經過Apache控制用戶認證,若是定義了模板用戶,新用戶將在第一次登錄時被建立,不然將會使用已定義的來賓用戶權限。

  • LDAP認證       容許將認證交給LADP服務器,若是定義了模板用戶,新用戶將在第一次登陸時被建立,不然,將會使用已定義的來賓用戶權限,若是沒有啓用PHP的LDAP模塊,下拉菜單中不會出現LDAP認證。

一般,咱們會選擇內建驗證。


開啓匿名訪問用戶:guest

第一步:User management -> 出現用戶列表, 點擊「用戶名」

User management -> 點擊「guest」, 會出現以下界面,勾選 Enabled

wKioL1PoIZbAUd7DAAQEr64sTJs123.jpg

第二步:針對graph等進行默認的權限設置。也就是被圈住的各個選項,分別配置其訪問的權限。



Cacti優化之spine輪詢器

   咱們知道cacti經過poller.php驅動其餘數據收集方法或腳本週期性的執行。因爲效率的緣由,在須要大量採集數據時,若是使用自帶的cmd.php輪詢器會比較慢,1分鐘1次的採集頻率可能沒法完成輪詢全部的被監控的機器。爲了解決效率問題,Cacti官方也推出spine,採用多線程的方式高效的輪詢。

這裏直接引入官方的文檔http://www.cacti.net/spine_install.php

Spine Installation

Spine needs to be compiled before it can be used. If you found a binary package of Spine for your operating system, you can skip the next step about compiling Spine.

Compiling Spine


Compiling Spine for Redhat/Fedora Linux

Before you continue, check if any pre-compiled packages are available for your version of Redhat/Fedora Linux. These instructions will help you compile Spine from source if no binary packages are available.

Prerequisites

Make sure that the following packages are installed before attempting to compile Spine:

  • net-snmp-devel

  • mysql

  • mysql-devel

  • openssl-devel

Compiling Spine

Download the latest source distribution of Spine and run the following commands to get a working binary:

tar xvzf cacti-spine-0.8.7.tar.gz
cd spine-0.8.7
./configure
make

Now you must move your new binary, spine and spine.conf to a more permanent home such as /usr/local/spine. Edit thespine.conf file and specify your database connection information for Cacti.

You should now be ready to start using Spine!


Setting Up Spine

Once Spine is installed on your system, you must perform the following steps to make your Cacti installation aware of it.

  1. Login to Cacti as an admin user.

  2. Select Settings on the menu and click the Paths tab.

  3. Enter the complete path to your Spine binary in the Spine Poller File Path field and click Save.

  4. Click the Poller tab.

  5. Choose "spine" from the Poller Type dropdown box and click Save.

After completing these steps, Cacti will spawn Spine every 5 minutes instead of cmd.php. If you are having problems getting Spine to gather data, you can always temporarily change Poller Type back to "cmd.php".


鑑於有些同窗看着英文就有點頭暈,這裏我也演示一下,若是安裝及設置spine。

一、解決依賴關係

## spine 依賴於mysql mysql-devel net-snmp-devel openssl-devel
## 咱們在安裝cacti的時候已經安裝 mysql  mysql-devel 因此,這裏只需安裝另外2個
[root@localhost ~]# yum -y install  net-snmp-devel openssl-devel

二、下載並安裝spine下載的版本最好與cacti一致,spine-0.8.8b

# 下載地址, 下載和 cacti 版本一致的spine
http://www.cacti.net/downloads/spine/

[root@localhost ~]# tar xf cacti-spine-0.8.8b.tar.gz 
[root@localhost ~]# cd cacti-spine-0.8.8b
[root@localhost cacti-spine-0.8.8b]# ./configure
[root@localhost cacti-spine-0.8.8b]# make && make install

# 默認安裝在/usr/local/spine/目錄下。

三、提供配置文件

[root@localhost ~]# cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
## 編輯配置文件,請根據實際狀況修改
[root@localhost ~]# vi /etc/spine.conf 
DB_Host         localhost
DB_Database         cactidb
DB_User         cactiuser
DB_Pass         cactiuser
DB_Port         3306
DB_PreG         0

# 這裏的配置是怎麼來的呢? 還記得吧, 就是 cacti/include/config.php
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;

四、測試是否正常

[root@localhost ~]# /usr/local/spine/bin/spine
## 報錯了
MYSQL: Connection Failed: Error:'2003', Message:'Can't connect to MySQL server on 'shuttle' (61)'
05/12/2012 07:14:22 PM - SPINE: Poller[0] FATAL: Connection Failed, Error:'2003', Message:'Can't connect to MySQL server on 'shuttle' (61)' (Spine init)

## google了一下
You probably checked it out already but make sure: 
DB_Host 127.0.0.1
and NOT
DB_Host localhost

wKioL1PoK5_RMHa4AABsxGQF3o0675.jpg

OK, 再測試一下:

[root@localhost ~]# /usr/local/spine/bin/spine 
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8b starting
SPINE: Time: 0.1707 s, Threads: 5, Hosts: 2
[root@localhost ~]#

五、在cacti的WEB頁面設置spine的路徑

 前面,咱們已經提到了。

Console -> 【Configureation】下的 Settings -> 【Paths】標籤下 Alternate Poller Path -> Spine Poller File Path

輸入spine的路徑:默認安裝在/usr/local/spine/bin/spine

wKiom1PoK5iRqptOAAFQqsCfm8g626.jpg

六、修改Cacti默認的Poller Types

剛纔Paths標籤旁邊 【Poller】 -> Poller Type

在下拉框中,選擇spine, 而後記得「Save」

wKioL1PoLTDh7Q8PAACj-QuoBLk804.jpg

注意:Spine沒必要爲其添加計劃任務,Cacti well spawn Spine every 5 minutes instead of cmd.php

而poller.php須要定義計劃任務去執行,而後poller.php再去調度數據收集方法。

小結一下:

a)以admin用戶登陸到Cacti。
b)從目錄菜單中選擇設置」Settings」,選擇」Paths」選項卡。
c)在」Spine Poller File Path」中輸入Spine可執行程序的完整路徑,個人是/usr/local/spine/bin/spine,保存設置。
d)選擇」Poller」選項卡。
e)在」Poller Type」下拉框設置中,選擇」spine」。並設置poller, cron間隔時間。

查看下Cacti日誌:

01/17/2012 11:31:02 PM – SYSTEM STATS: Time:1.1105 Method:spine Processes:1 Threads:1 Hosts:4 HostsPerProcess:4 DataSources:51 RRDsProcessed:27

原來的以下:
01/17/2012 10:46:03 PM – SYSTEM STATS: Time:1.5050 Method:cmd.php Processes:1 Threads:N/A Hosts:4 HostsPerProcess:4 DataSources:51 RRDsProcessed:27

查看服務器的流量圖正常。


poller.php 與 cmd.php和spine 之間是什麼關係呢?這裏有必要說明一下。

    poller.php顧名思義,就是輪詢器。它是cacti可以週期性獲取數據原始驅動。poller.php是cacti獲取數據的一個工具,這個工具是沒有辦法替代的,cacti必須使用poller.php才能正常工做。而後poller.php負責調用cmd.php或者spine。

    能夠這樣認爲,poller.php是最終彙總數據的,而cmd.php是獲取數據的就行。poller.php發出獲取數據的信號,告訴cmd.php 去獲取數據,而後cmd.php就會調用那些定義好的數據收集方法去獲取數據。

    poller.php能夠調用cmd.php, 可是因爲cmd.php效率不高,最短執行週期是5分鐘,所以cacti提供了一個更高效的工具spine來替代cmd.php,最短執行週期1分鐘,能夠極大的提升效率。

    因此,不管是使用cmd.php,仍是spine, 咱們都必須設置 poller.php 的 cron 計劃任務,讓poller.php去驅動cmd.php或者spine工做。

    在cacti設置中,選擇poller type 是 spine, 而後把poller Interval 改成Every Minute, 同時也把Cron Interval改成Every Minute。 而後, 咱們還須要把poller.php的計劃任務改成每分鐘執行一次。

    spine是根據咱們設定Poller Interval設置的值運行的,poller.php則是咱們cron計劃任務控制運行的,結果就是按照cron中定義的進行彙總。最好把Poller Interval 和 cron 定義的週期相同,不然可能出現偏差,莫名其妙的問題。

wKioL1RCOXCgs15AAAQIx3Wb-vI580.jpg

### 這裏的路徑,請根據實際狀況更改
## 對於spine
*/1 * * * *  path/to/your/php /usr/share/cacti/poller.php > /dev/null 2>&1

## 對於cmd.php
*/5 * * * * path/to/your/php /usr/share/cacti/poller.php > /dev/null 2>&1





好了, 到這裏就結束了。下一篇繼續講解。

相關文章
相關標籤/搜索