Centos 6.7 安张nagios和cacti 并添加监控主机

wget http://mcshell.org/nrpe-2.8.tar.gz

wget http://mcshell.org/nagios-plugins-1.4.13.tar.gz

一、环境Centos 6.7

ip:192.168.3.150 nagios 和cacti  监控主机

192.168.3.150/152   被检控主机

二、安装准备

mount

yum  –y install httpd php php-mysql mysql mysql-server php  net-snmp-utils  rrdtool snmp  cairo-devel libxml2-devel pango pango-devel

service mysqld start       # 启动mysql服务

chkconfig mysqld on      #使其开机自动启动

启动完mysql后,如果出现以下画面,并能通过mysql进入,说明成功安装。

只要在/etc/httpd/conf/httpd.conf的配置文件中找到

LoadModule  status_module  modules/mod_status.so

有这一项表示已经支持状态检测模块,所以无需额外添加,直接启动web服务即可.

service httpd start                   #启动http服务

chkconfig httpd on                 #开机自动启动httpd 服务

启动OK后,编辑

vim /var/www/html/index.php                 在其中添加以下内容#

<?php
phpinfo();
?>

# 保存退出

用web浏览器访问,如果出现以下画面,则表示http支持动态php.并能与php成功连接.

接着测试与mysql的连接,先给mysql设置个管理员密码

mysqladmin -uroot password ‘123456‘                            #密码设置为123456

编辑刚才的web页面

vim /var/www/html/index.php

把里面的内容改为

<?php $link=mysql_connect("localhost","root","123456");

if(!$link) echo "FAILD!";

else echo "OK!";

?>

刷新刚才的web浏览器页面,如果出现OK!字样,则表示成功连接.

下载wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.5.5.tar.gz

tar -zxvf rrdtool-1.5.5.tar.gz -C /usr/loacl/

./configure --prefix=/usr/local/rrdtool/ && maek && make install

make 的时候会报错安装以下即可解决

yum install -y perl-devel perl-CPAN

登陆mysql 创建 cacti库设置权限

指定了一个网段的授权,是将来做监控时数据库和监控工具不在同一台主机上,网段可根据自己需要进行授权

mysql -u  root -p

create database cactidb;

GRANT all privileges ON cactidb.* TO [email protected] IDENTIFIED BY ‘123456‘;

GRANT all privileges ON cactidb.* TO [email protected] IDENTIFIED BY ‘123456‘;

GRANT all privileges ON cactidb.* TO [email protected] IDENTIFIED BY ‘123456‘;

flush privileges; 

在net-snmp的主配置文件/etc/snmp/snmpd.conf中,默认的community为public,建议将public修改为您需的密码项,默认密码public

#sec.name  source          community

com2sec notConfigUser  default       public

接着,启动snmp进程

service snmpd restart   #如果修改过snmpd.conf 则需要重启服务

下载包

http://www.cacti.net/downloads/cacti-0.8.7a.tar.gz

cacti-0.8.7a.tar.gz

解压该压缩包

tar zxvf cacti-0.8.7a.tar.gz -C /usr/local/

##因为cacti的配置是在web页面下进行的,所以直接把cacti-0.8.7a 移至/var/www/html/cacti

mv /usr/local/cacti-0.8.7a /var/www/html/cacti

将cacti.sql数据库文件导入,会提示输入密码输入前面设置的root 的密码即可

mysql -u root -p cactidb < cacti.sql

编辑cacti的主配置文件,为其指定对应的数据库参数:

vim /var/www/html/cacti/include/config.php

将下列各参数的值修改为您前面所设定的:

$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactier";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
修改完成后保存退出。

添加cactier用户 并给其设置密码

useradd cactier
 passwd cactier

cd   /var/www/html/cacti/

#指定rra/ log/的属组属主为cactier用户

chown -R cactier rra/ log/

vim /etc/crontab

##编辑crontab文件 在空白行添加以下内容

*/5 * * * * cactier php /var/www/html/cacti/poller.php  > /dev/null &

#每5分钟以cactier去抓取数据绘图,这个时间5分钟应该是最小间隔了,可以根据自己想建议修改为更小值,建议就每5分钟执行一次。

关闭selinux

vim /etc/sysconfig/selinux

SELINUX=##后面的去掉即可

可以用web浏览器访问cacti进行配置管理了。

