天天看點

實戰2 Cacti監控本地主機和遠端主機

上篇博文主要講解了cacti監控host主機,由于上篇博文cacti的版本也不是最新的!是以在實戰2更新了cacti的版本,并添加了監控遠端伺服器和優化輪詢

實戰2 重點

一、新版cacti監控host

二、新版cacti監控Remote Host

三、新版cacti優化spine輪詢

附加

四、網卡流量和存儲挂在盤

1、安裝lamp平台

1

<code>[root@cacti ~]</code><code># yum install -y httpd php php-mysql php-snmp php-xml php-gd mysql mysql-server gd gd-devel</code>

2、啟動服務,設定開機自啟動

2

3

4

<code>[root@cacti ~]</code><code># service httpd start</code>

<code>[root@cacti ~]</code><code># service mysqld start </code>

<code>[root@cacti ~]</code><code># chkconfig httpd on</code>

<code>[root@cacti ~]</code><code># chkconfig mysqld on</code>

3、測試httpd是否能夠正常工作

<a href="http://s3.51cto.com/wyfs02/M02/2F/4D/wKioL1OfBH_TB2qiAAVbVIADMd8978.jpg" target="_blank"></a>

4、測試php能夠正常工作

[root@cacti ~]# cat /var/www/html/a.php 

&lt;?php

phpinfo();

?&gt; 

<a href="http://s3.51cto.com/wyfs02/M00/2F/4D/wKioL1OfBJOh-OKHAARPr-erEVI067.jpg" target="_blank"></a>

好了,到此lamp就安裝完成了

3、安裝net-snmp

<code>[root@cacti ~]# yum install -y net-snmp net-snmp-utils</code>

4、修改snmp的配置檔案

5

6

7

8

9

10

11

12

13

14

15

16

17

<code>[root@cacti ~]</code><code># cd /etc/snmp/</code>

<code>[root@cacti snmp]</code><code># cp snmpd.conf snmpd.conf.bak </code>

<code>[root@cacti snmp]</code><code># vim snmpd.conf</code>

<code>去掉末尾.1</code>

<code>#view    systemview    included   .1.3.6.1.2.1.1</code>

<code> </code><code>view    systemview    included   .1.3.6.1.2.1</code>

<code>啟動net-snmp,并測試net-snmp能夠正常工作</code>

<code>[root@cacti ~]</code><code># service snmpd start</code>

<code>Starting snmpd:                                            [  OK  ]</code>

<code>[root@cacti ~]</code><code># snmpnetstat -v 2c -c public -Ca -Cp tcp localhost</code>

<code>Active Internet (tcp) Connections (including servers)</code>

<code>Proto Local Address          Remote Address         (state)</code>

<code>tcp   *.</code><code>ssh</code>                  <code>*.*                   LISTEN</code>

<code>tcp   *.mysql                *.*                   LISTEN</code>

<code>tcp   localhost.smtp         *.*                   LISTEN</code>

<code>tcp   localhost.smux         *.*                   LISTEN</code>

<code>tcp   localhost.</code><code>ssh</code>          <code>localhost.53011       ESTABLISHED</code>

5、安裝RRDTool

<code>[root@cacti ~]</code><code>#  yum install -y rrdtool </code>

<code>測試RRDTool能夠正常工作</code>

<code>[root@cacti ~]</code><code># rrdtool -v</code>

<code>RRDtool 1.3.8  Copyright 1997-2009 by Tobias Oetiker &lt;[email protected]&gt;</code>

<code>               </code><code>Compiled Aug 21 2010 10:57:18</code>

<code>Usage: rrdtool [options] </code><code>command</code> <code>command_options</code>

<code>Valid commands: create, update, updatev, graph, graphv,  dump, restore,</code>

<code>  </code><code>last, lastupdate, first, info, fetch, tune,</code>

<code>  </code><code>resize, xport</code>

<code>RRDtool is distributed under the Terms of the GNU General</code>

<code>Public License Version 2. (www.gnu.org</code><code>/copyleft/gpl</code><code>.html)</code>

<code>For </code><code>more</code> <code>information </code><code>read</code> <code>the RRD manpages</code>

