分类: LINUX
2011-05-24 00:22:53
nagios的安装配置
yum install httpd php
yum install gcc glibc glibc-common
yum install gd gd-devel
useradd -m nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
wget
wget
cd ~/downloads
tar xzf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
vi /usr/local/nagios/etc/objects/contacts.cfg
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
##password 1q2w3e4r
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chkconfig --add nagios
chkconfig nagios on
Verify the sample Nagios configuration files.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, start Nagios.
service nagios start
声音告警
开启报警
#vi /usr/local/nagios/etc/cgi.cfg 将如下内容前面的注释去掉
#host_unreachable_sound=hostdown.wav
#host_down_sound=hostdown.wav
#service_critical_sound=critical.wav
#service_warning_sound=warning.wav
#service_unknown_sound=warning.wav
#normal_sound=noproblem.wav
上传报警声音文件
之所以上传音频文件到nagios服务器是因为新版的nagios并没有这些报警所需的音频文件,因此我们需要自己设置,
我们可以从网上下载一些自己喜欢的wav格式的音乐作为报警,然后将其重命名后放置到/usr/local/nagios/share/media目录下
cd /usr/local/nagios/share/media
chown nagios.nagios *
chmod 777 *
http://blog.163.com/lgh_2002/blog/static/44017526200911115407257/?fromdm&fromSearch&isFromSearchEngine=yes
画图(参考:)
wget
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install zlib rrdtool
pnp4nagios的安装()
wget %3A%2F%2Fsourceforge.net%2Fsearch%2F%3Fq%3Dpnp4nagios&ts=1305056346&use_mirror=cdnetworks-kr-1
tar -xzvf pnp4nagios-0.6.12.tar.gz
cd pnp4nagios-0.6.12
./configure
make all
make install
###After the installation of the program and HTML files you can copy a sample Apache configuration file to your web-server config directory
make install-webconf
make install-config
make install-init
###All these steps are combined in
make fullinstall
#config nagios.cfg
#Bulk Mode with NPCD
process_performance_data=1
添加如下:
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
######The used commands have to be announced to Nagios. If you used the quickstart installation guides for Nagios you can modify the definitions in commands.cfg.
define command{
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command{
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}
####Before starting NPCD you have to check the paths to the spool directory and to process_perfdata.pl specified in the config file npcd.cfg. The only thing that remains is to start NPCD.
/usr/local/pnp4nagios/bin/npcd -d -f /usr/local/pnp4nagios/etc/npcd.cfg
编辑templates.cfg添加pnp
(http://zhumeng8337797.blog.163.com/blog/static/10076891420107260034525/)
()
vim templates.cfg
引用
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
##########################################
以电子邮件的形式发送告警
修改/usr/local/nagios/object/contact.cfg文件中的联系人
define contact {
contact_name sun
use generic-contact
alias Nagios Admin
service_notification_period 24x7 #服务器监控时间范围,默认值。
host_notification_period 24x7 #主机告警时间范围,;默认值。
#####以下两行配置是主机、服务在什么状态下告警
#### w=warning,u=unknown,r=recover,c=critical
service_notification_options w,u,c,r ;默认值,无此行也可
host_notification_options d,u,r ;默认值,无此行也可
email testing@netease.com
pager 13312345678
#### 多个联系人时,照上述格式在下面增加。
}
#### 定义联系人组
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
membersS ### 多个联系人时,以逗号分隔
}
sendmail的设置
在/etc/mail/access添加必要的信息
# by default we allow relaying from localhost...
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
### add by sun
connect: RELAY
connect:nagios@localhost RELAY
connect:192.168.12 RELAY
connect:sun@localhost RELAY
connect:testing@netease.com RELAY
connect:test@sina.com RELAY
}
在/etc/mail/路径下执行:
makemap hash access < access
或者
makemap -v hash /etc/mail/access.db < /etc/mail/access
再执行:
chmod 777 /var/spool/mqueue
commands.cfg
此处的配置文件内容是默认的,不需任何修改,只是为了出现错误时的一个参照。
vi /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTA
DDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $
NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification
Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress:
$HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional
Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert:
$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
###########################################################
define contact{ ;
contact_name user2
use generic-contact
alias Nagios Admin
service_notification_commands service-by-sms,notify-service-by-email
host_notification_commands host-by-sms,notify-host-by-email
email [email]user2@domain.com[/email]
pager 137xxxxxxxx
}
###################################################################################3
邮件测试
/usr/lib/sendmail –bp
/var/spool/mqueue is empty
Total requests: 0
echo testing | /usr/sbin/sendmail -v test@hotmail.com
监控windows
安装windows客户端
%2B%2B-0.3.9-Win32-rc1.zip
在c盘解压NSClient%2B%2B-0.3.9-Win32-rc1.zip
打开命令行窗口,并将目录转换到NSClient%2B%2B-0.3.9目录执行如果下命令
nsclient++ /install
nsclient++ SysTray
open the service manager and make sure the nsclientpp service is allowed to interact with the desktop
(see the 'Log On' tab of the services manager).if it isn't already allowed to interact with the desktop,
check the box to allow it to.
#edit the nsc.ini file(located_hosts' option in the [setting] section.Add the ip address of the nagios
server to this line,or leave ti blank to allow all hosts to connect.
#Make sure the 'port' option in the [NSClient] section is uncommented and set to '12489'(the default port).
(参考http://blog.sina.com.cn/s/blog_485acedb0100cdyf.html)
nsclient++ /start
##Installation guide
NT4, 2000, XP (old)
NSC.ini
[modules]
SysTray.dll
Then run:NSClient++ -noboot systray install
###XP, 2k3, Vista, Windows 7, etc (modern)
[settings]
shared_session=1
And:
· Don't enable SysTray.dll
· Don't run the "systray install" thingy above.
##################################################
编辑C:\NSClient++\NSC.INI文件,做以下修改:
----- 将[modules]部分列出的所有模块前的注释去掉,除了CheckWMI.dll和RemoteConfiguration.dll
----- 在[settings]部分里的 `password` 段为客户端设定一个密码(这个设定是可选的);
----- 去掉[settings]部分里的`allowed_hosts` 前的注释,添加监控服务器的IP,或者空着,如果空着就是允许所有主机连接;
----- 确保[NSClient]部分里的`port`前面的注释去掉,并设定为默认值12489.
#####################################################
修改服务端配置文件windows.cfg ( 参考:)
vi /usr/local/nagios/etc/objects/windows.cfg
define host{
use windows-server
host_name winserver
alias my windows server
address 192.168.168.120
}
#monitor the version of the NSClient++ addon
define service{
use generic-service
host_name winserver
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
#monitor the uptime of the Windows server
define service{
use generic-service
host_name winserver
service_description Uptime
check_command check_nt!UPTIME
}
monitor the CPU utilization
define service{
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt!CPULOAD!-l 5,80,90
}
#monitor memory usage
define service{
use generic-service
host_name winserver
service_description Memory Usage
check_command check_nt!MEMUSE!-w 80 -c 90
}
#monitor usage of the C:\ drive
define service{
use generic-service
host_name winserver
service_description C:\ Drive Space
check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
}
#monitor the W3SVC service
define service{
use generic-service
host_name winserver
service_description W3SVC
check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
}
#monitor the Explorer.exe process
define service{
use generic-service
host_name winserver
service_description Explorer
check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
}
#Password Protection
vi /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s PASSWORD -v $ARG1$ $ARG2$
}
nrpe的安装
下载nrpe
wget
tar -xzvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
###Install the NRPE daemon as a service under xinetd.
make install-xinetd
##Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.
only_from = 127.0.0.1
##Add the following entry for the NRPE daemon to the /etc/services file.
nrpe 5666/tcp # NRPE.
启动nrpe
/etc/init.d/xinetd start
或者直接用
/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg
检查nrpe是否安装完好
/usr/local/nagios/libexec/check_nrpe -H localhost
配置服务端
vi /usr/local/nagios/etc/commands.cfg
and add the following definition to the file:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
配置服务,添加远程机器
eg:
新建文件test.cfg
vi test.cfg
define host{
use linux-server,host-pnp ; 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 test
alias localhost
address 127.0.0.1
contact_groups admins
}
define service{
use local-service ; Name of service template to use
host_name test
service_description Current Load
check_command check_nrpe!check_load
}
错误排查:
(1)../../libexec/check_nrpe -H 192.168.168.129 -c checktest
CHECK_NRPE: Error - Could not complete SSL handshake.
solution:
编辑客户端nrpe.cfg allowed_hosts 添加服务端ip