虚拟机ip为192.168.3.150                          ## IP根据自己实际情况可做相应修改

从浏览器直接访问以下地址 即可看到cacti配置画面

http://192.168.3.150/cacti/install/

看清路径没有报错则默认点击下一步 可以点击Finish 完成,中间的路径可能与图片不同。

Finish后就会出现登陆画面 用户名和秘密都是admin

用户名admin 密码admin 即可登陆

进入后点击graphs 会显示流量图

如果不出现图片执行以下命令让其手动绘图即可.

su -  cactier

php  /var/www/html/cacti/poller.php > /dev/null 2>&1

exit

数据部分启动较慢,请耐心等待,如显示如上图片数据,则成功安装配置

二、安装nagios 服务 和nagios 所依赖的包

yum -y install apache gcc glibc gd

nagios  需要一些基础支持套件才能运行,如apache,gcc,glibc,gd库等。
useradd -m nagios        #添加一个名为nagios的用户来运行nagios          
groupadd nagios                              #添加nagios用户组,用以通过web页面提交外部控制命令

usermod -a -G nagios daemon             #将运行apache用户daemon加入nagios组

解压安装nagios

tar -zxvf nagios-3.2.3.tar.gz -C /usr/local/

注意下面--with-httpd-conf 的路径,取决与你apache的
cd  /usr/local/nagios-3.2.3

./configure --with-command-group=nagios --with-httpd-conf=/etc/httpd/conf/

##如果没有报错,就进行一下步骤

make all && make install && make install-init    && make install-config && make install-commandmode

#安装完成没有报错开始以下配置

vim  /usr/local/nagios/etc/objects/contacts.cfg

make install-webconf

##修改nagiosadmin这行其中的邮件地址为你的email地址,以将报警邮件发到你的邮箱

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

##设置登陆web界面时HTTP验证的账号密码

下面修改httpd.conf ,yum装的apache ,配置文件的路径为如下所示:

vim /etc/httpd/conf/httpd.conf

在空白地方添加一下两行
# nagios  default settings
Include conf/nagios.conf

以上过程配置结束以后需要重新启动httpd:

# service httpd restart

可以正常启动,下面就可以开始编译、安装nagios-plugins

tar -zxvf nagios-3.2.3.tar.gz -C /usr/local/

cd nagios-plugins-1.4.15

./configure --with-nagios-user=nagios --with-nagios-group=nagios && make && maek install

(1)把nagios添加为系统服务并将之加入到自动启动服务队列:

chkconfig --add nagios

chkconfig nagios on

(2)检查其主配置文件的语法是否正确:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
(3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:

service nagios start

#当然,您也可以通过以下方式将nagios的CGI程序运行于SELinux/targeted模式而不用关闭selinux:

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin

chcon -R -t httpd_sys_content_t /usr/local/nagios/share

(5)通过web界面查看nagios:

http://192.168.3.150/nagios

登录时需要指定前面设定的web认证帐号和密码 nagiosadmin / 123.com

3.2.2版本的nagios有个bug .安装完在/usr/local/nagios/sbin目录下没有原来的statusmap.cgi执行脚本

点击左边的current status 中的Map会显示找不到页面,解决方法只能从老版本中拷贝一个statusmap.cgi到/usr/local/nagios/sbin目录下了,并赋予执行权限。

mv statusmap.cgi  histogram.cgi   /usr/local/nagios/sbin/

如果此时Nagios进程已启动,则需要停止并重新启动nagios:

# killall -SIGHUP nagios

# rm -f /usr/local/nagios/var/nagios.lock

# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

可进入nagios的web管理页面查看log

service httpd restart

说明:

i)此处停止Nagios必须通过向Nagios发送SIGHUP信号的方式进行;

ii)建议此时查看nagios日志文件中是否表明ndomod的模块加载是否正常,以及其是否能正常连接到data sink;查看日志,可以使用如下命令实现:# tail -30 /usr/local/nagios/var/nagios.log

如果此时Nagios进程已启动,则需要停止并重新启动nagios:

killall -SIGHUP nagios

rm -f /usr/local/nagios/var/nagios.lock

/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

总结:
1.cacti不显示曲线图 原因在安装rrdtool 时候是否安装正确在安装cacti的时候页面上的路径是否有报警。

2.网页不访问看是否关闭selinux 和iptables防火墙