6、安裝配置cacti

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

<code>[root@cacti src]</code><code># tar xf cacti-0.8.8b.tar.gz -C /var/www/html/</code>

<code>[root@cacti src]</code><code># cd /var/www/html/</code>

<code>[root@cacti html]</code><code># ll</code>

<code>total 8</code>

<code>drwxr-xr-x. 13 1000 </code><code>users</code> <code>4096 Aug  6  2013 cacti-0.8.8b</code>

<code>[root@cacti html]</code><code># mv cacti-0.8.8b cacti </code>

<code>#建立cacti資料庫,并導入cacti.sql到資料庫中</code>

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

<code>[root@cacti cacti]</code><code># mysqladmin create cactidb</code>

<code>[root@cacti cacti]</code><code># ll cacti.sql                #cacti源碼包中自帶的cacti資料庫</code>

<code>-rw-r--r--. 1 1000 </code><code>users</code> <code>178349 Aug  6  2013 cacti.sql</code>

<code>[root@cacti cacti]</code><code># mysql cactidb &lt; cacti.sql   #導入自帶的cacti資料庫</code>

<code>#建立授權使用者</code>

<code>[root@cacti ~]</code><code># mysql -e "GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'"</code>

<code>[root@cacti ~]</code><code># mysqladmin flush-privileges</code>

<code>[root@cacti ~]</code><code># mysql -ucactiuser -pcactiuser</code>

<code>Welcome to the MySQL monitor.  Commands end with ; or \g.</code>

<code>Your MySQL connection </code><code>id</code> <code>is 6</code>

<code>Server version: 5.1.73 Source distribution</code>

<code>Copyright (c) 2000, 2013, Oracle and</code><code>/or</code> <code>its affiliates. All rights reserved.</code>

<code>Oracle is a registered trademark of Oracle Corporation and</code><code>/or</code> <code>its</code>

<code>affiliates. Other names may be trademarks of their respective</code>

<code>owners.</code>

<code>Type </code><code>'help;'</code> <code>or </code><code>'\h'</code> <code>for</code> <code>help. Type </code><code>'\c'</code> <code>to </code><code>clear</code> <code>the current input statement.</code>

<code>mysql&gt; show databases;</code>

<code>+--------------------+</code>

<code>| Database           |</code>

<code>| information_schema |</code>

<code>| cactidb            |</code>

<code>| </code><code>test</code>               <code>|</code>

<code>3 rows </code><code>in</code> <code>set</code> <code>(0.01 sec)</code>

<code>mysql&gt; \q</code>

<code>Bye</code>

<code>#修改cacti連接配接資料庫的程式檔案</code>

<code>[root@cacti ~]</code><code># cd /var/www/html/cacti/include/</code>

<code>[root@cacti include]</code><code># cp config.php config.php.bak</code>

<code>[root@cacti include]</code><code># vim config.php</code>

<code>/* </code><code>make</code> <code>sure these values refect your actual database</code><code>/host/user/password</code> <code>*/</code>

<code>$database_type = </code><code>"mysql"</code><code>;</code>

<code>$database_default = </code><code>"cactidb"</code><code>;   </code><code>#修改使用的資料庫</code>

<code>$database_hostname = </code><code>"localhost"</code><code>;</code>

<code>$database_username = </code><code>"cactiuser"</code><code>;</code>

<code>$database_password = </code><code>"cactiuser"</code><code>;</code>

<code>$database_port = </code><code>"3306"</code><code>;</code>

<code>$database_ssl = </code><code>false</code><code>;</code>

<code>/*</code>

<code>   </code><code>Edit this to point to the default URL of your Cacti </code><code>install</code>

<code>   </code><code>ex: </code><code>if</code> <code>your cacti </code><code>install</code> <code>as at http:</code><code>//serverip/cacti/</code> <code>this</code>

<code>   </code><code>would be </code><code>set</code> <code>to </code><code>/cacti/</code>

<code>*/</code>

<code>//</code><code>$url_path = </code><code>"/cacti/"</code><code>;</code>

<code>#下面我們來建立一個cacti使用者(安裝初始化cacti)并修改相關目錄權限,</code>

