標籤:
安裝
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 definitiondefine 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.out command_line /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl }# ‘process-service-perfdata‘ command definitiondefine 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.out command_line /usr/bin/perl /usr/lib/pnp4nagios/libexec/process_perfdata.pl }commands.cfg Code
- 修改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-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$‘class=‘tips‘rel=‘/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register 0 process_perf_data 1}define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$‘class=‘tips‘rel=‘/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 process_perf_data 1}Code
- 預設是沒有監控記憶體的,若需要監控複製check_mem.sh檔案到外掛程式目錄,再添加相關設定檔
添加自訂執行命令
vi /etc/nagios3/conf.d/custom_commond.cfg
define command{ command_name check_mem command_line $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$ }Code添加原生check_mem服務
vi /etc/nagios3/conf.d/localhost_nagios2.cfg 添加如下配置
define service{ use local-service,srv-pnp host_name localhost service_description check_mem check_command check_mem!80!90 }Code
- 監控伺服器網卡流量
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
Code重啟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_traffic command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b}Code
當服務停止時重新監控失敗,運行以下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=NagiosAdminAuthPass=PassWordFromLineOverride=YESmailhub=smtp.gmail.com:587UseSTARTTLS=YES
Codeservice 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_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }Code
Debian 系統安裝 Nagios 伺服器監控端