2、安装nagios-4.1.1
cd nagios-4.1.1
useradd nagios -M -s /sbin/nologin
#unzip: command not found
yum -y install unzip
./configure --prefix=/usr/local/nagios --with-nagios-group=nagios
make install && make all && make install-init && make install-commandmode && make install-config
cp sample-config/httpd.conf /etc/httpd/nagios.conf
#make install-exfoliation,因找不到目录而失败
#cp: target /usr/local/nagios/share/stylesheetsis not a directory
mkdir -p /usr/local/nagios/share/stylesheetsis
cp -rf contrib/exfoliation/stylesheets/* /usr/local/nagios/share/stylesheetsis/
#make install-classicui
#cp: target usr/local/nagios/share/stylesheetsis not a directory
cp -rf html/stylesheets/* /usr/local/nagios/share/stylesheets
#安装插件
cd nagios-plugins-2.1.1
./configure --with-gnutls --enable-perl-modules --enable-libtap --with-openssl --with-gnutls && make && make install
#复制/usr/local/nagios/etc/objects/windows.cfg一份win-222.cfg,并修改为
#继承模板/usr/local/nagios/etc/objects/template.cfg windows-server主机监控设置以及generic-service服务监控设置
#监控主机IP为192.168.137.222,被监控的服务分别为:系统运行时间、CPU负载、内存使用情况、C盘使用情况以及explorer.exe进程数
define host{
use windows-server ; Inherit default values from a template
host_name win-222; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.137.222 ; IP address of the host
}
define hostgroup{
hostgroup_name windows-servers ; The name of the hostgroup
alias Windows Servers ; Long name of the group
}
define service{
use generic-service
host_name win-222
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
define service{
use generic-service
host_name win-222
service_description Uptime
check_command check_nt!UPTIME
}
define service{
use generic-service
host_name win-222
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
define service{
use generic-service
host_name win-222
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
define service{
use generic-service
host_name win-222
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
define service{
use generic-service
host_name win-222
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l explorer.exe
}
#效果图示,可以看到已经正常监控到windows各项服务
4、监控linux主机
#监控IP为192.168.137.6的linux主机,分别监控ping、root分区使用情况、现存用户情况、进程数、实时负载、swap使用情况、ssh和httpd进程
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name linux-6
alias linux-6
address 192.168.137.6
}
define hostgroup{
hostgroup_name my-linux-servers ; The name of the hostgroup
alias My Linux Servers ; Long name of the group
members linux-6 ; Comma separated list of hosts that belong to this group
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description PING
check_command check_ping!100.0,20%!500.0,60%
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description Root Partition
check_command check_local_disk!20%!10%!/
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description Swap Usage
check_command check_local_swap!20!10
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description SSH
check_command check_ssh
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name linux-6
service_description HTTP
check_command check_http
notifications_enabled 1
}
#在/usr/local/nagios/etc/nagios.cfg添加如下一行,并重新加载或者启动nagios
cfg_file=/usr/local/nagios/etc/objects/linux-6.cfg
/etc/init.d/nagios restart
/etc/init.d/nagios reload
systemctl restart nagios
systemctl reload nagios
5、邮件报警设置
5、邮件报警设置
#在/usr/local/nagios/etc/object/contact.cfg下修改为
#定义两个Nagios Admin邮箱地址,并隶属于admins组
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contacttemplate (defined above)
alias Nagios Admin ; Full name of user
email nagiosadmin@dnstest.com ;