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

发布时间:2020-06-17 02:05:47 作者:D十亿
来源:网络 阅读:806


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 cactier@localhost IDENTIFIED BY '123456';

GRANT all privileges ON cactidb.* TO cactier@127.0.0.1 IDENTIFIED BY '123456';

GRANT all privileges ON cactidb.* TO cactier@192.168.0.0 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 添加被监控主机===        ====

[root@localhost libexec]# cd /home/softwares/
[root@localhost softwares]# wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
[root@localhost softwares]# tar -xvf nagios-snmp-plugins.1.1.1.tgz -C /usr/local/
[root@localhost 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下
[root@localhost nagios_plugins]# ./install.sh
[root@localhost nagios_plugins]# cd /usr/local/nagios/libexec/
[root@localhost 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过程中我们为了检测配置的是否正确需要不断执行该命令来检查配置文件。
[root@localhost 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服务
[root@localhost libexec]# /etc/init.d/nagios start
Starting nagios:This account is currently not available.
 done.
把nagios加入开机自启动
[root@localhost libexec]# vim /etc/rc.d/rc.local
/etc/init.d/nagios start
至此nagios安装完毕
######################监控windows主机###################################
首先在windows主机上安装NSClient++插件(64/32位)在安装的过程中指定监控端的ip地址,安装完后启动NSClient++插件的服务
在监控端配置:
1.进入nagios的主配置文件中把监控windows.server服务打开
[root@localhost 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,如果没有还得手动添加
root@localhost 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文件中
[root@localhost 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服务
[root@localhost 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 守护进程:
[root@localhost 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/

[root@localhost 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.定义主机监控主机组

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


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


[root@localhost 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.根据所作监控更改配置文件

[root@localhost 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                       13522714779@139.com,zhangqiang@228.com.cn,15324168916@189.cn,18244074804@139.com    ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
define contact {
    contact_name            sa
    use                generic-contact
    alias                sa
    email                13522714779@139.com,15324168916@189.cn,18244074804@139.com
}
define contact {
    contact_name            dba
    use                generic-contact
    alias                dba
    email                zhangqiang@228.com.cn
}
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 重起服务

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


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 保存



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

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

Graph Templates                                        图模版                         

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

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

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


Parent Item                                 父项

Tree Item Type                            树向类型

host                                               监控主机

Graph Grouping Style                图分组风格

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

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                                                         数据模版

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

==add 添加===
 

Template [new]   ————新模版名字——Graph Template——图模版标题Title (--title)———其他默认即可
Centos 6.7  安张nagios和cacti 并添加监控主机

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

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

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

在Data Sources


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


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

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


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

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

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

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

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


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

总结:

cacti 如歌包snmp errer 看是否ping 通

iptables、和selinxu 是否关闭

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

vi /etc/snmp/snmpd.conf

#################
syslocation Server Room
syscontact Sysadmin (root@localhost)
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 页面可以看到这个两个包 点击那个小箭头

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


 

推荐阅读:
  1. centos7下搭建cacti
  2. CentOS下搭建cacti监控

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

监控主机(nagios+cacti) ce ct

上一篇:Oracle Study之--查看Oracle 版本运算字长(32/64位)方法

下一篇:thinkphp-比较标签-gt

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》