======================  naginx 添加被监控主机===        ====

[[email protected] libexec]# cd /home/softwares/
[[email protected] softwares]# wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
[[email protected] softwares]# tar -xvf nagios-snmp-plugins.1.1.1.tgz -C /usr/local/
[[email protected] softwares]# cd /usr/local/nagios_plugins/

置check_snmp_int.pl这些插件的使用时需要配置cpan,CPAN是Comprehensive Perl Archive
Network的缩写.。它是一个巨大的Perl软件收藏库,收集了大量有用的Perl模块(modules)及其相关的文件。这里主要是使用Perl-
Net-SNMP模块。有两种方式安装
perl -MCPAN -e shell
cpan> install Net::SNMP
执行nagios-snmp-plugins安装脚本,执行之后会将插件命令安装到/usr/local/nagios/libexec下
[[email protected] nagios_plugins]# ./install.sh
[[email protected] nagios_plugins]# cd /usr/local/nagios/libexec/
[[email protected] libexec]# ls
check_apt           check_ifstatus     check_nt                 check_snmp_cpfw.pl           check_swap
check_breeze        check_imap         check_ntp                check_snmp_css_main.pl       check_tcp
check_by_ssh        check_ircd         check_ntp_peer           check_snmp_css.pl            check_time
check_clamd         check_jabber       check_ntp_time           check_snmp_env.pl            check_udp
check_cluster       check_ldap         check_nwstat             check_snmp_int.pl            check_ups
check_dhcp          check_ldaps        check_oracle             check_snmp_linkproof_nhr.pl  check_uptime
check_disk          check_load         check_overcr             check_snmp_load.pl           check_users
check_disk_smb      check_log          check_ping               check_snmp_mem.pl            check_wave
check_dummy         check_mailq        check_pop                check_snmp_nsbox.pl          negate

检测nagios的配置是否正确,在后面配置nagios过程中我们为了检测配置的是否正确需要不断执行该命令来检查配置文件。
[[email protected] libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 3.2.1
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-09-2010
License: GPL
开启nagios服务
[[email protected] libexec]# /etc/init.d/nagios start
Starting nagios:This account is currently not available.
 done.
把nagios加入开机自启动
[[email protected] libexec]# vim /etc/rc.d/rc.local
/etc/init.d/nagios start
至此nagios安装完毕
######################监控windows主机###################################
首先在windows主机上安装NSClient++插件(64/32位)在安装的过程中指定监控端的ip地址,安装完后启动NSClient++插件的服务
在监控端配置:
1.进入nagios的主配置文件中把监控windows.server服务打开
[[email protected] etc]# vim /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring a Windows machine
把#cfg_file=/usr/local/nagios/etc/objects/windows.cfg的注释去掉,开启监控windows服务功能
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

2.进入nagios的命令配置文件中查看是否有监控windows的插件命令check_nt,如果没有还得手动添加
[email protected] etc]# vim /usr/local/nagios/etc/objects/commands.cfg
进入配置文件中进行收索,得知有check_nt命令
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
        }

3.进入windows.cfg文件中
[[email protected] etc]# vim /usr/local/nagios/etc/objects/windows.cfg

define host{
        use             windows-server  ; Inherit default values from a template
        host_name       winserver       ; The name we‘re giving to this host
        alias           My Windows Server       ; A longer name associated with the host
        address         192.168.3.28   ; #把ip地址改为被监控主机的ip地址
        }

4.都改完后重启nagios服务
[[email protected] etc]# service nagios restar
Running configuration check...done.
Stopping nagios: .done.
Starting nagios:This account is currently not available.
 done.
5.进入web页面进行查看,看windows主机是否成功加入。发现已成功加入

在被监控主机安装,nrpe naginx 插件

1.解压文件到/usr/local/
tar -zxvf nrpe-2.15.tar.gz -C /usr/local/

cd /usr/local/nrpe-2.15/

./configure

make all
 make install

make install-plugin —监控机需要安装check_nrpe这个插件,被监控机并不需要

被监控主机上安装:
# groupadd nagios
# useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios

安装nagios-plugin:
# ./configure -with-nagios-user=nagios -with-nagios-group=nagios -with-ping-command="/bin/ping"
make
make install
#查看播件文件是否已安装在这个目录有好多的check文件
ls /usr/local/nagios/libexec

