nagios

nagios配置文件设置分为俩种,一种如下设置,第二种为创建servers目录集中管理被监控主机和generic_cfg目录管理监控本机的配置文件。

#yuminstall-yhttpdphpglibcglibc-commongdgd-develgcc

[root@teacher~]#useraddnagios

[root@teacher~]#groupaddnagcmd

[root@teacher~]#usermod-a-Gnagcmdapache

[root@teacher~]#usermod-a-Gnagcmdnagios

开始安装

#tarzxvfnagios-3.2.3.tar.gz-C/usr/local/src

#cd/usr/local/src/nagios-3.2.3/

#./configure--prefix=/usr/local/nagios--with-command-group=nagcmd

#makeall
#makeinstall-init
#makeinstall-commandmode
#makeinstall-config
#makeinstall-webconf

#cd/etc/httpd/conf.d
#vimnagios.conf
//记住保存用户名和密码的文件

#htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin //配置密码
-------------
安装插件

#tarzxvfnagios-plugins-1.4.15.tar.gz-C/usr/local/src

#cd/usr/local/src/nagios-plugins-1.4.15/

#./configure--with-nagios-user=nagios--with-nagios-group=nagcmd

#make
#makeinstall

#cd/usr/local/nagios/libexec/
#ls
#./check_ssh--help//查看帮助

启动服务
#servicehttpdrestart

#servicenagiosrestart
----------------------------

监控端(服务器端)192.168.3.2
#cd/usr/local/nagios/etc/objects
#vimcontacts.cfg

39definecontact{
40contact_namematrix
41#usegeneric-contact
42aliasadministrator
43service_notification_period24x7
44host_notification_period24x7
45service_notification_optionsw,u,c,r
46host_notification_optionsd,u,r
47service_notification_commandsnotify-service-by-email
48host_notification_commandsnotify-host-by-email
49
50emailmatrix@localhost
51}

definecontactgroup{
contactgroup_nameadmins
aliasNagiosAdministrators
membersnagiosadmin,matrix//添加matrix 逗号分隔
}

#vimremotehost.cfg

definehost{
host_nameapache
aliasapache
address192.168.3.3
max_check_attempts5
check_period24x7
normal_check_interval5
retry_check_interval1
contact_groupsadmins
notification_period24x7
notification_optionsd,u,r
}

#vimservices.cfg

defineservice{
uselocal-service
host_nameapache
service_descriptionapache_alive
check_commandcheck_ping!100.0,20%!500.0,60%
}

defineservice{
host_nameapache
service_descriptioncheck_tcp80
max_check_attempts5
check_period24x7
normal_check_interval5
retry_check_interval2
contact_groupsadmins
notification_period24x7
notification_optionsw,u,c,r
check_commandcheck_tcp!80
}

#pwd
/usr/local/nagios/etc
#vimnagios.cfg

34cfg_file=/usr/local/nagios/etc/objects/remotehost.cfg
35cfg_file=/usr/local/nagios/etc/objects/services.cfg

//检查配置文件错误
#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

TotalWarnings:0
TotalErrors:0

//服务重启
#/etc/init.d/nagiosrestart

firefoxhttp://192.168.3.2/nagios&
//监控端的ip
-------------------------------
需要监控被监控端的web服务
在被监控端192.168.3.3
启动网页服务
#servicehttpdrestart

--------------------------------------
通过NRPE监控远程主机

远程主机(被监控端)192.168.3.3

#useradd-s/sbin/nologin-Mnagios

#yuminstallgccglibcglibc-common-y

#tarzxvfnagios-plugins-1.4.15.tar.gz-C/usr/local/src

#cd/usr/local/src/nagios-plugins-1.4.15/

#./configure--prefix=/usr/local/nagios
#make
#makeinstall

安装NRPE
#yuminstallopensslopenssl-devel-y

#tarzxvfnrpe-2.12.tar.gz-C/usr/local/src

#cd/usr/local/src/nrpe-2.12/

#./configure--prefix=/usr/local/nagios

#makeall

#makeinstall-plugin
#makeinstall-daemon
#makeinstall-daemon-config
#makeinstall-xinetd

#vim/etc/services

418nrpe5666/tcp#nrpe

#vim/etc/xinetd.d/nrpe

disable=no
only_from=192.168.3.2127.0.0.1//添加监控端的ip地址

#/etc/init.d/xinetdrestart

#netstat-altunp|grep:5666
tcp000.0.0.0:56660.0.0.0:*LISTEN21318/xinetd

若开启防火墙需开放端口

iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

编辑配置文件
#vim/usr/local/nagios/etc/nrpe.cfg

199command[check_users]=/usr/local/nagios/libexec/check_users-w5-c10
200command[check_load]=/usr/local/nagios/libexec/check_load-w15,10,5-c30,25,20
201command[check_sda1]=/usr/local/nagios/libexec/check_disk-w20%-c10%-p/dev/sda1
202command[check_sda2]=/usr/local/nagios/libexec/check_disk-w20%-c10%-p/dev/sda2
203command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w5-c10-sZ
204command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w150-c200

在本机测试
#/usr/local/nagios/libexec/check_nrpe-Hlocalhost-ccheck_sda2
DISKOK-freespace:/21788MB(77%inode=98%);|/=6431MB;23804;26780;0;29756
[root@teacherxinetd.d]#df-h
FilesystemSizeUsedAvailUse%Mountedon
/dev/sda230G6.3G22G23%/
/dev/sda199M12M83M12%/boot
tmpfs252M0252M0%/dev/shm
/rhel55.iso2.9G2.9G0100%/mnt/cdrom

[root@teacherxinetd.d]#df-i
FilesystemInodesIUsedIFreeIUse%Mountedon
/dev/sda2786432015691877074022%/
/dev/sda12610434260701%/boot
tmpfs644131644121%/dev/shm
/rhel55.iso000-/mnt/cdrom
-------------------------

监控端192.168.3.2

#yuminstallopensslopenssl-devel-y

#tarzxvfnrpe-2.12.tar.gz-C/usr/local/src

#cd/usr/local/src/nrpe-2.12/

#./configure--prefix=/usr/local/nagios
#makeall
#makeinstall-plugin

手动测试写上被监控端的ip地址

#/usr/local/nagios/libexec/check_nrpe-H192.168.3.3-ccheck_sda2

DISKOK-freespace:/21788MB(77%inode=98%);|/=6431MB;23804;26780;0;29756

#cd/usr/local/nagios/etc/objects/

#vimcommands.cfg

添加
definecommand{
command_namecheck_nrpe
command_line$USER1$/check_nrpe-H$HOSTADDRESS$-c$ARG1$
}

#vimservices.cfg

#define192.168.3.3"/boot"
defineservice{
uselocal-service
host_nameapache
service_descriptionbootpartition
check_commandcheck_nrpe!check_sda1
}

#define192.168.3.3"/"
defineservice{
uselocal-service
host_nameapache
service_description/partition
check_commandcheck_nrpe!check_sda2
}

检查配置文件
#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg

服务重启
#servicenagiosrestart