cacti 重图形,有数据历史,需用到数据库支持,支持web配置,默认不支持告警,可以加插件;
nagios重状态和结果,没有数据历史,不成图像,不支持web配置,可以自己开发脚本定制个性化监控,支持多种插件;
zabbix有数据历史,可成图像,支持web配置,可以自动发现;


第一部分:监控软件Cacti搭建

一、环境准备

1、安装epel扩展源

关闭selinux

临时关闭 setenforce 0

vim /etc/selinux/config

SELINUX=disbabled

1

[root@cacti~]#yuminstall-yepel-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~]#yuminstall-yhttpdphpphp-mysqlmysqlmysql-servermysql-develphp-gdlibjpeglibjpeg-devellibpng-devel

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

正在启动httpd:[确定]

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

初始化MySQL数据库:InstallingMySQLsystemtables...

OK

Fillinghelptables...

OK

Tostartmysqldatboottimeyouhavetocopy

support-files/mysql.servertotherightplaceforyoursystem

PLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER!

Todoso,starttheserver,thenissuethefollowingcommands:

/usr/bin/mysqladmin-urootpassword'new-password'

/usr/bin/mysqladmin-uroot-hcactipassword'new-password'

Alternativelyyoucanrun:

/usr/bin/mysql_secure_installation

whichwillalsogiveyoutheoptionofremovingthetest

databasesandanonymoususercreatedbydefault.Thisis

stronglyrecommendedforproductionservers.

Seethemanualformoreinstructions.

YoucanstarttheMySQLdaemonwith:

cd/usr;/usr/bin/mysqld_safe&

YoucantesttheMySQLdaemonwithmysql-test-run.pl

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

Pleasereportanyproblemswiththe/usr/bin/mysqlbugscript!

[确定]

正在启动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~]#yuminstall-ycactinet-snmpnet-snmp-utilsrrdtoolnet-snmp-develnet-snmp-libslm-sensorsphp-xmlzliblibpngfreetypecairo-develpango-develgd


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

正在启动snmpd:[确定]

[root@cacti~]#mysql-uroot

WelcometotheMySQLmonitor.Commandsendwith;or\g.

YourMySQLconnectionidis4

Serverversion:5.1.73Sourcedistribution

Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.

OracleisaregisteredtrademarkofOracleCorporationand/orits

affiliates.Othernamesmaybetrademarksoftheirrespective

owners.

Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.

mysql>createdatabasecacti;

mysql>grantalloncacti.*to'cactiuser'@'localhost'identifiedby'cactiuser';

QueryOK,0rowsaffected(0.00sec)

mysql>exit

Bye

[root@cacti~]#mysql-urootcacti</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

Denyfromall修改为Allowfromall

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

停止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~]#yuminstall-ynet-snmplm_sensors[root@rsa~]#vim/etc/snmp/snmpd.conf#syslocationUnknown(edit/etc/snmp/snmpd.conf)syslocation192.168.1.118#group contextsec.modelsec.levelprefixreadwritenotifaccessnotConfigGroup""anynoauthexactallnonenoneviewallincluded.180[root@rsa~]#/etc/init.d/snmpdstart

修改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/netSNMP 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 wgethttp://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_Hostlocalhost
DB_Databasecacti
DB_Userroot
DB_Passcacti
DB_Port3306

设置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! (Spineinit)