配置 NRPE:
# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1
#Nagios监控机的地址或域名

修改/etc/hosts.allow增加监控机ip
# echo ‘nrpe:192.168.3.152‘ >> /etc/hosts.allow

启动 NRPE 守护进程:
[[email protected]ocalhost nagios-plugins-1.4.14]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

可以将此命令加入 /etc/rc.local ,以便开机自动启动。
# echo “/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d” >> /etc/rc.local

可以将此命令加入 /etc/rc.local ,以便开机自动启动。

echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

添加一台监控机,主控上操作:
在监控机/usr/local/nagios/etc/objects/commands.cfg 添加nrpe的定义

# ‘check_nrpe ‘ command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

增加linuxserver.cfg
在/usr/local/nagios/etc/objects/ 目录下新建文件:linuxserver.cfg
把linuxserver.cfg添加到nagios主机:
# echo "cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg“ >> /usr/local/nagios/etc/nagios.cfg
如果要再添加新机器方法炮制就可以了

define host{
use linux-server
host_name 192.168.3.152
alias 192.168.3.152
address 192.168.3.152
}
define service{
use generic-service
host_name 192.168.3.152
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 192.168.3.152
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.3.152
service_description check_ftp
check_command check_ftp!21
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.3.152
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.3.152
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}

或者

define host{
    use     linux-server
    host_name   linhost
    alias       My Linux Server
    address     192.168.3.152

check_command check-host-alive
        check_interval 5
        retry_interval 1
        max_check_attempts 5
        check_period 24x7
        process_perf_data 0
        retain_nonstatus_information 0
        contact_groups admins
        notification_interval 30
        notification_period 24x7
        notification_options d,u,r

}
define service{
    use         generic-service
    host_name       linhost
    service_description CHECK USER
    check_command       check_nrpe!check_users
    }
define service{
    use         generic-service
    host_name       linhost
    service_description Load
    check_command       check_nrpe!check_load       
}   
define service{   
    use         generic-service   
    host_name       linhost
    service_description SDA1
    check_command       check_nrpe!check_sda1
    }
define service{
    use         generic-service
    host_name       linhost
    service_description Zombie
    check_command       check_nrpe!check_zombie_procs
    }
define service{
    use         generic-service
    host_name       linhost
    service_description Total procs
    check_command       check_nrpe!check_total_procs
    }

define service{
    use         generic-service
    host_name       linhost
    service_description HTTP
    check_command       check_nrpe!check_http
    }

define service{
    use         generic-service
    host_name       linhost
    service_description SSH
    check_command       check_nrpe!check_ssh

check_period 24x7
        max_check_attempts 4
        normal_check_interval 3
        retry_check_interval 2
        contact_groups admins
        notification_interval 10
        notification_period 24x7
        notification_options w,u,c,r
    }

define service{
    use         generic-service
    host_name       linhost
    service_description MYSQL
    check_command       check_nrpe!check_mysql
    }
===========================================================

添加监控主机的思路

1.定义监控主机

在/usr/local/nagios/etc/objects/

[[email protected] objects]# cat hosts.cfg
define host{
        host_name linux-3.152
        alias linux-3.152
        address 192.168.3.152
        check_command check-host-alive
        check_interval 5
        retry_interval 1
        max_check_attempts 5
        check_period 24x7
        process_perf_data 0
        retain_nonstatus_information 0
        contact_groups sagroup
        notification_interval 30
        notification_period 24x7
        notification_options d,u,r
        }

2.定义主机监控主机组

[[email protected] objects]# cat contactgroups.cfg
define contactgroup {
        contactgroup_name sagroup
        alias system administrator group
        members nagiosadmin                                     ###给那些成员使用
        }

3.定义监控主机监控那些服务

[[email protected] objects]# cat linuxserver.cfg
define service {
    host_name linux-3.152
    service_description check-host-alive
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check-host-alive
    }
define service {
    host_name linux-3.152
    service_description check-users
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_users
    }
define service {
    host_name linux-3.152
    service_description check-load
    check_period 24x7
    max_check_attempts 4                                    ##尝试最到时间
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_load
    }
define service {
    host_name linux-3.152
    service_description check-total-procs
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_total_procs
    }
define service {
    host_name linux-3.152
    service_description check-disk
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_disk
    }
define service {
    host_name linux-3.152
    service_description check-ping
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_ping
    }
