監控cacti/nagios/zabbix (一)cacti

cacti 重圖形,有數據歷史,需用到數據庫支持,支持web配置,默認不支持告警,可以加插件;
nagios重狀態和結果,沒有數據歷史,不成圖像,不支持web配置,可以自己開發腳本定製個性化監控,支持多種插件;
zabbix有數據歷史,可成圖像,支持web配置,可以自動發現;


第一部分:監控軟件Cacti搭建

一、環境準備

             1、安裝epel擴展源

  關閉selinux

 臨時關閉 setenforce 0

 vim /etc/selinux/config

 SELINUX=disbabled

1

[root@cacti ~]# yum install -y epel-release

             2、搭建lamp環境

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

[root@cacti ~]# yum install -y  httpd php php-mysql mysql mysql-server mysql-devel php-gd  libjpeg libjpeg-devel libpng-devel

[root@cacti ~]# /etc/init.d/httpd start

正在啓動 httpd:                                           [確定]

[root@cacti ~]# /etc/init.d/mysqld start

初始化 MySQL 數據庫: Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h cacti password 'new-password'

 

Alternatively you can run:

/usr/bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd /usr /usr/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the /usr/bin/mysqlbug script!

 

                                                           [確定]

正在啓動 mysqld:                                          [確定]

          

          3、安裝cacti監控主機

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

[root@cacti ~]# yum install -y cacti  net-snmp  net-snmp-utils  rrdtool net-snmp-devel net-snmp-libs lm-sensors php-xml zlib libpng freetype cairo-devel pango-devel gd

 

[root@cacti ~]# /etc/init.d/snmpd start

正在啓動 snmpd:                                           [確定]

[root@cacti ~]# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.73 Source distribution

 

Copyright (c) 2000, 2013, 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> create database cacti;

 

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

Query OK, 0 rows affected (0.00 sec)

 

mysql> exit

Bye

[root@cacti ~]# mysql -u root cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql

[root@cacti ~]# vim /usr/share/cacti/include/config.php

$database_type = "mysql";

$database_default = "cacti";

$database_hostname = "localhost";

$database_username = "cactiuser";

$database_password = "cactiuser";

$database_port = "3306";

$database_ssl = false;

 

[root@cacti ~]# vim /etc/httpd/conf.d/cacti.conf

Deny from all 修改爲 Allow from all

[root@cacti ~]# /etc/init.d/httpd restart

停止 httpd:                                               [確定]

正在啓動 httpd:                                           [確定]

4、通過瀏覽器訪問             

      如果訪問不了,請檢查主機的iptables和selinux

http://IP/cacti/  
點兩下“next” 和一次”Finish“ 即可
輸入admin   admin 登錄,重新設置新的密碼

5 查看默認主機

執行poller.php, 生成圖形, 加入計劃任務
/usr/bin/php /usr/share/cacti/poller.php添加cron任務
cront -e  增加:
*/5 * * * *  /usr/bin/php /usr/share/cacti/poller.php

6 添加需要被監控的主機

接下來我們添加被監控的主機

在被監控的主機上安裝

[root@rsa ~]# yum install -y net-snmp lm_sensors
[root@rsa ~]# vim /etc/snmp/snmpd.conf
 
#syslocation Unknown (edit /etc/snmp/snmpd.conf)
syslocation 192.168.1.118
 
#group  context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  all none none
 
view all    included  .1                               80    
[root@rsa ~]# /etc/init.d/snmpd start

修改syslocation以及syscontact, 其中syslocation 可以寫本機ip,syscontact寫管理員郵箱

view    systemview    included   .1.3.6.1.2.1.1
修改爲:
view    systemview    included   .1.3.6.1.2.1(如果不改,可能找不到網卡)

7 啓動 snmp

   /etc/init.d/snmpd start

8 管理cacti後臺

點console , 再點Device, 在右上角點”Add“

 Description  寫本機ip或你自定義一個名字
Hostname  寫本機ip
Host Template  選ucd/net  SNMP Host
SNMP Version  選Version 2
點右下角的create
點右上角的”Create Graphs for this Host“
Graph Types:  選擇SNMP - Interface Statistics
Graph Types:  再選擇 Graph Template Based
在下面的框中,選擇你要監控的項目,比如ucd/net - Load Average
在右側小方塊中打對勾,然後點右下角的create
9 添加實時監控後臺

選中”Default Tree“
點右上角的Add
Tree Item Type 選擇 ”Host“
Host 選擇我們剛剛增加的那個機器ip
點右下角的create

10 點左上角的Graphs

在左側可以看到
Defaut Tree下面已經增加了我們剛剛添加的主機,圖形一開始不會那麼快出來,要等一小會纔可以。
參考文章:http://www.it165.net/admin/html/201310/1956.html   


Cacti安裝高效輪詢器spine(轉)

Cacti默認輪詢器cmd.php執行效率有點低,spine爲C語言編寫的組件,性能要好許多。
編譯安裝spine需以下軟件支持:

1 net-snmp-devel
2 mysql
3 mysql-devel
4 openssl-devel
5 gcc

安裝spine要和Cacti的版本相匹配,本文以最新版cacti0.8.8a安裝爲例。

1 cd /usr/local/src/
2 wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz
3 tar -zxvf cacti-spine-0.8.8a.tar.gz
4 cd cacti-spine-0.8.8a

 編譯:

5 ./configure

6 make && make instatll


配置spine:
1 cd /usr/local/spine/etc/
2 mv spine.conf.dist 

/etc/spine.conf
3 vi spine.conf


填寫數據庫信息,即Cacti數據庫。

DB_Host        localhost
DB_Database    cacti
DB_User        root
DB_Pass        cacti
DB_Port        3306

設置spine路徑,Console——Settings——Paths
cacti設置spine路徑
/usr/local/spine/bin/spine
更改cacti輪詢器爲spine,Console——Settings——Poller
cacti更改輪詢器爲spine

運行:
#/usr/local/spine/bin/spine
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.7g starting
SPINE: Time: 0.2410 s, Threads: 5, Hosts: 2

說明:spine默認配置文件需要放在/etc纔會生效,否則報如下錯誤:
SPINE: Poller[0] FATAL: Unable to read configuration file! (Spine init)


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