<code>[root@cacti cacti]</code><code># useradd cactiuser</code>

<code>[root@cacti cacti]</code><code># chown -R cactiuser:cactiuser log/ rra/</code>

7、浏覽器通路cacti

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKiom1OfDBaDglOAAAO6gB3cRlE242.jpg" target="_blank"></a>

點選【Next】 進行下一步安裝

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfDCuQ-10HAAHMUUCurS4194.jpg" target="_blank"></a>

選擇【New Install】,點選【Next】進行下一步安裝

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfDIjAfgQOAATVFgK8s2A738.jpg" target="_blank"></a>

監測是否有權限錯誤,如果有,請修改對應目錄的權限,然後點選【Finsh】,進行下一步

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKiom1OfDRaB-LhMAAF1mkalPkc890.jpg" target="_blank"></a>

輸入賬戶和密碼,預設都是admin,點選【Login】,進行下一步

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfDRXiJBjkAAG0wZOkqGM922.jpg" target="_blank"></a>

系統提示:強制修改密碼,然後平【Save】,進行下一步安裝;進入cacti的首頁面

大家可以從圖上看到,由于我們還沒做任何配置,是以這裡沒有任何圖像。好了,下面我們就來詳細說一說這兩個标簽中内容。先說,console 标簽。

大家先看左邊這一欄,從圖中我們可以看出,大緻分為七個大項和多個項目。下面我們來的羅列一下,分别講解。

(1).Create 建立

New Graphs 添加新圖形

(2).Management 管理

Graph Management 圖形管理。可以在此删除、複制圖像,Cacti會自動建立圖像。不過如果我們有特殊的需要,比如将幾張圖上的資料合并在一張圖像上的話也可以在此手工建立圖像;

Graph Trees 圖形樹。在graphs界面裡,圖像或devices是樹狀結構顯示的,可以在此設定樹的結構;

Data Sources 資料源。記要用來管理rrd檔案的,一般無需修改,Cacti會自己建立rrd檔案;

Devices 裝置管理。這是我們最經常需要修改的地方,可以在此建立新的裝置或修改其名稱等資訊。

(3).Collection Methods 資料收集方法,一般我們無需對這兩項進行修改。(非常重要在下面的内容中進行詳解)

Data Queries 資料查詢,

Data Input Methods 資料輸入方法

(4).Templates 模闆,這些模闆可以導出、導入也可以自己編寫,一般無需修改。

Graph Templates 圖形模闆

Host Templates 主機模闆

Data Templates 資料模闆

(5).Import/Export 導入/導出,對上述模闆的導入、導出。我們可以在Cacti的官方網站上找到這些模闆,不過需要注意模闆對于的Cacti的版本。

Import Templates 導入模闆

Export Templates 導出模闆

(6).Configuration 配置

Settings 系統設定,Cacti的主要配置菜單;可以在此重新設定對應的程式的路徑、版本等資訊。也可以設定圖像的輸出方式(允許ftp)、顯示效果、登陸方式(允許使用LDAP)等。

Plugin Management 插件管理

(7).Utilities 工具

System Utilities 系統工具,顯示Cacti系統的一些cache和log資訊,如果log檔案太大建議直接到背景檢視;

User Management 使用者管理,可以在此添加、删除使用者,并對每個使用者設定詳細的權限;

Logout User 使用者退出

裡面的具體内容請大家自己去看,下面我們來講解一下第三大項收集方法,收集方法即資料收集方法。其中,有兩種方法:

資料查詢:xml格式資料收集方法

資料輸入方法:指令或腳本(比較常用)

注,腳本隻需要指定如何擷取資料,并且擷取到的資料經過處理後要按元寶輸出。案例,

<code>TAG:data TAG:data</code>

<code>input:30 output:40</code>

好了,我們用腳本定義了收集資料方法,也指定了資料輸出,那腳本多長時間執行一次呢?執行的時間是cacti程式設定的,下面我們來配置cacti安裝的最重要的一步也是最後一步,設定cacti收集資料的預設的任務計劃。這裡任務計劃是由poller.php程式執行的,需要說明的是poller.php是由php寫的,單線程的功能相對較弱,為此cacti官方單獨開發了一個多線程Spine工具,适合大規模監控應用。好了下面我們就來配置一下任務計劃并檢視。

