-
安装
apt-get update
apt-get install nagios* perl
apt-get install --no-install-recommends pnp4nagios
apt-get install apache2 apache2-utils php5 php-pear -
修改npcd设置
# vim /etc/default/npcd
Run="yes"
# service npcd start - 添加process_perfdata.pl执行权限
chmod +x /usr/lib/pnp4nagios/libexec/process_perfdata.pl - 修改commands.cfg设置(注释旧命令)
vi /etc/nagios3/commands.cfg# 'process-host-perfdata' command definition define command{command_name process-host-perfdata#command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/lib/nagios3/host-perfdata.outcommand_line /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl}# 'process-service-perfdata' command definition define command{command_name process-service-perfdata#command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/lib/nagios3/service-perfdata.outcommand_line /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl}
- 修改nagios.cfg配置
vi /etc/nagios3/nagios.cfg 修改以下3行配置
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
修改check_external_commands=1 (未修改可能导致web网站无法Re-schedule监控项)
修改enable_flap_detection=0 (虽然文档里说默认是0,但实际为1.改为0之后就解决了flapping state) - 修改services_nagios2.cfg配置
vi /etc/nagios3/conf.d/services_nagios2.cfg
notification_interval 1
vi /etc/nagios3/conf.d/generic-service_nagios2.cfg
notification_interval 1 -
删除install.php
# cd /usr/share/pnp4nagios/html
# mv install.php install.php.bak - Nagios插件目录: /usr/lib/nagios/plugins/
- 添加pnp4nagios插件
vi /etc/nagios3/conf.d/pnp4nagos.cfg 追加如下配置define host {name host-pnpaction_url /pnp4nagios/index.php/graph?host=$HOSTNAME$'class='tips'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_register 0process_perf_data 1 }define service {name srv-pnpaction_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'class='tips'rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$register 0process_perf_data 1 }
- 默认是没有监控内存的,若需要监控复制check_mem.sh文件到插件目录,再添加相关配置文件
添加自定义执行命令
vi /etc/nagios3/conf.d/custom_commond.cfg添加本机的check_mem服务define command{command_name check_memcommand_line $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$}
vi /etc/nagios3/conf.d/localhost_nagios2.cfg 添加如下配置define service{use local-service,srv-pnphost_name localhostservice_description check_memcheck_command check_mem!80!90}
- 监控服务器网卡流量
apt-get install snmpd snmp-mibs-downloader
vi /etc/snmp/snmpd.conf(可备份snmpd.conf,修改下面的localhost-IP为服务器IP,保存此文件即可)com2sec notConfigUser 127.0.0.1 public com2sec notConfigUser localhost-IP public group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser view systemview included .1.3.6.1.2.1.1 view systemview included .1.3.6.1.2.1.2 view systemview included .1.3.6.1.2.1.25.1.1 view all included .1 access notConfigGroup "" any noauth exact all none none
重启snmpd服务
下载check_traffic.sh到插件目录
cd /usr/lib/nagios/plugins/
测试执行
./check_traffic.sh -V 2c -C public -H your_ip -I 2 -w 1200,1500 -c 1700,1800 -K -B
# vi /etc/nagios3/conf.d/custom_commond.cfg 追加define command{command_name check_trafficcommand_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b }
-
当服务停止时重新监控失败,运行以下2行命令
# dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
# dpkg-statoverride --update --add nagios www-data 751 /var/lib/nagios3 - 配置发送邮件功能
apt-get install ssmtp (备用:apt-get install sendmail-bin sendmail)
修改ssmpt.conf文件配置
# vi /etc/ssmtp/ssmtp.conf 追加Google邮箱配置方式(勿开启2步验证)AuthUser=NagiosAdmin AuthPass=PassWord FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES
service sendmail stop
chkconfig sendmail off
cd /usr/sbin
mv sendmail sendmail.bak
ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
测试发邮件即可 - 添加被监控机需要注意
监控其他主机,需要添加check_nrpe命令,但在Debian系统中,添加check_nrpe命令会提示重复,但是却找不到其他地方有配置。
所以需要将check_nrpe改成其他名define command{command_name custom_check_nrpecommand_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}
举例监控客户机的CPU情况
先添加主机
# vi /etc/nagios3/conf.d/hosts.cfgdefine host{use generic-host ; Inherit default values from a templatehost_name Dow1_Server ; The name we're giving to this serveralias DriverServer ; A longer name for the serveraddress 10.10.0.32 ; IP address of Remote Linux host }
添加监控服务项,注意使用的命令是自定义的nrpe
# vi /etc/nagios3/conf.d/custom_services.cfgdefine service{use generic-servicehost_name Dow1_Server_198.27.75.32service_description CPU Loadcheck_command custom_check_nrpe!check_load}
iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
service iptables save
service iptables restart
转载于:https://www.cnblogs.com/Mrhuangrui/p/4638083.html