Nagios's rapid deployment, execution Environment initialization configuration script. Main configuration Epel Yum source, etc.
Yum install httpd nagios nagios-common nagios-devel nagios-plugins-all-y
rm-rf/etc/nagios/passwd
Htpasswd-c/etc/nagios/passwd Nagiosadmin
chmod 640/etc/nagios/passwd
chown:apache/etc/nagios/passwd
Service Nagios Checkconfig
Service Nagios Start
Chkconfig Nagios on
Configuration of the passive monitoring server:
Yum Install nsca*
Vi/etc/nagios/nsca.cfg#配置密码, IP address and other information
Pid_file=/var/run/nsca.pid
server_port=5667
server_address=192.168.10.34
Nsca_user=nagios
Nsca_group=nagios
Debug=1
Command_file=/var/spool/nagios/cmd/nagios.cmd
Alternate_dump_file=/var/spool/nagios/cmd/nsca.dump
Aggregate_writes=1
Append_to_file=0
Max_packet_age=60
password=123456
Decryption_method=1
VI contacts.cfg #修改email报警邮件地址
VI templates.cfg #增加被动监控的模板
Define Service{
Name Passive_service
Use Generic-service
Max_check_attempts 3
active_checks_enabled 0
Passive_checks_enabled 1
Normal_check_interval 2
Retry_check_interval 1
Notifications_enabled 1
Notification_interval 2
Notification_period 24x7
Contact_groups Admins
Register 0
}
VI command.cfg#增加被动监控的命令
Define Command{
Command_name Check_dummy
Command_line/usr/lib64/nagios/plugins/check_dummy $ARG 1$
}
VI localhost.cfg#增加远程客户端被动监控项目
Define Host{
Use linux-server
HOST_NAME Cacti-server
Alias Cacti-server
Address 192.168.10.33
}
Define Service{
Use Passive_service
HOST_NAME Cacti-server
Service_description Loadavg
Check_command check_dummy!3
Check_freshness 1
Freshness_threshold 120
notifications_enabled 0
}
Service Nagios Start
Service NSCA Start
Passive monitoring of client configuration:
Yum Install Nagios-plugins-all nsca-client-y
VI send_nsca.cfg
password=123456
VI nsca.sh
#!/bin/sh
Set-e
Host_name=$1
Svc_name=$2
Nsca_add=$3
If ["$ $"];then
Case "$" in
Check_load)
Check_arg= "-W 3-c 5"
;;
Check_users)
Check_arg= "-W 2-c 5"
;;
*)
Exit 0
;;
Esac
/usr/lib64/nagios/plugins/$2 $check _arg >/tmp/$2 &
Sleep 3
out= ' cat/tmp/$2 '
Output= ' echo $out |awk ' {print $} '
if [$output = = "OK"];then
Status=0
elif [$output = = "WARNING"];then
Status=1
elif [$output = = "CRITICAL"];then
status=2
Else
Status=3
Fi
echo "$host _name loadavg $status $out" |/usr/sbin/send_nsca-h $nsca _add-d ""-c/etc/nagios/send_nsca.cfg
Else
echo "Please use Bash nsca.sh hostname servicename nscaddr. recheck! "
Fi
SH nsca.sh cacti-server check_load 192.168.10.34
Vi/etc/crontab
* * * * * * root sh/etc/nagios/nsca.sh cacti-server check_load 192.168.10.34
Reference sources
Nagios NSCA Passive monitoring Server Setup