<code>[root@cacti ~]</code><code># echo '*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php  &amp;&gt;/dev/null' &gt; /var/spool/cron/cactiuser </code>

<code>[root@cacti ~]</code><code># crontab -u cactiuser -l </code>

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

為了防止這個任務計劃不執行,我們最好手動驗證一下

<code>[root@cacti ~]</code><code># su cactiuser</code>

<code>[cactiuser@cacti root]$  </code><code>/usr/bin/php</code> <code>/var/www/html/cacti/poller</code><code>.php </code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 165</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 165</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 166</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 166</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 167</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 167</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 168</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 168</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 169</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 169</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 170</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 170</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 171</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_constants</code><code>.php on line 171</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 671</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 671</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 672</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 672</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 673</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 673</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 674</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 674</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 675</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 675</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 676</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 676</code>

<code>PHP Warning:  strtotime(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 677</code>

<code>PHP Warning:  </code><code>date</code><code>(): It is not safe to rely on the system</code><code>'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 '</code><code>America</code><code>/New_York</code><code>' for '</code><code>EDT</code><code>/-4</code><code>.0</code><code>/DST</code><code>' instead </code><code>in</code> <code>/var/www/html/cacti/include/global_arrays</code><code>.php on line 677</code>

輸出後有警告資訊,提示時區有問題;接下來我們來修改php配置檔案的時區

<code>[root@cacti ~]</code><code># vim /etc/php.ini  </code>

<code>[Date]</code>

<code>; Defines the default timezone used by the </code><code>date</code> <code>functions</code>

<code>; http:</code><code>//www</code><code>.php.net</code><code>/manual/en/datetime</code><code>.configuration.php</code><code>#ini.date.timezone</code>

<code>;</code><code>date</code><code>.timezone =</code>

<code> </code><code>date</code><code>.timezone = Asia</code><code>/Shanghai</code>

<code> </code> 

<code>[root@cacti ~]</code><code># service httpd restart</code>

<code>Stopping httpd:                                            [  OK  ]</code>

<code>Starting httpd:                                            [  OK  ]</code>

接下來我們再來測試一下

<code>#檢視一下cacti輸出日志</code>

<code>[cactiuser@cacti root]$ </code><code>cd</code> <code>/var/www/html/cacti/log</code>

<code>[cactiuser@cacti log]$ </code><code>tail</code> <code>-f </code>

<code>cacti.log  .htaccess  </code>

<code>[cactiuser@cacti log]$ </code><code>tail</code> <code>-f cacti.log </code>

<code>06</code><code>/16/2014</code> <code>07:35:02 PM - SYSTEM STATS: Time:0.5954 Method:cmd.php Processes:1 Threads:N</code><code>/A</code> <code>Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5</code>

<code>06</code><code>/16/2014</code> <code>07:40:02 PM - SYSTEM STATS: Time:0.3670 Method:cmd.php Processes:1 Threads:N</code><code>/A</code> <code>Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5</code>

<code>06</code><code>/17/2014</code> <code>07:45:01 AM - SYSTEM STATS: Time:0.2106 Method:cmd.php Processes:1 Threads:N</code><code>/A</code> <code>Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5</code>

7、配置Cacti監控本機

首先我們點選一下“Devices”标簽,出下以下界面,大家從圖中可以看出,預設的主機就是Localhost。

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfFLSAzPQuAALzofzW608100.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfFJfx7peIAAQP2AKp9N8529.jpg" target="_blank"></a>

接下來我們點選一下“Localhost”主機,出現以下界面。

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKiom1OfFOGT-C5yAAUm27XnNwg456.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfFL3jBscmAAYkABNW3Mc425.jpg" target="_blank">上圖是預設的配置,我們隻要修改一處即可,便是“SNMP Options”。如下圖</a>

接下來我們選擇右上腳的“Create Graphs for this Host”(為這個主機增加監控圖形),

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKiom1OfFTqw1DNdAAVI5tZQmAE872.jpg" target="_blank"></a>

我們選擇監控本地主機的磁盤空間,點選“Create”即可。下面我們來點選最上面的“Graph”标簽 。如下圖,

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfFdCC26STAATixwgLJLM853.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfFf6h722aAADXt4lL_OA168.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfFdGQNXXbAAPjtK_LtS4830.jpg" target="_blank"></a>

從圖中我們可以看到我們新增加的監控磁盤空間的圖形還沒有出圖,我們得等個幾分鐘才會出現圖形,請博友耐心等待。好了,過幾分鐘就會出現下面的效果圖

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfFsuAXQ8XAATcphg139g436.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfFvmCCMh0AAQp1rMB558056.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfFsyyNpKHAAO-vyFqqNY925.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKiom1OfFvnCBKSXAAIYQkVSzGM645.jpg" target="_blank"></a>

到這裡我們配置Cacti監控localhost就全部完成了

1、用戶端安裝net-snmp(被監控端)

<code>[root@node1_cacti ~]# yum install -y net-snmp net-snmp-utils net-snmp-libs</code>

2、修改net-snmp配置檔案

<code>[root@node1_cacti ~]# cd /etc/snmp/</code>

<code>[root@node1_cacti snmp]# cp snmpd.conf snmpd.conf.bak</code>

<code>[root@node1_cacti snmp]# vim snmpd.conf </code>

<code>#去掉末尾的.</code><code>1</code>

<code>#view    systemview    included   .</code><code>1.3</code><code>.</code><code>6.1</code><code>.</code><code>2.1</code><code>.</code><code>1</code>

<code> </code><code>view    systemview    included   .</code><code>1.3</code><code>.</code><code>6.1</code><code>.</code><code>2.1</code>

3、啟動服務并設定開啟自啟動

<code>[root@node1_cacti snmp]# service snmpd start</code>

<code>[root@node1_cacti snmp]# chkconfig snmpd on </code>

<code>[root@node1_cacti snmp]# netstat -ntulp </code>

<code>Active Internet connections (only servers)</code>

<code>Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   </code>

<code>tcp        </code><code>0</code>      <code>0</code> <code>0.0</code><code>.</code><code>0.0</code><code>:</code><code>22</code>                  <code>0.0</code><code>.</code><code>0.0</code><code>:*                   LISTEN      </code><code>1039</code><code>/sshd           </code>

<code>tcp        </code><code>0</code>      <code>0</code> <code>127.0</code><code>.</code><code>0.1</code><code>:</code><code>25</code>                <code>0.0</code><code>.</code><code>0.0</code><code>:*                   LISTEN      </code><code>1115</code><code>/master         </code>

<code>tcp        </code><code>0</code>      <code>0</code> <code>127.0</code><code>.</code><code>0.1</code><code>:</code><code>199</code>               <code>0.0</code><code>.</code><code>0.0</code><code>:*                   LISTEN      </code><code>1348</code><code>/snmpd          </code>

<code>tcp        </code><code>0</code>      <code>0</code> <code>:::</code><code>22</code>                       <code>:::*                        LISTEN      </code><code>1039</code><code>/sshd           </code>

<code>tcp        </code><code>0</code>      <code>0</code> <code>::</code><code>1</code><code>:</code><code>25</code>                      <code>:::*                        LISTEN      </code><code>1115</code><code>/master         </code>

<code>udp        </code><code>0</code>      <code>0</code> <code>0.0</code><code>.</code><code>0.0</code><code>:</code><code>161</code>                 <code>0.0</code><code>.</code><code>0.0</code><code>:*                               </code><code>1348</code><code>/snmpd          </code>

<code>udp        </code><code>0</code>      <code>0</code> <code>0.0</code><code>.</code><code>0.0</code><code>:</code><code>68</code>                  <code>0.0</code><code>.</code><code>0.0</code><code>:*                               </code><code>934</code><code>/dhclient</code>

3、在cacti伺服器端測試

<code>[root@cacti ~]# snmpnetstat -v 2c -c </code><code>public</code> <code>-Can -Cp tcp </code><code>192.168</code><code>.</code><code>0.106</code>

<code>tcp   *.</code><code>22</code>                   <code>*.*                   LISTEN</code>

<code>tcp   </code><code>127.0</code><code>.</code><code>0.1</code><code>.</code><code>25</code>           <code>*.*                   LISTEN</code>

<code>tcp   </code><code>127.0</code><code>.</code><code>0.1</code><code>.</code><code>199</code>          <code>*.*                   LISTEN</code>

<code>tcp   </code><code>192.168</code><code>.</code><code>0.106</code><code>.</code><code>22</code>       <code>192.168</code><code>.</code><code>0.102</code><code>.</code><code>55805</code>   <code>ESTABLISHED</code>

好了,這裡我們的實驗環境就全部配置完成。下面我們繼續……

4、cacti監控遠端主機

進入Cacti的console面闆-&gt;點選“Devices”進入裝置面闆-&gt;

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfHlix0LS_AAP0w8atLuo570.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfHlnwXyItAAfSMDcrLyc555.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKiom1OfHoeTTpQGAACoHxsAuwU136.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfHlnwMprAAAUCDcn98Kc397.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKiom1OfHofBRqqzAAPeKnYCNUg886.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfHlqQ1ZRxAAQ2qZAyxMk477.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfHojQIaqFAATse4ZktuE763.jpg" target="_blank"></a>

好了,到這裡我們主機就增加完成了。下面我們來檢視一下。點選“Graph Management”可以看到剛才建立的監測點對應的圖像,注意由于Cacti預設每5分鐘到監測伺服器上取一次資料,是以剛建立的監測點會出現圖像不能顯示的現象,需要等幾分鐘檢視才會正常顯示。

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfH4Dj54a-AAZF1K36B9w398.jpg" target="_blank"></a>

點選分支名稱或“Add”新的分支-&gt;

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKiom1OfIVvSRnBqAAHd2V3kQOI817.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfIS7wJandAAJqZGn2B6Y794.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfIS6zUQwNAAMtyxjqVuQ277.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfIVzzBhaiAAPuRGJC90g784.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfIVyjKQEWAANqSpIoNhM056.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfIS-AVurwAAG7wvEiPFY811.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKiom1OfIV3jRKwLAAWwRaHK1cA929.jpg" target="_blank"></a>

好了,到這裡我們配置的Cacti監控遠端主機配置到這裡就全部完成了

注,出于效率原因,在大量采集資料時使用自帶的cmd.php輪詢器會比較慢,1分鐘1次的采集頻率可能無法完成輪詢所有機器。這裡為了優化,采用官方推薦的spine來高效輪詢。本例使用源代碼編譯安裝,下載下傳的版本是spine-0.8.8b,所用cacti為0.8.8b。

1、解決依賴關系

<code>[root@cacti ~]</code><code># yum install -y mysql-devel net-snmp-devel</code>

2、安裝spine

<code>[root@cacti src]</code><code># yum -y install gcc gcc-c++ make</code>

<code>[root@cacti src]</code><code># tar xf cacti-spine-0.8.8b.tar.gz </code>

<code>[root@cacti src]</code><code># cd cacti-spine-0.8.8b</code>

<code>[root@cacti cacti-spine-0.8.8b]</code><code># ./configure </code>

<code>[root@cacti cacti-spine-0.8.8b]</code><code># make &amp;&amp; make install</code>

3、提供配置檔案并修改

<code>[root@cacti ~]</code><code># cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf </code>

<code>[root@cacti ~]</code><code># vim /usr/local/spine/etc/spine.conf  </code>

<code>#末尾行</code>

<code>DB_Host         localhost</code>

<code>DB_Database     cactidb</code>

<code>DB_User         cactiuser</code>

<code>DB_Pass         cactiuser</code>

<code>DB_Port         3306</code>

<code>DB_PreG         0</code>

4、測試是否能夠正常工作

<code>[root@cacti ~]</code><code># /usr/local/spine/bin/spine -C /usr/local/spine/etc/spine.conf</code>

<code>SPINE: Using spine config </code><code>file</code> <code>[</code><code>/usr/local/spine/etc/spine</code><code>.conf]</code>

<code>SPINE: Version 0.8.8b starting</code>

<code>SPINE: Time: 0.2917 s, Threads: 5, Hosts: 3</code>

5、在cacti裡設定spine路徑

<code>Console -&gt; Configuration -&gt; Settings -&gt; Paths -&gt; Alternate Poller Path -&gt; Spine Poller File Path</code>

輸入spine路徑:/usr/local/spine/bin/spine

<a href="http://s3.51cto.com/wyfs02/M00/2F/4E/wKiom1OfJe2CJ6NgAAaMD6C-Puc721.jpg" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfJb_i4QiTAALxKyve3p4567.jpg" target="_blank"></a>

6. 修改Cacti使用的Poller Type

<code>Console -&gt; Cacti Settings-&gt;Poller-&gt;Poller Type</code>

在下拉中選擇spine,如下圖:

<a href="http://s3.51cto.com/wyfs02/M01/2F/4E/wKiom1OfJmKgr9GuAAYCdarJSaI962.jpg" target="_blank"></a>

好了,到這裡我們spine優化器就安裝完成了,這一篇部落格就到這裡吧

作為網際網路時代,用真實的實體主機做伺服器無非是資源的一種浪費,更多的企業為了減少成本,采用了租用雲主機或者内部的私有化來搭建各種服務。

就是這一種情況的出現,使得絕大多數的存儲盤并不是直接的本地硬碟,而是挂在過來的、這種情況的監控,我們需要額外的添加來實作動态的監控存儲盤

1、點選【console】,然後選擇【Device】後的《cacti server》來作為實驗對象,點選《cacti server》

<a href="http://s3.51cto.com/wyfs02/M00/2F/51/wKiom1OfoICCkVWUAAZQMILtWAw210.jpg" target="_blank"></a>

2、進入《cacti server》選項後,進行添加網卡資料源和挂在磁盤資料源,如下圖

<a href="http://s3.51cto.com/wyfs02/M02/2F/51/wKiom1OfoWqSX9MhAAYLBUrapGk144.jpg" target="_blank"></a>

注意:

SNMP-Interface Statistics                 :接口狀态也就是網卡流量監控的資料源

ucd/net - Get Monitred Partitions    :預設已經添加

Unix - Get Mouted Partitions           :挂載分區的監控

Add Data Query:

選擇完成後,點選添加如同下;表示網卡和存儲盤已經添加

<a href="http://s3.51cto.com/wyfs02/M01/2F/51/wKiom1OfoYWDd-ciAAYN6ayrudA122.jpg" target="_blank"></a>

之後我們選擇:Create Graphs for this host;

<a href="http://s3.51cto.com/wyfs02/M01/2F/51/wKiom1OfoyXDnnaSAAKWxhuRNPo064.jpg" target="_blank"></a>

進入後進行網卡接口的選擇,有三塊網卡,如下圖

lo:本地回環接口

eth0:第一塊網卡 内網卡

eth1:第二塊網卡 外網卡

<a href="http://s3.51cto.com/wyfs02/M02/2F/51/wKioL1Ofo6XhIzlaAATNP9N2YFw532.jpg" target="_blank"></a>

進入後進行挂在盤的選擇,如下圖

這個地方自已在做的時候,出現了一點問題就是找不到存儲盤,明明在系統上可以看到,無論怎麼重新整理都不顯示,最後才明白,多次點選畫黑圈的方框就出來了。

<a href="http://s3.51cto.com/wyfs02/M02/2F/51/wKiom1OfpTHwdGP8AAEwQqfdIT4882.jpg" target="_blank"></a>

到此,網卡和存儲盤的添加就完成了,接下來我們來看看繪圖後的效果

内外網卡的監控

<a href="http://s3.51cto.com/wyfs02/M02/2F/51/wKiom1OfpbTi4x-7AATOKd1eSs0306.jpg" target="_blank"></a>

挂在盤的監控

<a href="http://s3.51cto.com/wyfs02/M01/2F/51/wKiom1OfpbSj1tjAAAR2TmwujyU141.jpg" target="_blank"></a>

到此,實戰2就完成了,期待實戰3

與運維的朋友一起進步。很高興結識很多的朋友

     本文轉自zys467754239 51CTO部落格,原文連結:http://blog.51cto.com/467754239/1427119,如需轉載請自行聯系原作者