define service {
    host_name linux-3.152
    service_description check-ssh
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_ssh
    }
define service {
    host_name linux-3.152
    service_description check-http
    check_period 24x7
    max_check_attempts 4
    normal_check_interval 3
    retry_check_interval 2
    contact_groups sagroup
    notification_interval 10
    notification_period 24x7
    notification_options w,u,c,r
    check_command check_nrpe!check_http
    }

4.根据所作监控更改配置文件

[[email protected] objects]# cat ../nagios.cfg | grep -v ^# | grep cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg

5.更改nrpe 的配置文件监控端和被监控端为一样的配置文件

cat ../nrpe.cfg | grep -v ^# | grep check
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 -t 20 -p 22 localhost
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

command[check_httpd]=/usr/local/nagios/libexec/check_http -I 192.168.3.152 -p 80 -w 1 -c 3
command[check_ping]=/usr/local/nagios/libexec/check_ping -H localhost -w 3000.0,80% -c 5000.0,100% -p 5
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 300 -c 500

6。重起服务nrpe 和nagios 服务 后查看监控界面

可以根据以下命令作检测

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

7.定义编译报经邮件

cat  contacts.cfg | grep -v ^#

define contact{
        contact_name                    nagiosadmin        ; Short name of user   ##联系人名字也就是给谁发送
        use                generic-contact        ; Inherit default
values from generic-contact template (defined above) ##应用那个模版
        alias                           Nagios Admin        ; Full name of user

email                      
[email protected],[email protected],[email protected],[email protected]  
 ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
define contact {
    contact_name            sa
    use                generic-contact
    alias                sa
    email                [email protected],[email protected],[email protected]
}
define contact {
    contact_name            dba
    use                generic-contact
    alias                dba
    email                [email protected]
}
define contactgroup {
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin
        }

define contactgroup {                                     ###这个是自己编写或者直接用contacts.cfg 里面自己的admin组
    contactgroup_name    DBAadmins         ##组的名字
    alias            DBA Administrators               ##别名
    members            dba                                    ##应用给谁
}
define contactgroup {
    contactgroup_name    saadmins
    alias            system Administrator
    members            sa
}

=====================================

host_notification_options:

d =通知下主机上,

u =通知在遥不可及的主机状态

r =通知主机复苏(状态)

f =通知当主机启动和停止拍打

s =发送通知时,主机或服务计划停机时间开始和结束

n(没有)作为一个选项,接触不会接收任何类型的主机通知。

service_notification_options:

w =通知警告服务状态

u =通知在未知的服务状态

c =关键服务状态通知

r =通知服务复苏(好的状态)

f =通知当服务启动和停止拍打

n(没有)作为一个选项,接触不会接收任何类型的服务通知。

常用的设置

host_notification_options:d u r

service_notification_options:w,u c r

=======================================================

总结:
1.cacti不显示曲线图 原因在安装rrdtool 时候是否安装正确在安装cacti的时候页面上的路径是否有报警。

2.网页不访问看是否关闭selinux 和iptables防火墙

3.在添加监控主机间需要里清之间的关系(定义监控主机—定义监控主机服务—定监控主机组—定义配置文件)

监控端和被监控主机nrpe 配置需要一致

====================================================================================

cacti 添加主机监控监控模板

添加监控主机

Devices—> add添加,desription 主机名  hostname 被监控机ip host Template 监控模板 ucd/net SNMP host选择这个模板可

(local Linux  Machine  这个模版可以监控本机磁盘)    以查看监控网卡流量---

如过查看不到,就在被监控的服务器上编辑/etc/snmp/snmpd.conf文档
vi /etc/snmp/snmpd.conf

systemview included .1.3.6.1.2.1.2  如果不显示监控网卡在在

service snmpd restart 重起服务

Downed Device Detection 选择监控的协议

Ping Port                             ping监听端口

Ping Timeout Value             超时时间

Ping Retry Count                 重试计数

snmp version                                        版本信息建议选择version 2

snmp comunity                                     用户和cacai 配置文件里写的一样

snmp port                                             监听端口

snmp timeout                                        超时时间

Maximum OID‘s Per Get Request           最大的OID的/ Get请求

Associated Graph Templates———————add 添加监控模版

——save 保存

点击 ———>*Create Graphs for this Host

Graph Templates                                        图模版

Data Query                                                   数据查询 —添加监控网卡——添加——create 创建

Graph Trees                                                   添加树 ——Default Tree——add

Parent Item                                 父项

Tree Item Type                            树向类型

host                                               监控主机

Graph Grouping Style                图分组风格

Graphs -> Tree Mode                             查看监控主机界面

=======================手工导入模版====================

Import/Export                                                           导入导出   找到要导入的模版默认下一步就行

Import Templates                                                     导入模版

Export Templates                                                    导出模版

浏览——>找到下载模版——>(http://docs.cacti.net/plugins)将下载下来的模版里面的.php 文件复制到

/var/www/html/cacti/scripts 下同时注意权限成功导入可以看到最后一个也年有好多绿色提示

下载模版官网地址

http://forums.cacti.net/viewforum.php?f=12&sid=fe2532345bf037678cb1e9fb07b40f16

=======================手工导入脚本=========================

Templates                                                                 模板

Graph Templates                                                      图形模版
Host Templates                                                         主机模版

Data Templates                                                         数据模版

==add 添加===

Template [new]   ————新模版名字——Graph Template——图模版标题Title (--title)———其他默认即可

Graph Template Items [edit: we2]————add————Data Source————选择新添加数据源————Graph Item Type图类型—————Consolidation Function(整合功能)————(last去年、average平均、min最小值、max最大值)定义不同的颜色以便于区分(Color)

Graph Item Inputs———图像输入——add——默认save保存

在Data Sources

定义主机模版——add——添加————如下:保存

新模版名字——模版源名字——Data Input Method(可u选择几分钟采集数据)——保存save

====================add 命令

Data
Input Methods(数据输入方法)————add————**Input String(输入命令所在目录)————/bin/bash
<path_cacti>/scripts/tcpconn.sh<hostname><community>
——————剩下两个都add都添加——然后保存——最后保存save

========================================

总结:

cacti 如歌包snmp errer 看是否ping 通

iptables、和selinxu 是否关闭

如果和不行在被监控主机里面添加

vi /etc/snmp/snmpd.conf

#################
syslocation Server Room
syscontact Sysadmin ([email protected])
rocommunity public 127.0.0.1
agentaddress 161
rocommunity public
rwcommunity private

trapsink 192.168.3.152 public 162 ####被检控机的ip

然后重起服务

/etc/init.d/snmpd restart

在监控机用root 用户测试snmp 是否可以检测被监控机

snmpwalk -v 2c -c public 192.168.3.152

======================

cacti 插件下载地址

wget  http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz

wget  http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz

wget  http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7g-PA-v2.8.tar.gz

因为没有Plugin Management 选项需要在官网下载plugin补丁

wget  http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7g-PA-v2.8.tar.gz

检查发现没有安装包

rpm -qa | grep patch

yum -y install patch

二、配置安装cacti-plugin
cd   /var/www/html
tar   xvfz  cacti-plugin-0.8.7g-PA-v2.8.tar.gz
\cp -fr cacti-plugin-arch/* /var/www/html/cacti/
cd   /var/www/html/cacti

patch -p1 -N  < cacti-plugin-0.8.7g-PA-v2.8.diff

后将pa.sql数据库导入到了

mysql -u root -p cactidb < pa.sql##############mysql -u root -p cactidb < cacti.sql

mysql -u root -p cactidb < thold/thold.sql

重启服务

/etc/init.d/snmpd restar

在cacti 页面中User Management 给用户中勾选Plugin Management选项

下载插件

wget  http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tg

wget  http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz

解压

tar -zxvf plugin:monitor-v1.3-1.tg -C /var/www/html/cacti/plugins/

mysql -u root -p cactidb < pa.sql

tar -zxvf plugin:thold-v0.5.0.tgz  -C /var/www/html/cacti/plugins/

在cacti 页面可以看到这个两个包 点击那个小箭头

时间: 2024-07-29 11:03:16

Centos 6.7 安张nagios和cacti 并添加监控主机的相关文章

cacti批量添加监控主机网卡脚本

公司部署的cacti服务器专门用来监控所有服务器网卡流量,批量添加脚本 #!/bin/bash #add host for cacti path=/var/www/html/cacti/cli PHP=/usr/bin/php DEVICE=$path/add_device.php GRAPHS=$path/add_graphs.php TREE=$path/add_tree.php community_name=XXXXXX cat ./hosts | while read HOST;do h

Centos 7安装与配置nagios监控详细图解(二)

目 录 序言(必备知识) 一.安装规划 1.1系统环境 1.2所需软件包 二.配置安装环境 2.1同步时间 2.2禁用SElinux 2.3 xftp上传软件包 2.4安装邮件服务 三.监控主机安装 3.1安装nagios的运行环境 3.2增加用户 3.3安装nagios 3.4配置权限 3.5安装插件 3.6安装nrpe 四.远程主机安装 4.1配置运行环境 4.2安装nagios-plugin 4.3安装nrpe 4.4启动nrpe 五.监控主机安装PNP 5.1配置开发环境 5.2安装pn

centos下整合PagerDuty、nagios初探(on-call尝鲜和体验)

[前言] 今天在某个群里看见有人介绍了PagerDuty,介绍到了slack.整合后可以更加方便和团队合作.于是我觉得来尝尝鲜. [PagerDuty是什么?] PagerDuty是一款能够在服务器出问题时发送提醒的软件.在发生问题时,提醒的方式包括屏幕显示.电话呼叫.短信通知.电邮通知等,而且在无人应答时还会自动将提醒级别提高.该软件通过一个控制面板对问题进行监控.官方网站:http://www.pagerduty.com,提醒下这不是免费的午餐哈. [注册] 1.打开页面https://si

我们来看下 监控软件 Nagios 和 cacti 结合

来看下 两者区别 Cacti:在监控方面绘图比较不错,在流量与图型展现比较存在优势 Nagios:在故障分析比较不错,报警机制相对来说比较好,报警机制:邮箱.短信等,而且也比Cacti灵活:同时适用监控大量服务器以及服务器上面大批服务状态是否正常,重点不在图形化,而在状态故障的监控 1.安装相关的软件包 [[email protected] Desktop]# yum -y install httpd php gcc glibc glibc-common gd gd-devel libpng l

在CentOS 6.5下搭建Nagios

Nagios是一款很棒的监控工具,可以帮助你监控你的网络中的服务器等等,并且具有邮件问题提醒等功能,并且可以结合Nagios的硬件来监控机房的温度并实时查询和报警. 免费版的Nagios只能监控7台(记不清了,也可能是6台),但是对于小型的企业,重要的几台服务器被Nagios实时监控应该够用了. 配置环境:1)CentOS 6.5 作为监控主机,IP:10.0.0.30(根据自己公司需要改变) 2)客户机: windows server  2008R2 , windows 7, windows

生产环境下搭建 nagios+nconf+cacti+npc的整合

系统:CentOS6.5 内核版本系统:2.6.32-431.23.3.el6.x86_64 关闭iptables .selinux chkconfig iptables off 安装前的准备工作 yum install -y httpd-*  mysql-* php-*  net-snmp*  gcc glibc glibc-common gd gd-devel openssl* 一.nagios 环境的搭建 1.安装nagios useradd nagios tar zxf nagios-3

IT运维监控开源软件Zabbix、Nagios、Cacti

根据论坛整理:IT 监控软件大致可以分为3类:1-免费开源软件,比如Zabbix.Nagios.Cacti等 云监控服务,比如监控宝,阿里云监控等 收费企业级监控软件,比如惠普Openview, sitesope, AVMON, IBM tivoli, 摩卡BSD 等: 这3种监控方式各有优缺点. 开源软件虽然是免费,但是需要花时间去研究.配置其实也是有成本的.还得看企业的技术能力是否够强. 云监控的优点是价格较低,服务使用起来简单.缺点是被监控设备必须连接到公网上,很多企业有安全顾虑:而且服务

cacti批量添加研究

利用cacti提供的api接口可以进行添加查询监控 这些api脚本放在cacti的cli目录下面: /web/cacti02/cli 编写脚本循环调用下面这些api脚本,就可以达到批量添加的效果,省去大量的人力和时间 add_data_query.php add_device.php add_graphs.php add_graph_template.php add_perms.php add_tree.php 下面我们来实践添加一次cacti监控的过程: 1.添加设备 /usr/local/p

nagios 批量添加监控主机

#!/bin/bash #by xbzy #QQ:465667803 #add host to nagios Addfun() { for ip in `cat ips.txt` do echo -e "define host{ use                     linux-server host_name               $ip-record alias                   $ip address                 $ip }"